wx.DirPickerControl problem

Help
2010-07-19
2013-05-01
<< < 1 2 (Page 2 of 2)
  • Steven  Lehar
    Steven Lehar
    2010-07-28

    Ok I've got it now! If enough monkeys type randomly for long enough….

        print self.dirBrowseButton1.GetChildren().GetValue()

    And of course now that I've got it, it makes sense retrospectively!

    Thanks for the help guys.

     
  • Riaan Booysen
    Riaan Booysen
    2010-07-28

    Hi,

    Ok, from your code, the text control is the second child control of the dirctrl.

    So you can save a reference too it like this:

    self.dirBrowseButton1 = ….

    self.dirBrowseText = self.dirBrowseButton1.GetChildren()
    self.dirBrowseText.Bind(wx.EVT_KILL_FOCUS, self.OnDirBrowseButtonText)

    Then when you can access it later like this:
    print self.dirBrowseText.GetValue()

    Hope this helps,
    Riaan.

     
  • Chelonian
    Chelonian
    2010-07-28

    Although sometimes some trial and error work is involved, if you have access to the wxPython API there should not be any actual guessing.   It is a matter of learning wxPython well.  There is a wxPython book, lots of tutorials out on the web, video tutorials, the wxPython demo, etc.  All of that is out there and shows you how to do this.  But it does take time, sometimes a lot of time. 

    Some of what you were doing wrong before is a Python issue and not a wxPython one.  If you have self.TextCtrl and there is no name in your app called self.TextCtrl, of course you are going to get a name error.  Working through books, using the Python Tutor List, etc., can help with that.

     
  • Riaan Booysen
    Riaan Booysen
    2010-07-28

    Hi,

    Ah, didn't see you got it, but glad you figured it out yourself :)

    Cheers,
    Riaan.

     
  • Steven  Lehar
    Steven Lehar
    2010-07-30

    I've got my DirBrowseButton working pretty much except for one glitch: When I click the  button it does indeed browse and puts the resulting path into the DirBrowseButton's textCtrl field. But there is no event handler for that button, so I have to then click into the textCtrl in order to trigger a textCtrl event which I catch, and it prints out the path.

    If I write a handler for the button and Bind it (commented out below) then clicking the button does *not* browse the folders!

    There must be a secret hidden event handler for that button - if I could find it, I could retrieve my folder path, but its not in the source code anywhere. How are you supposed to do this?
           

        self.dirBrowseButton1 = wx.lib.filebrowsebutton.DirBrowseButton(buttonText='Browse',
                  dialogTitle='', id=wxID_FRAME1DIRBROWSEBUTTON1,
                  labelText='Select a directory:', newDirectory=False,
                  parent=self.panel1, pos=wx.Point(48, 40), size=wx.Size(552, 48),
                  startDirectory='.', style=wx.TAB_TRAVERSAL,
                  toolTip='Type directory name or browse to select')
            self.dirBrowseButton1.GetChildren().Bind(wx.EVT_KILL_FOCUS, self.OnDirBrowseButton1Text)
            #self.dirBrowseButton1.GetChildren().Bind(wx.EVT_BUTTON, self.OnDirBrowseButton1Button)

        def OnDirBrowseButton1Text(self, event):
            print "OnDirBrowseButton1Text Event: "
            print self.dirBrowseButton1.GetChildren().GetValue()
           
        def OnDirBrowseButton1Button(self, event):
            print "OnDirBrowseButton1Button Event: "
            print self.dirBrowseButton1.GetChildren().GetValue()
           

     
  • Riaan Booysen
    Riaan Booysen
    2010-07-30

    Hi,

    I've taken a look at the wx.lib.filebrowsebutton source code to see how this is supposed to work.

    Seems one problem is that because Boa cannot pass methods as parameters in the generated source, the callback even is not setup properly.

    Below is example code of doing that manually.

    Hope this helps and can get you working on more fun things than just dir browse buttons ;)
    Riaan.


    #Boa:Frame:Frame1

    import wx
    import wx.lib.filebrowsebutton

    def create(parent):
        return Frame1(parent)

    [wxID_FRAME1, wxID_FRAME1DIRBROWSEBUTTON1, wxID_FRAME1PANEL1,
    wxID_FRAME1STATICTEXT1,
    ] =

    class Frame1(wx.Frame):
        def _init_ctrls(self, prnt):
            # generated method, don't edit
            wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
                  pos=wx.Point(154, 154), size=wx.Size(400, 196),
                  style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
            self.SetClientSize(wx.Size(392, 169))

            self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
                  pos=wx.Point(0, 0), size=wx.Size(392, 169),
                  style=wx.TAB_TRAVERSAL)

            self.dirBrowseButton1 = wx.lib.filebrowsebutton.DirBrowseButton(buttonText='Browse',
                  dialogTitle='', id=wxID_FRAME1DIRBROWSEBUTTON1,
                  labelText='Select a directory:', newDirectory=False,
                  parent=self.panel1, pos=wx.Point(8, 8), size=wx.Size(296, 48),
                  startDirectory='.', style=wx.TAB_TRAVERSAL,
                  toolTip='Type directory name or browse to select')

            self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
                  label='staticText1', name='staticText1', parent=self.panel1,
                  pos=wx.Point(8, 72), size=wx.Size(55, 13), style=0)

        def __init__(self, parent):
            self._init_ctrls(parent)
           
            self.dirBrowseButton1.changeCallback = self.OnBrowsed
            self.dirBrowseButton1.textControl.Bind(wx.EVT_TEXT, self.dirBrowseButton1.OnChanged)
       
        def OnBrowsed(self, event):
            self.staticText1.SetLabel(self.dirBrowseButton1.GetValue())

    if __name__ == '__main__':
        app = wx.PySimpleApp()
        frame = create(None)
        frame.Show()
       
        app.MainLoop()

     
<< < 1 2 (Page 2 of 2)