Control three frames from main menu
I created three frames separately. I need to call these child frames from the click events of buttons located in a main frame. And when a child frame is open, I wan开发者_运维问答t the main frame to be hidden or disabled until the child frame is closed. How can I do this?
Thanks in advance.
I use pubsub to do this. Right after I open a child frame, I call the main frame's Hide method. When I close a child frame, I uses pubsub to let the main frame know that it can Show itself. You can see a fairly simple tutorial here:
http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/
are your child frames set with the main frame as their parent? If so than you can just create a variable self.parent = parent, than add a line to your OnClose handler to show the parent frame before you close/destroy the child frame:
# Untested, although it should give you an idea of what to do
class ChildFrame(wx.Frame):
def __init__(self, parent, id=-1, title="Default Frame", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self._parent = parent
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnClose(self, event):
# display your parent frame
self._parent.Show()
Create an event queue for each frame, when a child frame is opened set a variable that is checked on processing events to join the queue, and then unset this on destruction of the child frame. If this variable is set then throw the message away, otherwise add it to the queue for processing.
Depending on the libraries you are using there may be a nice built-in way of dong most of this.
精彩评论