Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

wx.DirPickerControl problem

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

    Hi,

    I'm trying to add a wx.DirPickerControl from the Buttons controls, and as soon as I click the location on my panel, I get the error:

    Error on Accessing Getter for ToolTipString: 'NoneType' object has no attribute 'Get Tip'

    I'm using Python 2.5, wxPython 2.8.7.1, Boa Constructor 0.6.1

     
  • Hi,

    I see the same with wxPython 2.8.10.1, for some reason Boa doesn't set a default value for ToolTipString.

    If I read the code correctly this should be done in BaseCompanions.ControlDTC but it doesn't happen for DirPickerCtrl nor FilePickerCtrl.

    Hopefully Riaan or someone else can shed a light why this is happing.

    If I ignore the error one can still resize the control.
    Werner

     
  • Hi.

    I have the same problem.

     
  • Steven  Lehar
    Steven Lehar
    2010-07-22

    My error is more serious. If I ignore the warning message, the wx.DirPickerControl appears where it should, but its all screwed up, the text field is too small off to the left, with a big gap between it and the  button, and it doesn't work! Nor does it respond correctly to changes in its Properties.

    Worse still, if I cut and paste the Boa-generated code into a simple Python program and import wxPython, it STILL doesn't work!

    I'm afraid thats too much for me, I need results right now! I'm turning back to Tkinter, at least I can get it running!

     
  • Obviously something wrong with wx.DirPickerControl, you might want to report it on the wxPython list.

    Anyhow there is an alternative, see wx.lib.filebrowsebutton.DirBrowseButton, on Boa it is under the Library tab.

    Werner

     
  • Steven,

    Not sure what you did but I can get wx.DirPickerCtrl to work outside the Boa designer, e.g. the following code (note use of sizer) works for me:

    #Boa:Dialog:Dialog1

    import wx

    def create(parent):
        return Dialog1(parent)

    =

    class Dialog1(wx.Dialog):
        def _init_sizers(self):
            # generated method, don't edit
            self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)

            self.SetSizer(self.boxSizer1)

        def _init_ctrls(self, prnt):
            # generated method, don't edit
            wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
                  pos=wx.Point(640, 340), size=wx.Size(400, 250),
                  style=wx.DEFAULT_DIALOG_STYLE, title='Dialog1')
            self.SetClientSize(wx.Size(384, 212))

            self._init_sizers()

        def __init__(self, parent):
            self._init_ctrls(parent)

            self.dirPickerCtrl1 = wx.DirPickerCtrl(self, -1, 'c:', 'Select dir')
           
            self.boxSizer1.Add(self.dirPickerCtrl1, 0, wx.EXPAND)
           
            self.boxSizer1.Layout()
           
           

    if __name__ == '__main__':
        app = wx.PySimpleApp()
        dlg = create(None)
        try:
            dlg.ShowModal()
        finally:
            dlg.Destroy()
        app.MainLoop()

     
  • Steven  Lehar
    Steven Lehar
    2010-07-22

    Ok, I've reverted back to Boa Constructor, thanks guys for helping me out, I've got my UI pretty much done!

    But now I'm having trouble with the events. Which event triggers when I change the text in DirBrowseButton control?

    Or even my wx.TextCtrl !

    I've been putting debug print statements in various event callback functions…

      def OnTextCtrl1TextEnter(self, event):
            print "Event: OnTextCtro1TextEnter"

    and I've found events that trigger for each individual character, but isn't there one that triggers when you finally hit  or click outside the text box? Damned if I could find it!

    And similarly for my DirBrowseButton.

     
  • Steven  Lehar
    Steven Lehar
    2010-07-23

    Werner > there's a really neat tool in wxPython

    WIDGET INSPECTION TOOL

    Wow! That really IS neat!!! Thanks Werner!

    Now I know that the event I am looking for is not a DirBrowseButton event, but an event of its text box (Frame1.panel1.dirBrowseButton.text) called EVT_KILL_FOCUS (or an event of the browse button called EVT_SET_FOCUS) to catch the final event when a valid folder has been selected.

    But although I can click on the DirBrowseButton in the Frame Designer to access it properties, I cannot click on its component text box or browser button in the Frame Designer, or view their properties, and thus I cannot get Boa to auto-generate a callback function for those components.

    How do I generate the callback handler for the text box event?

     
  • Steven  Lehar
    Steven Lehar
    2010-07-23

    Oh, NEVER MIND! There it is!

    self.dirBrowseButton1.bind(wx.EVT_KILL_FOCUS, self.OnDirBrowseButton1SetFocus)

    I'll just write a handler called OnDirBrowseButton1SetFocus( ).

    Thanks!

     
  • Steven  Lehar
    Steven Lehar
    2010-07-23

    Wrong again - excuse the flip-flopping!

    The functions OnDirBrowseButton1SetFocus(self, event) and OnDirBrowseButton1KillFocus(self, event)  which would *seem* to be triggered by a change in focus of my DirBrowseButton widget, do NOT in fact do so, so I still can't find a way to generate the callback function for the EVT_KILL_FOCUS event of the text box (or the  button) components of my DirBrowseButton.

    By rights, there *should* be a way to click on those components and thus explore their properties and set up their events, but when I click on the text box, all I get is the properties of the whole compound DirBrowsebutton widget.

     
  • Riaan Booysen
    Riaan Booysen
    2010-07-23

    Hi,

    Firstly, I must mention, if you ever have trouble with a control not behaving in the designer, just place a container in it's place and create the control yourself after boa creation code completes, there is really no reason to give up because of designer issues.

    Secondly, I have none of the problems so far mentioned in this thread so I guessed I fixed the tooltip issue some time ago, it will be in the next release.

    Third, when dealing with compound controls and events, it is sometimes easiest to just bind the correct event to the right control inside the compound control. You can't do this with the Designer, you need to do it in your code.
    You can use things like ctrl.GetChildren() to access controls inside compound controls usually.

    Hope this helps,
    Riaan.

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    Thanks Riaan, thats exactly the kind of advice I need. I'm a rank beginner with Boa.

    Another question at that level: When I was experimenting with various events, I auto-generated a bunch of event handlers, most of which are totally irrelevant. How do I remove them again? I'm guessing that I can't just delete the source code, because Boa must have hidden internal copies of them and would get confused. But if I delete an object in the Frame Designer, its source code remains!  How do people deal with this in the trial-and-error debugging process?

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    Also, Riaan, if I start messing around with my code outside of Boa, I can never get it back INTO Boa again, can I?

    So do you make the rough interface first with Boa, then you leave Boa never to return, and start tweaking the code outside of Boa?

     
  • Steven,

    1. Deleting an event handler is simple, click on it in the Inspector/Evts tab, there are options to delete, rename showall.
    2. Boa has no hidden code for the module you generated with Boa's designer, i.e. all code is in the source you can see and edit.
    3. You can edit Boa code outside Boa and get it to Boa without any problems, AS LONG as you respect the code convention Boa uses.  Any method marked with "# generated method, don't edit" has to respect Boa's convention, e.g.:

        def _init_coll_boxSizer1_Items(self, parent):
            # generated method, don't edit

            parent.AddWindow(self.button1, 0, border=0, flag=0)

    Outside Boa the above line could also be:
            parent.Add(self.button1, 0, border=0, flag=0)

    you could even "run" it from within Boa, but when you try to use the designer it will hick up as it expects AddWindow and not Add.

    Hope this helps
    Werner

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    Thank you Werner, yes, that is very helpful!

    Steve

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    So for example I have a wx.textCtrl and I selected it in the Frame Designer and checked its Evts properties, and  picked wx.EVT_Text, which related to the callback function OnTexCtrl1Text( ) which was autogenerated, and I added…

    def OnTextCtrl1Text(self, event)
        print "OnTextCtrl1 Event: " + event.GetString()
        event.Skip()

    What does the event.Skip() do? Nothing changes when I #comment it out.

    When I run that, and highlight the text in textCtrl1 and replace it with "text", I get in the output field:

    OnTextCtrl1 Event: t
    OnTextCtrl1 Event: te
    OnTextCtrl1 Event: tex
    OnTextCtrl1 Event: text

    Four separate events for each character of "text", but no particular event when I hit "Enter".

    Isn't there an event I can search for when the text entry is complete?

      Steve

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    Never mind! I've got it!

    def OnTextCtrl1KillFocus(self, event)
        print "OnTextCtrl1KillFocus Event: text = " + self.textCtrl1.GetValue()
        event.Skip()

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    Werner >>
    To find what events fire and to work out issues with sizers and ….. there is a really neat tool in wxPython.
    http://wiki.wxpython.org/Widget%20Inspection%20Tool
    << Werner

    That looks very useful Werner, but it doesn't seem that it would have helped me.

    Now I discover that to catch the event when my textCtrl box's text has just been changed ( was hit) I need to catch the wx.EVT_KILL_FOCUS event (with callback function OnTextCtrl1KillFocus(self, event ) )

    But when I view the Widget Inspection Tool / Events, and type text into my textCtrl and hit , the only events I get are:

    EVT_CHAR_HOOK  None
    EVT_CHILD_FOCUS Panel "panel1" (114)
    EVT_CHILD_FOCUS CheckBox "checkBox2" (104)

    Why do I not see EVT_KILL_FOCUS ? How would the Widget Inspection Tool / EventWatcher have told me the right event to watch for? Does it only report events for Frame1, and not its children? (checkBox2 is the next widget in sequence after checkBox1, so that's the event of the focus passing from my textCtrl to the checkBox.)

      Steve

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    NEVER MIND! I see it now!

    I have to browse the Widget Tree in the Widget Inspection Tool, and select the TextCtrl("textCtrl1") whose events I want to watch.

    I'm getting it slowly. Thanks for your patience.

      Steve

     
  • Steven  Lehar
    Steven Lehar
    2010-07-26

    Riaan >>
    When dealing with compound controls and events, it is sometimes easiest to just bind the correct event to the right control inside the compound control. You can't do this with the Designer, you need to do it in your code.
    You can use things like ctrl.GetChildren() to access controls inside compound controls usually.
    << Riaan

    So after creating my compound control dirBrowseButton I find this auto-generated code:

    self.dirBrowseButton1 = wx.lib.filebrowsebutton.DirBrowseButton(…
        …
        …
        …
        …)

    after which I type in something like this?

    self.dirBrowseButton1.text.Bind(wx.EVT_KILL_FOCUS,              # bind this event of the dirBrowseButton's text control \
        self.OnTextCtrlKillFocus)                                                                 # to this callback function. And then, same indent level I add…
    def OnTextCtrlKillFocus( self.dirBrowseButton1.text, event):       # Callback function defined within compound control
         <event handling code here>
         event.Skip()

    Syntax error: invalid syntax

     
  • Riaan Booysen
    Riaan Booysen
    2010-07-26

    Steven,

    Look closely at all Werner told you!

    As response to your last message, is self.dirBrowseButton1.text really the subcontrol or did you make that up?

    If you ever get a syntax error, you are just typing stuff, not real python, please try harder to make it work.

    I guess compound controls is advanced for a beginner, but you need to learn to investigate such things yourself.

    e.g print out the first few controls in the dir control:
    print self.dirBrowseButton1.GetChildren()
    print self.dirBrowseButton1.GetChildren()
    print self.dirBrowseButton1.GetChildren()

    Does that give you some hints which controls to access and bind events too?

    I haven't tried this, I'm just guessing for you.

    Hope it helps,
    Riaan.

     
  • Chelonian
    Chelonian
    2010-07-26

    Hi Stephen,

    Couple of very general points.  One is, it is not good form to ask many different questions using the same thread.  Your thread started out about "DirPickerControl problem" and has wandered all over in a general survey of Boa Constructor and wxPython.  Instead, it is better to post a new thread for each new idea.  This way when others are trying to learn, they can know how to find the information more easily.  It also keeps it straighter for you and for those answering you.

    Second, you can learn much by researching about how Boa works on your own.  There are some good resources to help.  One is the Boa tutorial that is included.  Hit F1 and then read-or rather work through-the Boa Constructor Getting Started Guide and or the help.  There is also some videos I did on Intro to Boa on ShowMeDo here: 
    http://showmedo.com/videotutorials/series?name=wKQrywla5

    You can also search this forum or just Google for the answer.  Also, some of your questions are not really Boa questions but wxPython questions, and there's an excellent wxPython forum with good folks who can help with that, as well as lots of wxPython tutorials out there as well.  The mailing list is here:  http://www.wxpython.org/maillist.php

    Good luck,
    Che

     
  • Steven  Lehar
    Steven Lehar
    2010-07-27

    Riaan >>
    As response to your last message, is self.dirBrowseButton1.text really the subcontrol or did you make that up?

    If you ever get a syntax error, you are just typing stuff, not real python, please try harder to make it work.

    I guess compound controls is advanced for a beginner, but you need to learn to investigate such things yourself.
    << Riaan

    Believe it or not, I HAVE done hours and hours of research on the web. I *never* post a question without first trying hard to find the answer myself. I have gone through the you-do-it tutorials, and many of the help pages, but none of them happen to use or document  this compound control and how to catch its events. Yes that code was just made up by guessing - I have no idea what it should be. Maybe I should give up on using that compound dirBrowseButton and just use a button and a text box, which I *do* know how to use. You have to have a working example to "close the loop" before you can do trial-and-error investigation. If you have something that *doesn't* work, there's no way to figure out whats wrong.  I know this stuff is all crystal clear to yous guys, but it ain't so clear to me! Not until I see a working example that I can tweak and modify to suit my needs.

     
  • Steven  Lehar
    Steven Lehar
    2010-07-28

    I don't know why I am still working on this ridiculous thing!

    I got this part to work…

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

    And I even get a print working in the event handler!

        def OnDirBrowseButtonText(self, event):
            print "OnDirBrowseButtonText Event: "     # <= this WORKS!

    But now how do I retrieve the Value of that text field?
            print event.GetValue()                   # has no attrib. GetValue
            print self.GetChildren().GetValue()   # has no attrib. GetValue
            print self.GetChildren().GetValue()      # has no attrib. GetValue
            print self.GetChildren.GetValue()     # has no attrib. GetValue
            print self.text.GetValue()               # Frame1 no attrib. 'text'
            print self.TextCtrl.GetValue()           # Frame1 no attrib. 'TextCtrl'
            print self.dirBrowseButton1.text.GetValue()    # no attrib. 'text'
            print self.dirBrowseButton1.TextCtrl.GetValue()# no attrib. 'TextCtrl'
            event.skip()                             # FocusEvent no attrib 'skip'
           

    If you don't have an example to follow, its just a matter of random guessing!

    This really sucks!

     
1 2 > >> (Page 1 of 2)