add support for one shot Idlers
authorMark Tearle <mtearle@ucc.gu.uwa.edu.au>
Wed, 29 Sep 2004 10:02:23 +0000 (10:02 +0000)
committerMark Tearle <mtearle@ucc.gu.uwa.edu.au>
Wed, 29 Sep 2004 10:02:23 +0000 (10:02 +0000)
sql-edition/servers/Idler.py
sql-edition/servers/VendServer.py

index 48e819a..a231d96 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import string
+import string, time
 from random import random
 from MessageKeeper import MessageKeeper
 
@@ -15,6 +15,9 @@ class Idler:
 
        def reset(self):
                pass
+       
+       def finished(self):
+               return False
 
 class TrainIdler(Idler):
        def __init__(self, v):
@@ -210,6 +213,13 @@ class StringIdler(Idler):
        def next(self):
                self.mk.update_display()
 
-       def reset(self):
-               pass
-               #self.mk.update_display(forced=True)
+class ClockIdler(Idler):
+       def __init__(self, v):
+               self.v = v
+               self.last = None
+
+       def next(self):
+               output = time.strftime("%H:%M:%S")
+               if output != self.last:
+                       self.v.display(" %8.8s " % (output))
+                       self.last = output
index c82dda8..eda4dc9 100755 (executable)
@@ -15,7 +15,7 @@ from VendingMachine import VendingMachine, VendingException
 from MessageKeeper import MessageKeeper
 from HorizScroll import HorizScroll
 from random import random, seed
-from Idler import TrainIdler,GrayIdler,StringIdler
+from Idler import TrainIdler,GrayIdler,StringIdler,ClockIdler
 import socket
 from posix import geteuid
 
@@ -189,6 +189,7 @@ idler = None
 def setup_idlers(v):
        global idlers, idler
        idlers = [
+               ClockIdler(v),
                StringIdler(v),
                StringIdler(v, text=CREDITS),
                StringIdler(v, text=str(math.pi) + "            "),
@@ -211,6 +212,8 @@ def choose_idler():
 
 def idle_step():
        global idler
+       if idler.finished():
+               choose_idler()
        idler.next()
 
 def run_forever(rfh, wfh, options, cf):

UCC git Repository :: git.ucc.asn.au