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 = MySQLdb.connect(host = "localhost", #connects to the database
user = "someuser",
passwd = "somepw",
db = "meds")
frame = MyFrame(None, -1, 'EMR') #create instance 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=(900,550))
self.nb = wx.Notebook(self) #create instance of wx.Notebook
self.page1 = 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 = 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 = 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 = wx.StaticText(self, -1, "Enter first letters of last name:",wx.Point(20,65))
self.editname = wx.TextCtrl(self, 20, "", wx.Point(225, 60), wx.Size(140,-1))
wx.EVT_BUTTON(self, 10, self.onClick) #calls function to get list of patients
self.editname.SetFocus()
def onClick(self, event):
f = wx.GetTopLevelParent(self) #gets reference to instance of MyFrame
f.patient_lookup(self.editname.Value) #now calling the MyFrame function works
app = MyApp() #create instance of MyApp
app.MainLoop() #run program
Thanks for any help.
Mike Barron