Added StringIdler
authorMark Tearle <[email protected]>
Tue, 21 Sep 2004 09:57:30 +0000 (09:57 +0000)
committerMark Tearle <[email protected]>
Tue, 21 Sep 2004 09:57:30 +0000 (09:57 +0000)
Factored out into own file MessageKeeper

sql-edition/servers/Idler.py
sql-edition/servers/MessageKeeper.py [new file with mode: 0755]
sql-edition/servers/VendServer.py

index 5ffea0b..80963a8 100755 (executable)
@@ -2,6 +2,7 @@
 
 import string
 from random import random
+from MessageKeeper import MessageKeeper
 
 orderings = None
 
@@ -179,3 +180,16 @@ class GrayIdler(Idler):
                self.grayCode = 0
                if self.reorder:
                        self.reorder = int(random()*40319)+1
+
+
+class StringIdler(Idler):
+       def __init__(self, v, text="Hello Cruel World!"):
+               self.v = v
+               self.mk = MessageKeeper(v)
+               self.text = text
+
+       def next(self):
+               self.mk.update_display()
+
+       def reset(self):
+               self.mk.set_message(self.text, True, None)
diff --git a/sql-edition/servers/MessageKeeper.py b/sql-edition/servers/MessageKeeper.py
new file mode 100755 (executable)
index 0000000..e9dee51
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+# vim:ts=4
+
+import sys, os, string, re, pwd, signal
+from HorizScroll import HorizScroll
+from random import random, seed
+
+class MessageKeeper:
+       def __init__(self, vendie):
+               # Each element of scrolling_message should be a 3-tuple of
+               # ('message', True/False if it is to be repeated, time to display)
+               self.scrolling_message = []
+               self.v = vendie
+               self.next_update = None
+
+       def set_message(self, string):
+               self.scrolling_message = [(string, False, None)]
+               self.update_display(True)
+
+       def set_messages(self, strings):
+               self.scrolling_message = strings
+               self.update_display(True)
+
+       def update_display(self, forced = False):
+               if not forced and self.next_update != None and time() < self.next_update:
+                       return
+               if len(self.scrolling_message) > 0:
+                       if len(self.scrolling_message[0][0]) > 10:
+                               (m, r, t) = self.scrolling_message[0]
+                               a = []
+                               exp = HorizScroll(m).expand(padding = 0, wraparound = True)
+                               if t == None:
+                                       t = 0.1
+                               else:
+                                       t = t / len(exp)
+                               for x in exp:
+                                       a.append((x, r, t))
+                               del self.scrolling_message[0]
+                               self.scrolling_message = a + self.scrolling_message
+                       newmsg = self.scrolling_message[0]
+                       if newmsg[2] != None:
+                               self.next_update = time() + newmsg[2]
+                       else:
+                               self.next_update = None
+                       self.v.display(self.scrolling_message[0][0])
+                       if self.scrolling_message[0][1]:
+                               self.scrolling_message.append(self.scrolling_message[0])
+                       del self.scrolling_message[0]
+
+       def done(self):
+               return len(self.scrolling_message) == 0
+
index 45288f1..71097bb 100755 (executable)
@@ -12,12 +12,22 @@ from time import time, sleep
 from popen2 import popen2
 from LATClient import LATClient, LATClientException
 from VendingMachine import VendingMachine, VendingException
+from MessageKeeper import MessageKeeper
 from HorizScroll import HorizScroll
 from random import random, seed
-from Idler import TrainIdler,GrayIdler
+from Idler import TrainIdler,GrayIdler,StringIdler
 import socket
 from posix import geteuid
 
+CREDITS="""
+This vending machine software brought to you by:
+Bernard Blackham
+Mark Tearle
+Nick Bannon
+Cameron Patrick
+and a collective of hungry alpacas.
+"""
+
 GREETING = 'UCC SNACKS'
 PIN_LENGTH = 4
 
@@ -164,50 +174,7 @@ def center(str):
        LEN = 10
        return ' '*((LEN-len(str))/2)+str
 
-class MessageKeeper:
-       def __init__(self, vendie):
-               # Each element of scrolling_message should be a 3-tuple of
-               # ('message', True/False if it is to be repeated, time to display)
-               self.scrolling_message = []
-               self.v = vendie
-               self.next_update = None
-
-       def set_message(self, string):
-               self.scrolling_message = [(string, False, None)]
-               self.update_display(True)
-
-       def set_messages(self, strings):
-               self.scrolling_message = strings
-               self.update_display(True)
-
-       def update_display(self, forced = False):
-               if not forced and self.next_update != None and time() < self.next_update:
-                       return
-               if len(self.scrolling_message) > 0:
-                       if len(self.scrolling_message[0][0]) > 10:
-                               (m, r, t) = self.scrolling_message[0]
-                               a = []
-                               exp = HorizScroll(m).expand(padding = 0, wraparound = True)
-                               if t == None:
-                                       t = 0.1
-                               else:
-                                       t = t / len(exp)
-                               for x in exp:
-                                       a.append((x, r, t))
-                               del self.scrolling_message[0]
-                               self.scrolling_message = a + self.scrolling_message
-                       newmsg = self.scrolling_message[0]
-                       if newmsg[2] != None:
-                               self.next_update = time() + newmsg[2]
-                       else:
-                               self.next_update = None
-                       self.v.display(self.scrolling_message[0][0])
-                       if self.scrolling_message[0][1]:
-                               self.scrolling_message.append(self.scrolling_message[0])
-                       del self.scrolling_message[0]
 
-       def done(self):
-               return len(self.scrolling_message) == 0
 
 idlers = []
 idler = None
@@ -215,6 +182,8 @@ def setup_idlers(v):
        global idlers, idler
        idlers = [
                TrainIdler(v),
+               StringIdler(v),
+               StringIdler(v, text=CREDITS),
                GrayIdler(v),
                GrayIdler(v,one="*",zero="-"),
                GrayIdler(v,one="/",zero="\\"),

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