I have a wxpython program that defines a frame and sets it as a top and later defines another frame and sets it as the top. I use SetTopWindow. The second frame is however not showing up on top of the first frame. It is desired that it show up on top of the first frame. What am I doing wrong. Here is the code.
# copyright (c) 2006 Max M. Stalnaker
import wx import pickle import pgdb
tree=["Login",["jobs",["Jobs f/m","Jobs list"]],["Manufacturers",["Manufacturers f/m","Manufacturers list"]],["Job Code",["Job Code f/m","Job Code list"]], ["Schedules",["Schedules f/m","Schedules list"]],["Administrative",["Postgresql","Self.users"]]]
class Frame(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,parent,id,title,size=(1024,768))
class myApp(wx.App):
def __init__(self,redirect=False,filename=None,useBestVisual=False,clearSigInt=True): wx.App.__init__(self,redirect,filename,useBestVisual,clearSigInt) def OnInit(self): self.database() self.mainFrame() return True def mainFrame(self): self.frame=Frame(None,-1,"Detailing") self.panel=wx.Panel(self.frame) self.tree=wx.TreeCtrl(self.panel,style=wx.TR_HAS_BUTTONS|wx.TR_NO_LINES|wx.TR_FULL_ROW_HIGHLIGHT|wx.TR_HIDE_ROOT,size=(200,200)) self.root=self.tree.AddRoot("Menu") self.Bind(wx.EVT_TREE_ITEM_ACTIVATED,self.OnActivated,self.tree) self.Bind(wx.EVT_TREE_ITEM_EXPANDED,self.OnExpanded,self.tree) self.expanded=None self.addTreeNodes(self.root,tree) self.frame.Show() self.SetTopWindow(self.frame) return def addTreeNodes(self,root,data): for item in data: if type(item)== str: self.tree.AppendItem(root, item) else: newRoot=self.tree.AppendItem(root,item[0]) self.addTreeNodes(newRoot,item[1]) def GetItemText(self,item): if item: return self.tree.GetItemText(item) else: return "" def OnActivated(self,evt): self.literal=self.GetItemText(evt.GetItem()) if self.literal=="Login": login(self.panel) elif self.literal== "Jobs f/m": jobsfm(self.panel) elif self.literal=="Jobs List": jobslist(self.panel) elif self.literal=="Manufacturers f/m": manufactutersfm(self.panel) elif self.literal=="Manufactures list": manufacturerslist(self.panel) elif self.literal=="Job Code f/m": jobcodefm(self.panel) elif self.literal=="Job Code list": jobcodelist(self.panel) elif self.literal=="Schedules f/m": schedulesfm(self.panel) elif self.literal=="Schedules list": scheduleslist(self.panel) elif self.literal=="Postgresql": postgresql(self.panel) elif self.literal=="Self.users": self.users(self.panel) def OnExpanded(self,evt): if self.expanded: self.tree.Collapse(self.expanded) self.expanded=evt.GetItem() def databaselogin(self): self.frame2=Frame(None,-1,"Database") self.panel2=wx.Panel(self.frame2) wx.StaticText(self.panel2,-1,"Database",(30,10)) wx.StaticText(self.panel2,-1,"User",(30,50)) wx.StaticText(self.panel2,-1,"Password",(30,90)) wx.StaticText(self.panel2,-1,"Host",(30,130)) self.field1=wx.TextCtrl(self.panel2,-1,self.databasename,(130,10)) self.field2=wx.TextCtrl(self.panel2,-1,self.user,(130,50)) self.field3=wx.TextCtrl(self.panel2,-1,self.password,(130,90), style=wx.TE_PASSWORD) self.field4=wx.TextCtrl(self.panel2,-1,self.host,(130,130),size=(300,-1) ) self.button=wx.Button(self.panel2,-1,"Save",(130,170)) self.Bind(wx.EVT_BUTTON,self.OnClick,self.button) self.SetTopWindow(self.frame2) self.frame2.Show() self.field1.SetInsertionPoint(0) self.field1.ShowPosition(0) self.field1.SetSelection(0,0) self.field1.SetFocus() return def OnClick(self,event): self.databasename=self.field1.GetValue() self.user=self.field2.GetValue() self.password=self.field3.GetValue() self.host=self.field4.GetValue() self.fp=file("detailing.dat","wb") pickle.dump([self.databasename,self.host,self.user,self.password],self.fp,-1) self.fp.close() try: db=pgdb.connect(user=self.user,password=self.password,database=self.databasename,host=self.host) except: return return def database(self): self.databasename="" self.host="" self.user="" self.password="" try: self.fp=file("detailing.dat","rb") except IOError: self.fp=file("detailing.dat","wb") pickle.dump([self.databasename,self.host,self.user,self.password],self.fp,-1) self.fp.close() self.fp=file("detailing.dat","rb") [self.databasename,self.host,self.user,self.password]=pickle.load(self.fp) self.fp.close() if self.databasename=="": missingadminuser=True else: missingadminuser=False try: db=pgdb.connect(user=self.user,password=self.password,database=self.databasename,host=self.host) except: self.databaselogin() return app=myApp() app.MainLoop()
|