From: Phil E. <ph...@li...> - 2008-03-25 23:27:11
|
Okay, probably not the nicest bit of code I've ever written, but it seems to do the trick: -----begin loop-demo.rsrc.py----- {'application':{'type':'Application', 'name':'Template', 'backgrounds': [ {'type':'Background', 'name':'bgTemplate', 'title':u'Loop Demo', 'size':(380, 220), 'statusBar':1, 'style':['resizeable'], 'menubar': {'type':'MenuBar', 'menus': [ {'type':'Menu', 'name':'menuFile', 'label':'&File', 'items': [ {'type':'MenuItem', 'name':'menuFileExit', 'label':'E&xit', 'command':'exit', }, ] }, ] }, 'components': [ {'type':'StaticText', 'name':'StaticText3', 'position':(10, 45), 'text':u'environment:', }, {'type':'StaticText', 'name':'StaticText2', 'position':(10, 30), 'text':u'known as iteration) in an event-driven programming', }, {'type':'Button', 'name':'stopLoopBtn', 'position':(115, 125), 'label':u'Stop Looping', }, {'type':'Button', 'name':'startLoopBtn', 'position':(10, 125), 'label':u'Start Looping', }, {'type':'Gauge', 'name':'Gauge1', 'position':(15, 80), 'size':(345, 28), 'backgroundColor':(220, 230, 232, 255), 'layout':'horizontal', 'max':10, 'value':0, }, {'type':'StaticText', 'name':'StaticText1', 'position':(10, 15), 'text':u'This program demonstrates a way to control loops (also', }, ] # end components } # end background ] # end backgrounds } } ------end loop-demo.rsrc.py------ -----begin loop-demo.py----- #!/usr/bin/python # simple demonstration of looping # standard Python imports import time # PythonCard imports import wx from PythonCard import model class loopDemo(model.Background): def on_initialize(self, event): self.loopRunning = False self.components.stopLoopBtn.enabled = False print self.components.Gauge1.max print self.components.Gauge1.value def on_startLoopBtn_mouseClick(self, event): if not self.loopRunning: self.components.startLoopBtn.enabled = False self.components.stopLoopBtn.enabled = True self.components.Gauge1.value = 0 self.loopRunning = True self.countValue = 0 while self.countValue < self.components.Gauge1.max: self.countValue += 1 self.components.Gauge1.value = self.countValue wx.Yield() time.sleep(1) print self.countValue def on_stopLoopBtn_mouseClick(self, event): if self.loopRunning: self.loopRunning = False self.countValue = self.components.Gauge1.max + 1 self.components.startLoopBtn.enabled = True self.components.stopLoopBtn.enabled = False self.components.Gauge1.value = 0 if __name__ == '__main__': app = model.Application(loopDemo) app.MainLoop() ------end loop-demo.py------ -- Regards Phil Edwards | PGP/GnuPG Key Id Brighton, UK | 0x68393AEE |