[Tutor] Questions about wxEvents

Jeff Younker jeff at drinktomi.com
Thu Dec 6 18:38:55 CET 2007


While I can't help you with the wx specific part of the question, I can
offer help with the reuse question.     Here is one approach.  Add an
controller identifier to fpCallback.  Then use lambda expressions for  
the
actual callback, where the lambda expressions pass in a fixed value  
for the
identifier.

Modified code:

         self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1,  
size=(300, -1),
             labelText='', fileMask='*.*', fileMode=wx.OPEN,
             dialogTitle='Select the file containing UCF claims',
             changeCallback= lambda x: self.fpCallback('fp1', x)
         )
         self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1,  
size=(300, -1),
             labelText='', fileMask='FI*.*', fileMode=wx.OPEN,
             dialogTitle='Select the form-image file - generally  
starts with FI',
             changeCallback= lambda x: self.fpCallback('fp2', x)
         )
         [snip]
     def fpCallback(self, controlID, evt):
         print evt.__dict__
         print help(evt)
         value = evt.GetString()
         [snip]



- Jeff Younker - jeff at drinktomi.com -


On Dec 6, 2007, at 9:12 AM, Marc Tompkins wrote:

> I have a specific question - how can I generalize a  
> FileBrowseButtonWithHistory - and I realized, as I was trying to  
> word my question, that my real question is a bit more generic.
>
> First, the specific question:  The FileBrowseButtonWithHistory  
> requires a callback override and some custom code to straighten out  
> handling the history.  So far, so good.  However, I wish to use more  
> than one FBBWH on my form, and I can't figure out how to re-use the  
> custom callback so it will work for both controls.  (It makes me  
> sick to my stomach when I look at my code and see duplicate  
> blocks!)   Don't get me wrong - it's working right now, it's just  
> that my code is fugly and I want to clean it up.
>
> In more general terms, how can I set more than one control to use  
> the same block of code as a custom callback, and figure out at  
> runtime which control I'm responding to?  Doesn't the Event or  
> CommandEvent carry any information about itself?
> I've tried this:
>
>         [snip]
>         self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1,  
> size=(300, -1),
>             labelText='', fileMask='*.*', fileMode=wx.OPEN,
>             dialogTitle='Select the file containing UCF claims',  
> changeCallback= self.fp1Callback)
>         self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1,  
> size=(300, -1),
>             labelText='', fileMask='FI*.*', fileMode=wx.OPEN,
>             dialogTitle='Select the form-image file - generally  
> starts with FI', changeCallback= self.fp2Callback)
>         [snip]
>     def fp1Callback(self, evt):
>         print evt.__dict__
>         print help(evt)
>         value = evt.GetString()
>         [snip]
>     def fp2Callback(self, evt):
>         print evt.__dict__
>         print help(evt)
>         value = evt.GetString()
>         [snip]
>
> All I get from "print evt.__dict__" is: {'_string': u'E:\\ultrahld\ 
> \report\\FILE'}
>
> and all I get from help is:
> Help on instance of LocalEvent in module wx.lib.filebrowsebutton  
> object:class instance(object)
>  |  instance(class[, dict])
>  |
>  |  Create an instance without calling its __init__() method.
>  |  The class must be a classic class.
>  |  If present, dict must be a dictionary or None.
>  |
>  |  Methods defined here:
>  |
>  |  __abs__(...)
>  |      x.__abs__() <==> abs(x)
>  |
> ...  in other words, I might as well have typed "help(object)".
> I only know that the method "evt.GetString()" exists because the  
> example in the demo uses it.
> I've Googled, and Gmaned, and read the wx docs (such as they are),  
> but I'm not seeing anything I can use.
>
> I know that this is a wxPython question, and that this is the Python  
> list... but y'all have answered some wx questions in the past, and I  
> hate to join another list for one question.   If I must, I will...  
> but thanks in advance for any light you can shed.
>
> -- 
> www.fsrtechnologies.com  
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071206/c7bee703/attachment-0001.htm 


More information about the Tutor mailing list