/[anoncvs]/projects/dispense2/sql-edition/servers/MessageKeeper.py


UCC Code Repository

Contents of /projects/dispense2/sql-edition/servers/MessageKeeper.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download) (as text)
Wed Sep 29 10:24:37 2004 UTC (16 years, 7 months ago) by mtearle
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/x-python
one shot stuff done

1 #!/usr/bin/python
2 # vim:ts=4
3
4 import sys, os, string, re, pwd, signal
5 from HorizScroll import HorizScroll
6 from random import random, seed
7 from time import time, sleep
8
9 class MessageKeeper:
10 def __init__(self, vendie):
11 # Each element of scrolling_message should be a 3-tuple of
12 # ('message', True/False if it is to be repeated, time to display)
13 self.scrolling_message = []
14 self.v = vendie
15 self.next_update = None
16
17 def set_message(self, string):
18 self.scrolling_message = [(string, False, None)]
19 self.update_display(True)
20
21 def set_messages(self, strings):
22 self.scrolling_message = strings
23 self.update_display(True)
24
25 def update_display(self, forced = False, padding = 0):
26 if not forced and self.next_update != None and time() < self.next_update:
27 return
28 if len(self.scrolling_message) > 0:
29 if len(self.scrolling_message[0][0]) > 10:
30 (m, r, t) = self.scrolling_message[0]
31 a = []
32 exp = HorizScroll(m).expand(padding, wraparound = r)
33 if t == None:
34 t = 0.1
35 else:
36 t = t / len(exp)
37 for x in exp:
38 a.append((x, r, t))
39 del self.scrolling_message[0]
40 self.scrolling_message = a + self.scrolling_message
41 newmsg = self.scrolling_message[0]
42 if newmsg[2] != None:
43 self.next_update = time() + newmsg[2]
44 else:
45 self.next_update = None
46 self.v.display(self.scrolling_message[0][0])
47 if self.scrolling_message[0][1]:
48 self.scrolling_message.append(self.scrolling_message[0])
49 del self.scrolling_message[0]
50
51 def done(self):
52 return len(self.scrolling_message) == 0
53

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26