From: Alex T. <al...@tw...> - 2005-08-04 18:17:39
|
Robert Pieczonka wrote: > Hello. > > I'd to use gauge component in the code below. I want to show > Queue.quantity in gauge (during running thread, every time when it > changed). I don't know which event i must use. I find some info about > Time event for gauge but don't understand how it works. Any suggestions? > The only events that a gauge will get (by default) are mouse events when the user clicks in, or moves over the gauge. I don't think you are interested in those - you simply want a timed event and want to update the gauge at that point in time. Assuming hat's right - see code added below. > > #---gauge.rcrc.py--- > > {'application':{'type':'Application', > 'name':'Template', > 'backgrounds': [ > {'type':'Background', > 'name':'GaugeTest', > 'size':(187, 147), > > 'components': [ > > {'type':'Gauge', > 'name':'gauge', > 'position':(4, 10), > 'size':(156, 28), > 'foregroundColor':(248, 29, 67), > 'layout':'horizontal', > 'max':100, > 'value':0, > }, > > {'type':'Button', > 'name':'startbtn', > 'position':(5, 44), > 'label':'record', > }, > ] }] } } > #--------------------------- > > > #--------gauge.py---------------------- > from threading import Thread > from threading import Condition > import time > > class Queue: > def __init__(self): > self.quantity=0 > > def produce(self): > self.quantity+=1 > > def consume(self): > self.quantity-=1 > def isEmpty(self): > return not self.quantity > > class Prod(Thread): > def __init__(self, queue, cond): > Thread.__init__(self) > self.queue=queue > self.cond=cond > def run(self): > while 1: > self.cond.acquire() > self.queue.produce() > print "Producer produce(1), quantity:",self.queue.quantity > self.cond.notifyAll() > self.cond.release() > time.sleep(1) > class Cons(Thread): > def __init__(self, queue, cond): > Thread.__init__(self) > self.queue=queue > self.cond=cond > def run(self): > while 1: > time.sleep(2) > self.cond.acquire() > while self.queue.isEmpty(): > print " >>>Quantity: 0. I'm waiting." > self.cond.wait() > self.queue.consume() > print " >>>Consumer consume(1), quantity:", > self.queue.quantity > self.cond.release() > > from PythonCard import model > class PythonCardWin(model.Background): > def on_initialize(self,event): > self.q=Queue() > self.c=Condition() > self.p=Prod(self.q,self.c) > self.c=Cons(self.q,self.c) self.timer = timer.Timer(self.components.gauge, -1) > > def on_startbtn_mouseClick(self,event): > self.p.start() > self.c.start() self.timer.start(100) # number of millisecs for timer frequency > > def on_gauge_???????(self, event): <---------------- look here def on_gauge_timer(self, event): self.components.gauge.value = ???? # whatever value you need. range is 0 to self.components.gauge.max # max can be set in resourceEditor, or by script # just to show how to do it if ????: self.timer.stop() > > if __name__ == '__main__': > app = model.Application(PythonCardWin) > app.MainLoop() > I'll try to come up with some reason to add a gauge to one of the samples (or with a new sample to demonstrate the gauge). If anyone has suggestions - or any other component type that needs a sample to demonstrate it - please tell me. -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.0/63 - Release Date: 03/08/2005 |