Problem Einstellung Wert von wx.TextCtrl in wxPython

Ich versuche zu übergeben, das Verzeichnis, wählt der Benutzer zurück auf die wx.TextCtrl namens ChooseRoot. Das hat nicht funktioniert so weit.

Was mache ich falsch? Verschiedene Sachen ausprobiert, aber entweder es hängt sich auf oder ich bekomme diese Fehlermeldung.

Neue zu OOP, bitte Hilfe ein Neuling, eifrig zu lernen. =)

Traceback (most recent call last):

Datei "F:\Indexinator3000_x64.pyw", line 78, in OnChooseRoot

selbst.ChooseRoot.SetValue("Hallo")

AttributeError: 'MainPanel' - Objekt hat kein Attribut 'ChooseRoot'

import wx 

ID_EXIT = 110

class MainPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.parent = parent

        #------------- Setting up the buttons
        self.Run = wx.Button(self, label="Run")
        self.Run.Bind(wx.EVT_BUTTON, self.OnRun )
        self.ExitB = wx.Button(self, label="Exit")
        self.ExitB.Bind(wx.EVT_BUTTON, self.OnExit)

        #------------- Setting up Static text
        self.labelChooseRoot = wx.StaticText(self, label ="Root catalog: ") 
        self.labelScratchWrk = wx.StaticText(self, label ="Sratch workspace: ")
        self.labelMergeFile = wx.StaticText(self, label ="Merge file: ")

        #------------ Setting up inputtext
        self.ChooseRoot = wx.TextCtrl(self, -1, size=(210,-1))
        self.ChooseRoot.Bind(wx.EVT_LEFT_UP, self.OnChooseRoot)
        self.ScratchWrk = wx.TextCtrl(self, -1, size=(210,-1))
        self.MergeFile = wx.TextCtrl(self, -1, size=(210,-1))


        #------------- Setting up the outputbox
        self.Output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)

        #------------- Setting up the sizer
        SizerF = wx.FlexGridSizer(3,2,5,5)
        SizerF.Add(labelChooseRoot)      #row 1, col 1
        SizerF.Add(ChooseRoot)           #row 1, col 2
        SizerF.Add(labelScratchWrk)      #row 2, col 1
        SizerF.Add(ScratchWrk)           #row 2, col 2
        SizerF.Add(labelMergeFile)       #row 3, col 1
        SizerF.Add(MergeFile)            #row 3, col 2

        SizerB = wx.BoxSizer(wx.VERTICAL)
        SizerB.Add(Run, 1, wx.ALIGN_RIGHT|wx.ALL, 5)
        SizerB.Add(ExitB, 0, wx.ALIGN_RIGHT|wx.ALL, 5)

        Sizer1 = wx.BoxSizer()
        Sizer1.Add(SizerF, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL, 10)
        Sizer1.Add(SizerB, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)

        Sizer2 = wx.BoxSizer()
        Sizer2.Add(Output, 1, wx.EXPAND | wx.ALL, 5)

        SizerFinal = wx.BoxSizer(wx.VERTICAL)
        SizerFinal.Add(Sizer1, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
        SizerFinal.Add(Sizer2, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)


        self.SetSizerAndFit(SizerFinal)

    #--- START EVENT HANDLERS

    def OnChooseRoot(self, Event=None):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                          style=wx.DD_DEFAULT_STYLE
                           #| wx.DD_DIR_MUST_EXIST
                           #| wx.DD_CHANGE_DIR
                           )

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            RootPath = dlg.GetPath()
            self.ChooseRoot.SetValue(RootPath)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnRun(self, Event=None):
        #First check if any of the boxes is empty
        pass

    def OnExit(self, Event=None):
        self.GetParent().Close()


    #--- END EVENT HANDLERS

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size = (430,330),
                          style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE | wx.STAY_ON_TOP)
        self.CreateStatusBar() 
        #------------- Setting up the menu
        filemenu = wx.Menu()
        filemenu.Append(ID_EXIT, "E&xit", "Exit the program")
        #------------- Creating the menu
        menubar = wx.MenuBar()
        menubar.Append(filemenu, "&File")
        self.SetMenuBar(menubar)
        #---------- Setting menu event handlers
        wx.EVT_MENU(self, ID_EXIT, self.OnExit)                    
        #--- Add MainPanel
        self.Panel = MainPanel(self, -1)

        self.SetMaxSize(self.GetSize()) #Sets the Maximum size the window can have
        self.SetMinSize(self.GetSize()) #Sets the Minimum size the window can have
        #Centre on Screen
        self.CentreOnScreen()

        ###---- SHOW THE WINDOW
        self.Show(True)

    def OnExit(self,  event):
        self.Close(True) # Close the Frame
    #--- END EVENT HANDLERS ---------------------------------



if __name__=='__main__':

    try:
        app = wx.PySimpleApp()
        frame = MainWindow(None, -1, "IndexGenerator")
        app.MainLoop()
    finally:
        del app
InformationsquelleAutor sekstiseks | 2011-06-07
Schreibe einen Kommentar