Re: How prevent wxglade overwriting button handler
"Brendan Simon (eTRIX)" <[email protected]>
| Newsgroups | gmane.comp.python.wxglade |
|---|---|
| Organization | eTRIX pty ltd |
| Message-ID | <[email protected]> |
On 20/6/17 1:27 am, Dietmar Schwertberger wrote:
> On 6/19/17 1:36 PM, Brendan Simon (eTRIX) wrote:
>> I don't understand why I have to deactivate "Overwrite existing
>> sources". That doesn't make sense to me. I've added some extra
>> widgets to the design and now I want to regenerate sources, so I need
>> to overwrite them.
> If you interpret this option that way, then it would not be too useful
> as only the first time any code would be written.
> I think, the label should be changed to something like "Overwrite user
> code" together with some better tooltip help, though.
Yes, that was how I interpreted the option, which as you say wouldn't be
too useful as you could only generate your code once.
So it makes sense to clarify the description for that option.
"Overwrite user code" is a little clearer.
OK. So I should definitely have this option checked to protect myself
from overwriting my own code :)
>> I ended up sub-classing the app and binding the widgets, as I have
>> asyncio coroutines working at that level that need to interact with
>> the gui.
>>
>> Still wxglade is generates the print statement that outputs to stdio,
>> whether you want it or not. If it is commented out or deleted, it
>> gets regenerated on the next regeneration of the sources.
> This way, you have two handlers, both bound to the event and therefore
> also both are executed:
> - generated by wxGlade in the generated class and bound by the
> generated class
> - written and bound by you in your application
>
> So either don't define a handler in wxGlade or override the generated
> handler in a derived class.
> Probably I should have written in my last message:
>
> class ExampleFrame(ExampleGUI.ExampleFrame):
> def __init__(self, app):
> self.app = app
> ExampleGUI.ExampleFrame.__init__(self, None, wx.ID_ANY, "")
>
> # XXX override generated handlers here
> def on_button(self, event):
> #print("Event handler 'on_button' not implemented!")
> self.app.do_something_useful()
> event.Skip()
OK. That makes sense. Either override the function (i.e. no need to
bind in the sub-class), or don't create a handler via wxglade and do the
binding in the sub-class.
I'm not sure if one method is better than the other. I think I'm
leaning towards letting wxglade generate the handler, and override the
function in the sub-class. That way I don't have to explicitly write
the binding code, which makes it a little more RAD like. If the user
doesn't override the function (intentionally or otherwise), then the
default super class function will be called.
The counter argument is that it is not explicit in the subclass who is
generating the event or calling the function, but I guess that's just an
attribute of using polymorphism.
Thanks,
Brendan.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
wxGlade-general mailing list
wxGlade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/wxglade-general