List Info

Thread: Design Patterns: MenuBar, StatusBar, etc.




Design Patterns: MenuBar, StatusBar, etc.
user name
2006-02-28 23:02:16
On Tue, 28 Feb 2006 12:09:01 -0600, Michael Hipp
<MichaelHipp.com> wrote:

>
> I'm struggling with what sort of design pattern to use
for creation
> and interacting with the "fixed" stuff like
menu bars and status bars.
> I have found 3 possibilities:
>
> 1) Create the bar inside the frame and then pass
"parent" down every
> call to everyone who might ever at some future date
need to access the
> bar and it looks like thus:
>
> This(self, parent)
>     That(self, parent)
>         TheOtherThing(self, parent)
>             parent.statusBar.SetStatusText(...)
>
> Problem: passing all this "parent" stuff
down layer by layer seems
> crude and error prone and adds a lot of overhead.


Well, it's not really that much overhead...

One possibility is to give each class a
"getStatusBar()" or
"getMenuBar()" method which knows how to find a
status bar or menu.  It
either returns it (if it knows about it), or calls the
parent's method. 
You could even cache it, to reduce the number of calls:

    class MyInnerControl:
         def __init__(self, parent):
            self.parent = parent
            self.statusbar = None
        def getStatusBar(self):
            if not self.statusbar:
                self.statusbar = self.parent.getStatusBar()
            return self.statusbar

-- 
Tim Roberts, timrprobo.com
Providenza & Boekelheide, Inc.


------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )