Absturz bei klick

Plattformunabhängige GUIs mit wxWidgets.
Antworten
patmaster
User
Beiträge: 106
Registriert: Donnerstag 3. Februar 2011, 17:21

Hi,

Ich habe ein dummes Problem. Ich habe eine Anwendung in wxPython geschrieben und die läuft auch wunderbar. Wenn man allerdings erst mal die eigentliche "Funktion" (OnCheck) startet stürzt Python ab (Python.exe hat einen Fehler entdeckt...), sobald man in das RichTextCtrl klickt (dauert kurz...paar Sekunden).
Lässt man die Anwendung während ihrer Arbeit in Ruhe, dann passt alles und danach kann man auch klicken wie man will.

hat einer ne Idee dazu ?

Als ich noch eine normales TextCtrl verwendet habe, gab's das Problem nicht.

Hier der Code:

Code: Alles auswählen

# -*- coding: utf-8 -*-
import wx, os, win32com.client as win32, traceback, word_test, time
from lxml import etree
from threading import Thread
from wx.lib.pubsub import setupv1 as psv1
from wx.lib.pubsub import Publisher 
import pythoncom
import wx.richtext

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        self.checkson = word_test.CheckOr()
        # A "-1" in the size parameter instructs wxWidgets to use the default size.
        # In this case, we select 200px width and the default height.
        wx.Frame.__init__(self, parent, title=title)
        self.control = wx.richtext.RichTextCtrl(self)
        self.control.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL))
        self.Statusbar = self.CreateStatusBar() # A Statusbar in the bottom of the window
        self.Statusbar.SetStatusText("DCM 2012 (c)")
        self.Button1 = wx.Button(self, -1, "Check'em", size=(100,50))
        self.Button2 = wx.Button(self, -1, "Clear", size=(100,50))
        self.ChoiceList = wx.Choice(self,1,choices=self.checkson.getJournals())
        self.Label1 = wx.StaticText(self,1, label="Zeitschrift: ")
        dt = MyFileDropTarget(self.control)
        self.control.SetDropTarget(dt)
        
        Publisher.subscribe(self.updateDisplay, "update")
        
        ib = wx.IconBundle()
        ib.AddIconFromFile("check.ico", wx.BITMAP_TYPE_ANY)
        self.SetIcons(ib)
        
        # Setting up the menu.
        filemenu= wx.Menu()
        #menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open a file to edit")
        menuAbout= filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")        
        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&Menu") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        
        # Events.
        #self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_BUTTON, self.OnCheck, self.Button1)
        self.Bind(wx.EVT_BUTTON, self.OnClear, self.Button2)
        # Use some sizers to see layout options
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.control, 1, wx.EXPAND)
        self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer.Add(self.sizer2, 0, wx.EXPAND)        
        self.sizer2.Add(self.Button1, 1,wx.EXPAND)
        self.sizer2.Add(self.Button2, 1,wx.EXPAND)
        self.sizer3 = wx.BoxSizer(wx.VERTICAL)
        self.sizer2.Add(self.sizer3, 2,wx.EXPAND)
        self.sizer3.Add(self.Label1, 0)
        self.sizer3.Add(self.ChoiceList, 0,wx.EXPAND)     
        
        self.SetBackgroundColour("#FFFFF")   
        
        #Layout sizers
        self.SetSizer(self.sizer)
        self.MinSize = (700,500)
        self.Fit()
        self.Show()

    def OnAbout(self,e):
        # Create a message dialog box
        dlg = wx.MessageDialog(self, "This Tool checks for troubles in Word-documents.\n", "About", wx.OK)
        dlg.ShowModal() # Shows it
        dlg.Destroy() # finally destroy it when finished.                                
        
    def OnExit(self,e):
        self.Close(True)  # Close the frame.
    
    def OnClear(self,e):
        self.control.Clear()
        
    def OnCheck(self, file):
        files = []
        for line in range(0,self.control.GetNumberOfLines()-1):        
            files.append(self.control.GetLineText(line))
        self.control.Clear()
        #for i in range(0,len(files)):
            #self.control.AppendText(" \n")
        self.control.Clear()
        if not(self.ChoiceList.GetSelection() > -1):
            dlg = wx.MessageDialog(self, "Warnung: Sie sollten eine Zeitschrift bestimmen!", "Warnung", wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal() # Shows it
            dlg.Destroy() # finally destroy it when finished.     
        if len(files) > 0:
            self.Button1.Disable()
            time.sleep(5)
            CheckThread(files, self.ChoiceList.GetSelection())
            
        else:
            dlg = wx.MessageDialog(self, "Was soll ich machen, ohne Files?", "Frage", wx.OK | wx.ICON_QUESTION)
            dlg.ShowModal() # Shows it
            dlg.Destroy() # finally destroy it when finished.
                                
        #for file in files:
        #    self.control.AppendText("Working on %s...\n" % file)
        #    for error in self.checkson.main(file):
        #        self.control.AppendText("      Unknown: '%s' at '%s'(%i)\n" % (error[2],error[1],error[0]))
        #        self.control.AppendText("Done...\n")
        #self.control.AppendText("\n")
        #self.control.AppendText("Finished!\n")
    
    def updateDisplay(self, msg):
        """
        Receives data from thread and updates the display
        """
        t = msg.data        
        if t != "button_act":
            if t.find("Working") > -1:
                self.control.BeginBold()
                self.control.WriteText(t)
                self.control.EndBold()
            elif t.find("Error") > -1:                
                self.control.BeginTextColour('red')
                self.control.WriteText(t)
                self.control.EndTextColour()
            elif t.find("Finished") > -1:                
                self.control.BeginTextColour('blue')
                self.control.WriteText(t)
                self.control.EndTextColour()
            else:
                self.control.WriteText(t)            
        else:
            self.Button1.Enable()
        
class MyFileDropTarget(wx.FileDropTarget):
    def __init__(self, window):
        wx.FileDropTarget.__init__(self)
        self.window = window

    def OnDropFiles(self, x, y, filenames):
        for file in filenames:            
            self.window.AppendText("%s\n" % file)
            
class CheckThread(Thread):
    """Test Worker Thread Class."""
 
    def __init__(self, files, zeitschrift):
        """Init Worker Thread Class."""
        Thread.__init__(self)        
        self.checkson = word_test.CheckOr()
        self.files = files
        self.zeitschrift = zeitschrift
        self.start()    # start the thread
    
    def run(self):
        pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
        """Run Worker Thread."""
        # This is the code executing in the new thread.
        for file in self.files:
            self.postTime("Working on %s...\n" % os.path.split(file)[1])
            try:
                for error in self.checkson.main(file, self.zeitschrift):
                    if error[0] != "":
                        self.postTime("  Error: '%s' at '%s'(%i)\n" % (error[2],error[1][:70],error[0]))
                    if error[0] == "":
                        self.postTime("  Error:" + error[1] + "\n")
                self.postTime("Done...\n")
                self.postTime("\n")
            except:
                print traceback.format_exc()
                self.postTime("\n")                
                self.postTime("ERROR: %s\n" % traceback.format_exc())
                self.postTime("\n")
        self.postTime("\n")
        self.postTime("Finished!\n")
        self.postTime("button_act")        
        pythoncom.CoUninitialize(pythoncom.COINIT_APARTMENTTHREADED)
 
    def postTime(self, amt):
        Publisher.sendMessage("update", amt)

app = wx.App(False)
frame = MainWindow(None, "ChecktO_ol")
app.MainLoop()
Zuletzt geändert von patmaster am Mittwoch 20. März 2013, 14:36, insgesamt 2-mal geändert.
EyDu
User
Beiträge: 4881
Registriert: Donnerstag 20. Juli 2006, 23:06
Wohnort: Berlin

Hallo,

wie lautet denn der gesamte Traceback?

Sebastian
Das Leben ist wie ein Tennisball.
patmaster
User
Beiträge: 106
Registriert: Donnerstag 3. Februar 2011, 17:21

EyDu hat geschrieben:Hallo,

wie lautet denn der gesamte Traceback?

Sebastian
Das steht in den weiteren Informationen die von Windows kommen:
AppName: python.exe AppVer: 0.0.0.0 ModName: wxbase292u_vc.dll
ModVer: 2.9.2.4 Offset: 0007201c
Antworten