|
From: John H. <ec...@ya...> - 2011-03-09 18:21:43
|
I am happy to let you know that I succeeded in adding MDI support to Pythoncard
with only a few lines of modifications to the Background class in model.py
I made the Background class into a BackgroundBase class, and have the Background
class subclass from the BackgroundBase class.
Then I added a MDIParentBackground and MDIChildBackground which simply force
Background to subclass from wxMDIParentFrame and wxMDIChildFrame respectively,
instead of the wx.Frame class. Once I've done that, wxPython does the rest of
the work.
################ mod to model.py ######################
from wxPython.wx import wxMDIParentFrame, wxMDIChildFrame
# Used to say:
# class BackgroundBase(Scriptable, wx.Frame, event.EventSource):
class BackgroundBase(Scriptable, event.EventSource):
"""
A window that contains Widgets.
"""
def __init__(self, aParent, aBgRsrc, frameclass=wx.Frame):
...<original code>...
#Changed original code from invoking wx.Frame here to a method passed down
# First, call the base class' __init__ method to create the frame
frameclass.__init__(self, aParent,
self.id,
#self.name,
aBgRsrc.title,
position,
aBgRsrc.size,
style | wx.NO_FULL_REPAINT_ON_RESIZE,
aBgRsrc.name)
...<rest of original code>...
class Background(BackgroundBase, wx.Frame):
def __init__(self, aParent, aBgRsrc):
return BackgroundBase.__init__(self, aParent, aBgRsrc,
frameclass=wx.Frame)
class MDIParentBackground(BackgroundBase, wxMDIParentFrame):
def __init__(self, aParent, aBgRsrc):
return BackgroundBase.__init__(self, aParent, aBgRsrc,
frameclass=wxMDIParentFrame)
class MDIChildBackground(BackgroundBase, wxMDIChildFrame):
def __init__(self, aParent, aBgRsrc):
return BackgroundBase.__init__(self, aParent, aBgRsrc,
frameclass=wxMDIChildFrame)
############## end of mod to model.py #########################
To use these two new classes, the code is remarkably unremarkable. The parent
code:
############# Parent ######################
#!/usr/bin/python
"""
__version__ = "$Revision: 1.5 $"
__date__ = "$Date: 2004/04/30 16:26:12 $"
"""
from PythonCard import model
MDI_rsrc=\
{'application':{'type':'Application',
'name':'Template',
'backgrounds': [
{'type':'Background',
'name':'bgTemplate',
'title':'Testing MDI Controls',
'size':(400, 300),
'style':['resizeable'],
'menubar': {'type':'MenuBar',
'menus': [
{'type':'Menu',
'name':'menuFile',
'label':'&File',
'items': [
{'type':'MenuItem',
'name':'menuFileExit',
'label':'E&xit',
'command':'exit',
},
]
},
{'type':'Menu',
'name':'menuOptions',
'label':'Options',
'items': [
{'type':'MenuItem',
'name':'menuOptionsOpenNew',
'label':'Open New\tAlt+N',
'command':'openNew',
},
]
},
]
},
'components': [
] # end components
} # end background
] # end backgrounds
} }
MyCW_rsrc=\
{'application':{'type':'Application',
'name':'Template',
'backgrounds': [
{'type':'Background',
'name':'bgTemplate',
'title':'Standard Template with File->Exit menu',
'size':(698, 517),
'style':['resizeable'],
'menubar': {'type':'MenuBar',
'menus': [
{'type':'Menu',
'name':'menuFile',
'label':'&File',
'items': [
{'type':'MenuItem',
'name':'menuFileExit',
'label':'E&xit',
'command':'exit',
},
]
},
{'type':'Menu',
'name':'menuOptions',
'label':'Options',
'items': [
{'type':'MenuItem',
'name':'menuOptionsOpenNew',
'label':'Open New\tAlt+N',
'command':'openNew',
},
]
},
]
},
'components': [
{'type':'TextArea',
'name':'TextArea1',
'position':(20, 20),
'size':(651, 333),
},
{'type':'Button',
'name':'Button1',
'position':(559, 376),
'label':'Button1',
},
] # end components
} # end background
] # end backgrounds
} }
class MyBackground(model.MDIParentBackground):
def on_initialize(self, event):
# if you have any initialization
# including sizer setup, do it here
#MDI.on_initialize(self, event)
pass
def on_openNew_command ( self, event ):
# Create a child window
child = model.childWindow(self, MyCW, rsrc=MyCW_rsrc)
if __name__ == '__main__':
app = model.Application(MyBackground, None, MDI_rsrc)
app.MainLoop()
############# End of Parent ######################
############# Child ######################
class MyCW(model.MDIChildBackground):
def on_initialize(self, event):
self.parent = self.getParent()
self.components.TextArea1.text='I am only a child.'
def on_openNew_command ( self, event ):
return self.parent.on_openNew_command ( event )
############# End of Child ######################
That's it!!!
Now I have to play around with resizer to see how that would work here.
--
John Henry
|
|
From: Steven D'A. <st...@pe...> - 2011-03-09 19:56:19
|
John Henry wrote: > I am happy to let you know that I succeeded in adding MDI support to Pythoncard > with only a few lines of modifications to the Background class in model.py Thank you for following up your question with a solution! I'm very glad to see that this PythonCard group isn't quite dead yet. -- Steven |
|
From: John H. <ec...@ya...> - 2011-03-09 20:43:24
|
A slight cleanup, if I use wx.MDIParentFrame, and wx.MDIChildFrame, then nothing
needs to be changed at the import line.
BTW: The sizers works fine for the child windows! This is great.
###########
class Background(BackgroundBase, wx.Frame):
def __init__(self, aParent, aBgRsrc):
return BackgroundBase.__init__(self, aParent, aBgRsrc,
frameclass=wx.Frame)
class MDIChildBackground(BackgroundBase, wx.MDIChildFrame):
def __init__(self, aParent, aBgRsrc):
return BackgroundBase.__init__(self, aParent, aBgRsrc,
frameclass=wx.MDIChildFrame)
class MDIParentBackground(BackgroundBase, wx.MDIParentFrame):
def __init__(self, aParent, aBgRsrc):
return BackgroundBase.__init__(self, aParent, aBgRsrc,
frameclass=wx.MDIParentFrame)
--
John Henry
----- Original Message ----
> From: Steven D'Aprano <st...@pe...>
> To: pyt...@li...
> Sent: Wed, March 9, 2011 11:40:24 AM
> Subject: Re: [Pythoncard-users] Added MDI support to Pythoncard (was MDI -
>childwindows within a window)
>
> John Henry wrote:
> > I am happy to let you know that I succeeded in adding MDI support to
>Pythoncard
>
> > with only a few lines of modifications to the Background class in model.py
>
> Thank you for following up your question with a solution!
>
> I'm very glad to see that this PythonCard group isn't quite dead yet.
>
>
>
> --
> Steven
>
> ------------------------------------------------------------------------------
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the future.
> http://p.sf.net/sfu/internap-sfd2d
> _______________________________________________
> Pythoncard-users mailing list
> Pyt...@li...
> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
|