MyApp now creating 2 instances of MyFrame
Michael Barron
barronmo at gmail.com
Fri Nov 30 08:24:06 PST 2007
I'm having an unusual problem with my code generating 2 instances of a
frame, neither of which are working correctly. The frame can no longer see
a class called Repository in another module. This has been working fine for
a long time until yesterday when I changed the code in MyApp to replace
__init__ with OnInit. I also added the database login stuff which was part
of another module. I've since changed it back but the problem remains.
Here is the code:
import wx
import sys
sys.path.append('~/PyPrograms/EMRGUI')
import Selectable
import MySQLdb
class MyApp(wx.App):
def __init__(self):
wx.App.__init__(self)
self.conn =3D MySQLdb.connect(host =3D "localhost", #connects to=
the
database
user =3D "someuser",
passwd =3D "somepw",
db =3D "meds")
frame =3D MyFrame(None, -1, 'EMR') #create instan=
ce
of MyFrame
frame.Show(True) #make visible and
center frame
frame.Centre()
def OnExit(self):
self.conn.close() #closes
connection to MySQL
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=3D(900,550))
self.nb =3D wx.Notebook(self) #create instance=
of
wx.Notebook
self.page1 =3D Form1(self.nb, -1) #create instance=
of
panel Form1 with Notebook instance as parent
self.nb.AddPage(self.page1, "Choose Patient") #add the panels as
Notebook pages
def patient_lookup(self, first_ltrs): #passes
first letters of last name and creates new page c results
self.page2 =3D Selectable.Repository(self.nb, -1, first_ltrs)
#creates instance of panel Repository
self.nb.AddPage(self.page2, "Patient Lookup") #adds
second page with results
self.page2.SetFocus() #give
focus to new page (this isn't working)
class Form1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
#inherits from wx.Panel
self.button =3D wx.Button(self, 10, "Search", wx.Point(225, 100))
#create instance of wx.Button
wx.Button.SetTransparent(self.button, 100)
#experiment with SetTransparent method
self.lblname =3D wx.StaticText(self, -1, "Enter first letters of la=
st
name:",wx.Point(20,65))
self.editname =3D wx.TextCtrl(self, 20, "", wx.Point(225, 60), wx.S=
ize
(140,-1))
wx.EVT_BUTTON(self, 10, self.onClick)
#calls function to get list of patients
self.editname.SetFocus()
def onClick(self, event):
f =3D wx.GetTopLevelParent(self)
#gets reference to instance of MyFrame
f.patient_lookup(self.editname.Value)
#now calling the MyFrame function works
app =3D MyApp()
#create instance of MyApp
app.MainLoop()
#run program
Thanks for any help.
Mike Barron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200711=
30/3fada865/attachment.htm
More information about the wxpython-users
mailing list