500538c3d56708dd5cc97a512f61b57703779ace
[enigma2.git] / lib / python / Components / PerServiceDisplay.py
1 from GUIComponent import *
2 from VariableText import *
3 from VariableValue import *
4
5 from enigma import iPlayableService
6 from enigma import eLabel, eSlider, eTimer
7
8 class PerServiceBase(object):
9         def __init__(self, navcore, eventmap):
10                 self.eventmap = eventmap
11                 self.navcore = navcore
12                 self.navcore.event.append(self.event)
13                 self.poll_timer = eTimer()
14                 self.poll_timer.timeout.get().append(self.poll)
15                 
16                 # start with stopped state, so simulate that
17                 self.event(iPlayableService.evEnd)
18
19         def destroy(self):
20                 self.navcore.event.remove(self.event)
21
22         def event(self, ev):
23                 # loop up if we need to handle this event
24                 if self.eventmap.has_key(ev):
25                         # call handler
26                         self.eventmap[ev]()
27         
28         def enablePolling(self, interval=60000):
29                 if interval:
30                         self.poll_timer.start(interval)
31                 else:
32                         self.poll_timer.stop()
33         
34         def disablePolling(self):
35                 self.enablePolling(interval=0)
36
37         def poll(self):
38                 pass
39
40 class PerServiceDisplay(PerServiceBase, VariableText, GUIComponent):
41         """Mixin for building components which display something which changes on navigation events, for example "service name" """
42         def __init__(self, navcore, eventmap):
43                 GUIComponent.__init__(self)
44                 VariableText.__init__(self)
45                 PerServiceBase.__init__(self, navcore, eventmap)
46
47         GUI_WIDGET = eLabel
48
49 class PerServiceDisplayProgress(PerServiceBase, VariableValue, GUIComponent):
50         def __init__(self, navcore, eventmap):
51                 GUIComponent.__init__(self)
52                 VariableValue.__init__(self)
53                 self.eventmap = eventmap
54                 self.navcore = navcore
55                 self.navcore.event.append(self.event)
56
57                 # start with stopped state, so simulate that
58                 self.event(iPlayableService.evEnd)
59
60         GUI_WIDGET = eSlider