From: Liam C. <cy...@gm...> - 2005-04-09 03:44:35
|
I am confused. What are you trying to do exactly? >I cannot seem to find a way to reference the worldclock instance object so= =20 that my controller can >use it's methods to update the GUI. the snippet I= =20 think relates is: So, are you trying to access the original worldclock, or your own class? Consider making your Pythoncard class your controller, as it will be the on= e=20 responding to events. I have a similar case -=20 from PythonCard import model, dialog import dao import ConfigParser import search class Main(model.Background): def on_initialize(self, event): db =3D self.getCfg() self.SQLWrapper =3D dao.DAO(db) self.Show() def getCfg(self): cfg =3D ConfigParser.ConfigParser() cfg.read('./config.ini') dbFile =3D cfg.get('Database details', 'filename') return dbFile def on_clients_mouseClick(self, event): searchWindow =3D model.childWindow(self, search.SearchClient) searchWindow.DAO =3D self.SQLWrapper if __name__=3D=3D'__main__': app=3Dmodel.Application(Main) app.MainLoop() From the main class, references to the database access object are passed to= =20 each child window. Child windows can open other children windows, but they= =20 always assign the above class as the parent, so the Main class will always= =20 stick around. On Apr 9, 2005 2:30 AM, Sells, Fred <fr...@ad...> wrote: >=20 > I have a single window PythonCard app plus a few more classes to wrap=20 > access to a DB, Serial IO and a directory of jpg's. > I would like to pull everything together in a Controller.py module which= =20 > would be able to access the my PythonCard module (i.e. the one that=20 > matches the PythonCard resource file). I started off using the worldclock= =20 > demo from the samples directory and have significantly gutted it to fit m= y=20 > needs. > I cannot seem to find a way to reference the worldclock instance object= =20 > so that my controller can use it's methods to update the GUI. the snippet= I=20 > think relates is: > app =3D model.Application(WorldClock) > app.MainLoop() > I tried doing a "dir()" on app, but didn't recognize anything as giving= =20 > me access to the instance of WordClock.=20 > I realize I could make WorldClock my "Controller", but that's just not= =20 > the way I see the design. After all this, by questions are: > 1. is there a way to reference the instance of WorldClock, or > 2. am I looking into the wrong end of the pipe for PythonCard and should = I=20 > make WorldClock.py my primary controller? > I've included the entire source for WorldClock.py below, for what it's= =20 > worth: > #!/usr/bin/python > =20 > import urllib > import os > import time > import wx > from cStringIO import StringIO > from PythonCard import graphic, log, model, timer > #from PythonCard.log import Log > class WorldClock(model.Background): > def on_initialize(self, event): > self.clockTimer =3D timer.Timer(self.components.staticTextClock, -1) > self.clockTimer.start(1000) # 1 second > self.updateDateAndTime() > def on_staticTextClock_timer(self, event): > self.updateDateAndTime() > def updateDateAndTime(self):=20 > t =3D time.strftime("%I:%M %p") > if t[0] =3D=3D "0": t =3D t[1:] > d =3D time.strftime("%A, %B %d, %Y") > self.components.staticTextClock.text =3D d+" "+t >=20 > def on_imageButtonWorld_timer(self, event): > print "imageButtonWorld_timer" >=20 > def on_Leave_mouseClick(self, event): > print "clicked leave" > def on_Arrive_mouseClick(self, event): > print "arrive" > def on_showHistory_mouseClick(self, event): > print "history" > def on_close(self, event): > self.clockTimer.stop() > event.skip() >=20 > def setEmployee(self, employee): > self.components.Name.text =3D employee.getFullName() > bmp =3D graphic.Bitmap(employee.getPictureFilename()) > if employee.LName=3D=3D'BURRILL': > bmp.rotate180(1) > =20 > def createApplication(): > app =3D model.Application(WorldClock) > for d in dir(app):print d > app.MainLoop() > ##mainloop never returns. > if __name__ =3D=3D '__main__': > createApplication() > =20 --=20 'There is only one basic human right, and that is to do as you damn well=20 please. And with it comes the only basic human duty, to take the consequences. |