handle case of empty text
[enigma2.git] / lib / python / Components / PerServiceDisplay.py
1 from GUIComponent import GUIComponent
2 from VariableText import VariableText
3 from VariableValue import VariableValue
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_callback)
13                 self.poll_timer = eTimer()
14                 self.poll_timer.callback.append(self.poll)
15                 self.with_event = with_event
16                 
17                 # start with stopped state, so simulate that
18                 self.event_callback(iPlayableService.evEnd)
19
20         def destroy(self):
21                 self.navcore.event.remove(self.event_callback)
22
23         def event_callback(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                 PerServiceBase.__init__(self, navcore, eventmap)
58                 self.eventmap = eventmap
59                 self.navcore = navcore
60                 self.navcore.event.append(self.event)
61
62                 # start with stopped state, so simulate that
63                 self.event(iPlayableService.evEnd)
64
65         GUI_WIDGET = eSlider