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 19/6/17 5:44 am, Dietmar Schwertberger wrote: > On 6/18/17 2:22 PM, Brendan Simon (eTRIX) wrote: >> If I create a button handler, then edit the code, then regenerate the >> code, the button handler is reset to the default. >> >> How can I prevent wxglade from overwriting MY code? > With "Overwrite existing sources" deactivated, your handler code > should be kept. The marker to detect handlers is "# wxGlade: > ...<event_handler>". > I'have just tried this and noted a bug where sometimes newlines are > inserted. I will correct this asap. > Long term the keep/overwrite code needs some modifications to be more > robust and user friendly. > > The alternative approach is to derive a class in your own file and > implement the handler in the derived class. For non-trivial projects > this is probably the better option. > There is a wiki page on this topic at > https://wiki.wxpython.org/OrganizingYourCode > This is a bit older and I wish it would be a bit more compact. > > > *In a nutshell:* > > Set output file name from wxGlade to e.g. ExampleGui.py > > In the main.py or Example.py: > > import ExampleGui > > class ExampleFrame(ExampleGUI.ExampleFrame): > def __init__(self, app): > self.app = app > ExampleGUI.ExampleFrame.__init__(self, None, wx.ID_ANY, "") > > XXX implement your handlers etc. here > > > > class ExampleApp(wx.App): > # application / logic > def OnInit(self): > self.frame = ExampleFrame(self) > self.SetTopWindow(self.frame) > self.frame.Show() > return True > > Example = ExampleApp(0) > Example.MainLoop() > > Regards, > Dietmar 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. 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. Brendan. -- ------------------------------------------------------------------------ *eTRIX pty ltd* PO Box 497, Inverloch, VIC 3996, AUSTRALIA. +61-(0)417-380-984 [email protected] ------------------------------------------------------------------------ ------------------------------------------------------------------------------ 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