F
fiddlehead
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?
#---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)
def on_startbtn_mouseClick(self,event):
self.p.start()
self.c.start()
def on_gauge_???????(self, event):
??????????/
if __name__ == '__main__':
app = model.Application(PythonCardWin)
app.MainLoop()
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?
#---gauge.rcrc.py---
{'application':{'type':'Application',
'name':'Template',
'backgrounds': [
{'type':'Background',
'name':'GaugeTest',
'size'
'components': [
{'type':'Gauge',
'name':'gauge',
'position'
'size'
'foregroundColor'
'layout':'horizontal',
'max':100,
'value':0,
},
{'type':'Button',
'name':'startbtn',
'position'
'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)
def on_startbtn_mouseClick(self,event):
self.p.start()
self.c.start()
def on_gauge_???????(self, event):
??????????/
if __name__ == '__main__':
app = model.Application(PythonCardWin)
app.MainLoop()