a36d4a6045131142f65ec7fd972f34e0d8213992
[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, with_event=False):
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                 self.with_event = with_event
16                 
17                 # start with stopped state, so simulate that
18                 self.event(iPlayableService.evEnd)
19
20         def destroy(self):
21                 self.navcore.event.remove(self.event)
22
23         def event(self, ev):
24                 # loop up if we need to handle this event
25                 if self.eventmap.has_key(ev):
26                         # call handler
27                         if self.with_event:
28                                 self.eventmap[ev](ev)
29                         else:
30                                 self.eventmap[ev]()
31         
32         def enablePolling(self, interval=60000):
33                 if interval:
34                         self.poll_timer.start(interval)
35                 else:
36                         self.poll_timer.stop()
37         
38         def disablePolling(self):
39                 self.enablePolling(interval=0)
40
41         def poll(self):
42                 pass
43
44 class PerServiceDisplay(PerServiceBase, VariableText, GUIComponent):
45         """Mixin for building components which display something which changes on navigation events, for example "service name" """
46         def __init__(self, navcore, eventmap):
47                 GUIComponent.__init__(self)
48                 VariableText.__init__(self)
49                 PerServiceBase.__init__(self, navcore, eventmap)
50
51         GUI_WIDGET = eLabel
52
53 class PerServiceDisplayProgress(PerServiceBase, VariableValue, GUIComponent):
54         def __init__(self, navcore, eventmap):
55                 GUIComponent.__init__(self)
56                 VariableValue.__init__(self)
57                 self.eventmap = eventmap
58                 self.navcore = navcore
59                 self.navcore.event.append(self.event)
60
61                 # start with stopped state, so simulate that
62                 self.event(iPlayableService.evEnd)
63
64         GUI_WIDGET = eSlider