Hi everybody !
The problem I have encountered regards the displaying of dialogue "Window
1". This dialogue can be run from "Menu/Window 1" (and it is working fine),
it can also be run from the option "Menu/Window 2". After clicking the
button "Run Window 1" the window is displayed but there is no access to it
(it can be neither moved nor switched off).
I have a lot of data to be loaded what lasts a long time and these data must
be displayed in several places of the programme. That's why I was thinking
about loading up these data just at the beginning of the programme and
display them in several places calling ShowModal() function on the
previously created dialogue. In the enclosed example Instance (win1) of
class xDialogue (representing the loading of data), Dialogue win1 is created
only in MainWindow class and is called in several different places. How can
the access to the window1 from the level of Menu/Window 2 be reached?
I will very much appreciate any helpful suggestions.
Artur
test.py (1.74 KB)
···
----------------------------------------------------------------------------
---------------------------------------------/# test.py
from wxPython.wx import *
win1=None
class xApp(wxApp):
def OnInit(self):
frame = MainWindow(NULL, "")
frame.Show(true)
self.SetTopWindow(frame)
return true
class MainWindow(wxFrame):
def __init__(self, parent, title= 'Test'):
wxFrame.__init__(self, parent, -1, title,size = (800, 600))
menu_program = wxMenu()
menu_program.Append(1, "&WINDOW1","")
menu_program.Append(2, "&WINDOW2","")
menu_program.Append(3, "Exit")
menuBar = wxMenuBar()
menuBar.Append(menu_program,"< &Test >")
self.SetMenuBar(menuBar)
self.SetAutoLayout(true)
global win1
win1 = xDialog(self)
self.Show(true)
EVT_MENU(self, 1, self.OnWindow1)
EVT_MENU(self, 2, self.OnWindow2)
EVT_MENU(self, 3,self.OnExit)
def OnWindow1(self,event):
global win1
win1.Display()
def OnWindow2(self,event):
x = xDialog2(self)
def OnExit(self,event):
global win1
win1.Destroy()
self.DestroyChildren()
self.Destroy()
class xDialog(wxDialog):
def __init__ (self,parent,id = -1 ,title="Window1",pos=(-1,-1)
,size=(400,200) ):
#wxDialog.__init__(self,NULL,id,title,pos,size,style =
wxDEFAULT_DIALOG_STYLE |wxDIALOG_NO_PARENT )
wxDialog.__init__(self,parent,id,title,pos,size, )
self.CentreOnParent(wxBOTH)
self.SetAutoLayout(true)
def Display(self):
self.ShowModal()
class xDialog2(wxDialog):
def __init__ (self,parent,id = -1 ,title="Window2",pos=(-1,-1)
,size=(600,400) ):
wxDialog.__init__(self,parent,id,title,pos,size)
self.CentreOnParent(wxBOTH)
button = wxButton(self, 10 , 'Run Window1')
EVT_BUTTON(self,10,self.OnButton)
self.SetAutoLayout(true)
self.ShowModal()
def OnButton(self,event):
global win1
win1.Display()