So I have a wxFrame that has a button on it that instantiates an instance of a different wxFrame class (call it Preview window).
My problem is I need a way to detect if an instance of the Preview
window is already open so if my user clicks the “Preview Button” on
first wxFrame, the program will realize that the Preview window is
already open and just ignore the click.
I just dont know of a way to detect if there is an instance of the
Preview window class (wxFrame) already open. Could someone show
me a simple example?
It might be easier to track whether or not you have the preview window open by maintaining a flag yourself, or a reference to the open preview wxFrame with it set to None when there isn’t one open.
Steven
···
From: Ryan McDonald [mailto:mcdonald.ryan@gmail.com]
Sent: Wednesday, 17 August 2005 4:44 PM
To: wxPython-users@lists.wxwidgets.org
Subject:
[wxPython-users] Detecting an instance of a class
So I have a wxFrame that has a button on it that instantiates an instance of a different wxFrame class (call it Preview window).
My problem is I need a way to detect if an instance of the Preview window is already open so if my user clicks the “Preview Button” on first wxFrame, the program will realize that the Preview window is already open and just ignore the click.
I just dont know of a way to detect if there is an instance of the Preview window class (wxFrame) already open. Could someone show me a simple example?
I was going to do that until I realized that I don’t know how to have
the “preview window” signal back to the main window that it is
closing. Any help with that route?
-R
···
On 8/17/05, Steven Reddie smr@essemer.com.au wrote:
It might be easier to track whether or not you have the preview window open by maintaining a flag yourself, or a reference to the open preview wxFrame with it set to None when there isn’t one open.
Steven
From: Ryan McDonald [mailto:mcdonald.ryan@gmail.com]
Sent: Wednesday, 17 August 2005 4:44 PM
To: wxPython-users@lists.wxwidgets.org
Subject:
[wxPython-users] Detecting an instance of a class
So I have a wxFrame that has a button on it that instantiates an instance of a different wxFrame class (call it Preview window).
My problem is I need a way to detect if an instance of the Preview window is already open so if my user clicks the “Preview Button” on first wxFrame, the program will realize that the Preview window is already open and just ignore the click.
I just dont know of a way to detect if there is an instance of the Preview window class (wxFrame) already open. Could someone show me a simple example?
The simplest method would be for the preview window to hold a reference to the main window and call a previewWindowIsClosing method on the main window. There is probably a less coupled approach involving events or messages, and I know how to do that in Windows, but am new to wxPython and wxWidgets so can’t yet help you with that.
Steven
···
From: Ryan McDonald [mailto:mcdonald.ryan@gmail.com]
Sent: Wednesday, 17 August 2005 5:07 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Detecting an instance of a class
I was going to do that until I realized that I don’t know how to have the “preview window” signal back to the main window that it is closing. Any help with that route?
-R
On 8/17/05, Steven Reddie smr@essemer.com.au wrote:
It might be easier to track whether or not you have the preview window open by maintaining a flag yourself, or a reference to the open preview wxFrame with it set to None when there isn’t one open.
Steven
From: Ryan McDonald [mailto:mcdonald.ryan@gmail.com]
Sent: Wednesday, 17 August 2005 4:44 PM
To: wxPython-users@lists.wxwidgets.org
Subject:
[wxPython-users] Detecting an instance of a class
So I have a wxFrame that has a button on it that instantiates an instance of a different wxFrame class (call it Preview window).
My problem is I need a way to detect if an instance of the Preview window is already open so if my user clicks the “Preview Button” on first wxFrame, the program will realize that the Preview window is already open and just ignore the click.
I just dont know of a way to detect if there is an instance of the Preview window class (wxFrame) already open. Could someone show me a simple example?
From within the preview window module, how would you reference the parent?
I call the preview window with:
cframe = frmPreview.Preview(None, -1, “”)
cframe.Show()
This is what my preview window looks like:
import wx
class Preview(wx.Frame):
def init(self, *args, **kwds):
# begin wxGlade: Preview.init
kwds[“style”] = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU
wx.Frame.init(self, *args, **kwds)
self.Preview = wx.Panel(self, -1)
self.__set_properties()
self.__do_layout()
# end wxGlade
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def __set_properties(self):
# begin wxGlade: Preview.__set_properties
self.SetTitle("Preview")
self.Preview.SetMinSize((720, 486))
# end wxGlade
def __do_layout(self):
# begin wxGlade: Preview.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.Preview, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
self.Centre()
# end wxGlade
def OnCloseWindow(self, event):
self.Destroy()
end of class Preview
···
On 8/17/05, Steven Reddie smr@essemer.com.au wrote:
The simplest method would be for the preview window to hold a reference to the main window and call a previewWindowIsClosing method on the main window. There is probably a less coupled approach involving events or messages, and I know how to do that in Windows, but am new to wxPython and wxWidgets so can’t yet help you with that.
Steven
Add a reference to the preview window and initialize it when the preview window it created. One example:
class Preview(wx.Frame):
def __init__(self, main_window, *args, **kwds):
self.main_window = main_window
...
def OnCloseWindow(self, event):
self.main_window.justLettingYouKnowThatThePreviewWindowIsNowClosing()
self.Destroy()
self.main_window.thePreviewWindowIsNowClosed()
class MainWindow(wx.Frame):
def openPreviewWindow(self):
if not self.preview_window:
self.preview_window = Preview(self)
...
···
From: Ryan McDonald [mailto:mcdonald.ryan@gmail.com]
Sent: Wednesday, 17 August 2005 5:27 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Detecting an instance of a class
From within the preview window module, how would you reference the parent?
I call the preview window with:
cframe = frmPreview.Preview(None, -1, “”)
cframe.Show()
This is what my preview window looks like:
import wx
class Preview(wx.Frame):
def init(self, *args, **kwds):
# begin wxGlade: Preview.init
kwds[“style”] = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU
wx.Frame.init(self, *args, **kwds)
self.Preview = wx.Panel(self, -1)
self.__set_properties()
self.__do_layout()
# end wxGlade
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def __set_properties(self):
# begin wxGlade: Preview.__set_properties
self.SetTitle("Preview")
self.Preview.SetMinSize((720, 486))
# end wxGlade
def __do_layout(self):
# begin wxGlade: Preview.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.Preview, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
self.Centre()
# end wxGlade
def OnCloseWindow(self, event):
self.Destroy()
end of class Preview
On 8/17/05, Steven Reddie smr@essemer.com.au wrote:
The simplest method would be for the preview window to hold a reference to the main window and call a previewWindowIsClosing method on the main window. There is probably a less coupled approach involving events or messages, and I know how to do that in Windows, but am new to wxPython and wxWidgets so can’t yet help you with that.
Steven