ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxPython-users
wxPython-users
[wxPython-users] Re: wxGlade and Events. HOW?!
by Alberto Griggio other posts by this author
Apr 15 2003 6:10PM messages near this date
Re: [wxPython-users] wxGlade and Events. HOW?! | [wxPython-users] Question re right-aligned text control
Hello,

> > Less ugly fix:
> >wxGlade is great for GUI design. Do your GUI magic in another file
> >that imports and uses MyFrame. Then if you need to do GUI reworking,
> >you don't lose your GUI magic. wxGlade is pretty good at taking care
> >of your code vs its code, but I don't trust anyone else not to
> >overwrite my code.
>  That sounds like a fabulous idea, but I'm scratching my head to a
>  polished chromedome trying to wrap my peabrain around it. So you
>  would keep the wxGlade generated code in say, MyGUI.py and the
>  functions the GUI is supposed to execute in say MyAPP.py? Then
>  instantiate MyFrame in MyAPP.py or somesuch like in your DemoApp
>  class? The events would still go into MyGUI I take it, but where
>  would OnExit() go? If all the functions go into into MyGUI.py
>  anyway, then what's the point?

You have basically two options:

1. Mix your code and the wxGlade-generated one in the same file, as Chris
   showed in his example: this works and should be safe as long as you
   "keep out" of the "wxGlade-regions", i.e. portions of code enclosed in
   # begin wxGlade ...
   # end wxGlade
   tags

2. Put a logic on a separate class, derived from the wxGlade-generated
   one, which will be on a different file.
   A quick example of this:

# file a.py - generated by wxGlade

ID_EXIT = wxNewId()

class MyFrame(wxFrame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wxDEFAULT_FRAME_STYLE 
        wxFrame.__init__(self, *args, **kwds)

        # Menu Bar
        self.frame_1_menubar = wxMenuBar()
        self.SetMenuBar(self.frame_1_menubar) 
        wxglade_tmp_menu = wxMenu()
        wxglade_tmp_menu.Append(ID_EXIT, "Exit", "Blow This
                                Popstand!") 
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
        # Menu Bar end

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("frame_1")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout 
        sizer_1 = wxBoxSizer(wxVERTICAL)
        self.SetAutoLayout(1)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        sizer_1.SetSizeHints(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame


# now, file b.py - "generated" by you

import a

class MyRealFrame(a.MyFrame):
    def __init__(self, *args, **kwds):
        a.MyFrame.__init__(self, *args, **kwds)
        # now, let's bind the event you wanted
        EVT_MENU(self, a.ID_EXIT, self.OnExit)

    def OnExit(self, event):
        self.Close(True)

# end of class MyRealFrame



I think option 2) is cleaner, but this depends a lot on your taste (and
the situation). The only problem I see is that you may need to tweak the
generated file a bit in order to make the menu IDS global variables: at
the moment wxGlade either generates them as local variables in the
__init__ body, or does not generate them at all: I'll try to tell the
author to find a solution for this ;-P

HTH,
Alberto

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@[...].org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
Thread:
Eladio Ventura
Frank Millman
Chris Munchenberg
Eladio Ventura
Eladio Ventura
Robin Dunn
Chris Munchenberg
Eladio Ventura
Chris Munchenberg
Eladio Ventura
Eladio Ventura
Alberto Griggio
Frank Millman
Robin Dunn

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved