IDLER_TEXT_SPEED=1.8
class Idler:
- def __init__(self, v):
+ def __init__(self, v, affinity=None):
self.v = v
+ if affinity:
+ self._affinity = affinity
+ else:
+ self._affinity = 1
def next(self):
"""Displays next stage of the idler. Returns time to the next step"""
def affinity(self):
"""How much we want this idler to be the next one chosen"""
- return 1
+ return self._affinity
class GreetingIdler(Idler):
def __init__(self, v, secs_to_greeting = None):
- self.v = v
+ affinity = 0
+ Idler.__init__(self, v, affinity = affinity)
self.secs_to_greeting = secs_to_greeting
self.message_displayed = False
def finished(self):
return self.message_displayed
- def affinity(self):
- return 0
-
class TrainIdler(Idler):
def __init__(self, v):
+ Idler.__init__(self, v)
self.idle_state = 0
- self.v = v
def put_shark(self, s, l):
if self.s[l] == ' ':
class GrayIdler(Idler):
def __init__(self, v, one=None, zero=None, reorder=0):
+ Idler.__init__(self, v)
self.bits = 8
self.size = 1 << self.bits
self.i = 0
self.grayCode = 0
- self.v = v
self.one = one
self.zero = zero
self.reorder = reorder
class StringIdler(Idler):
- def __init__(self, v, text="Hello Cruel World! ",repeat=True):
- self.v = v
+ def __init__(self, v, text="Hello Cruel World! ",repeat=True, affinity=None):
+ Idler.__init__(self, v, affinity=affinity)
self.mk = MessageKeeper(v)
self.text = self.clean_text(text) + " "
class ClockIdler(Idler):
def __init__(self, v):
- self.v = v
+ affinity = 3
+ Idler.__init__(self, v, affinity = affinity)
self.last = None
def next(self):
self.v.display(" %8.8s " % (output))
self.last = output
- def affinity(self):
- return 3
-
class FortuneIdler(StringIdler):
- def __init__(self, v):
+ def __init__(self, v, affinity = 30):
fortune = "/usr/games/fortune"
text = "I broke my wookie...."
if os.access(fortune,os.F_OK|os.X_OK):
(lines, unused) = Popen((fortune,), close_fds=True, stdout=PIPE).communicate()
text = lines.replace('\n', ' ').replace('\r', '')
- StringIdler.__init__(self, v, text,repeat=False)
+ StringIdler.__init__(self, v, text,repeat=False, affinity=affinity)
- def affinity(self):
- return 20
class PipeIdler(StringIdler):
- def __init__(self, v, command, args):
+ def __init__(self, v, command, args, affinity = 5):
text = "I ate my cookie...."
if os.access(command,os.F_OK|os.X_OK):
(lines, unused) = Popen([command,] + args.split(), close_fds=True, stdout=PIPE).communicate()
text = lines.replace('\n', ' ').replace('\r', '')
- StringIdler.__init__(self, v, text,repeat=False)
-
- def affinity(self):
- return 20
+ StringIdler.__init__(self, v, text,repeat=False, affinity=affinity)
class FileIdler(StringIdler):
def __init__(self, v, thefile=None, repeat=False, affinity=8):
text = "I broke my wookie...."
- self._affinity = affinity
if file and os.access(thefile,os.F_OK|os.R_OK):
f = file(thefile,'r')
text = string.join(f.readlines())
f.close()
- StringIdler.__init__(self, v, text,repeat=repeat)
-
- def affinity(self):
- return self._affinity
+ StringIdler.__init__(self, v, text,repeat=False, affinity=affinity)