okay... still bugs with StringIdler
[uccvend-vendserver.git] / sql-edition / servers / MessageKeeper.py
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
8 class MessageKeeper:
9         def __init__(self, vendie):
10                 # Each element of scrolling_message should be a 3-tuple of
11                 # ('message', True/False if it is to be repeated, time to display)
12                 self.scrolling_message = []
13                 self.v = vendie
14                 self.next_update = None
15
16         def set_message(self, string):
17                 self.scrolling_message = [(string, False, None)]
18                 self.update_display(True)
19
20         def set_messages(self, strings):
21                 self.scrolling_message = strings
22                 self.update_display(True)
23
24         def update_display(self, forced = False):
25                 if not forced and self.next_update != None and time() < self.next_update:
26                         return
27                 if len(self.scrolling_message) > 0:
28                         if len(self.scrolling_message[0][0]) > 10:
29                                 (m, r, t) = self.scrolling_message[0]
30                                 a = []
31                                 exp = HorizScroll(m).expand(padding = 0, wraparound = True)
32                                 if t == None:
33                                         t = 0.1
34                                 else:
35                                         t = t / len(exp)
36                                 for x in exp:
37                                         a.append((x, r, t))
38                                 del self.scrolling_message[0]
39                                 self.scrolling_message = a + self.scrolling_message
40                         newmsg = self.scrolling_message[0]
41                         if newmsg[2] != None:
42                                 self.next_update = time() + newmsg[2]
43                         else:
44                                 self.next_update = None
45                         self.v.display(self.scrolling_message[0][0])
46                         if self.scrolling_message[0][1]:
47                                 self.scrolling_message.append(self.scrolling_message[0])
48                         del self.scrolling_message[0]
49
50         def done(self):
51                 return len(self.scrolling_message) == 0
52

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