- sdl is now default output
[enigma2.git] / components.py
index 63e5669e9e0e59af5ade944c976ecfe1b7c996a8..abf25f208988a2f24d067bdc53112152c705d5ff 100644 (file)
@@ -86,7 +86,13 @@ class GUIComponent:
 
        def __init__(self):
                pass
+               
+       def execBegin(self):
+               pass
        
+       def execEnd(self):
+               pass
+
 class VariableText:
        """VariableText can be used for components which have a variable text, based on any widget with setText call"""
        
@@ -153,7 +159,8 @@ class Clock(HTMLComponent, GUIComponent, VariableText):
 
 # "funktionalitaet"    
        def doClock(self):
-               self.setText("clock: " + time.asctime())
+               t = time.localtime()
+               self.setText("%2d:%02d:%02d" % (t[3], t[4], t[5]))
 
 # realisierung als GUI
        def createWidget(self, parent, skindata):
@@ -264,12 +271,13 @@ class MenuList(HTMLComponent, GUIComponent):
        
        def GUIdelete(self):
                self.instance.setContent(None)
+               del self.instance
 
 class ServiceList(HTMLComponent, GUIComponent):
        def __init__(self):
                GUIComponent.__init__(self)
                self.l = eListboxServiceContent()
-       
+               
        def getCurrent(self):
                r = eServiceReference()
                self.l.getCurrent(r)
@@ -284,6 +292,19 @@ class ServiceList(HTMLComponent, GUIComponent):
 
        def setRoot(self, root):
                self.l.setRoot(root)
+               
+               # mark stuff
+       def clearMarked(self):
+               self.l.clearMarked()
+       
+       def isMarked(self, ref):
+               return self.l.isMarked(ref)
+
+       def addMarked(self, ref):
+               self.l.addMarked(ref)
+       
+       def removeMarked(self, ref):
+               self.l.removeMarked(ref)
 
 class ServiceScan:
        
@@ -310,16 +331,120 @@ class ServiceScan:
                self.progressbar = progressbar
                self.text = text
                self.scan = eComponentScan()
+               self.state = self.Idle
+               self.scanStatusChanged()
+               
+       def execBegin(self):
+               self.scan.statusChanged.get().append(self.scanStatusChanged)
                if self.scan.start():
                        self.state = self.Error
                else:
                        self.state = self.Running
-               self.scan.statusChanged.get().append(self.scanStatusChanged)
                self.scanStatusChanged()
+       
+       def execEnd(self):
+               self.scan.statusChanged.get().remove(self.scanStatusChanged)
+               if not self.isDone():
+                       print "*** warning *** scan was not finished!"
 
        def isDone(self):
                return self.state == self.Done
+       
+class ActionMap:
+       def __init__(self, contexts = [ ], actions = { }, prio=0):
+               self.actions = actions
+               self.contexts = contexts
+               self.prio = prio
+               self.p = eActionMapPtr()
+               eActionMap.getInstance(self.p)
 
-       def fix(self):
-               self.scan.statusChanged.get().remove(self.scanStatusChanged)
-       
\ No newline at end of file
+       def execBegin(self):
+               for ctx in self.contexts:
+                       self.p.bindAction(ctx, self.prio, self.action)
+       
+       def execEnd(self):
+               for ctx in self.contexts:
+                       self.p.unbindAction(ctx, self.action)
+       
+       def action(self, context, action):
+               print " ".join(("action -> ", context, action))
+               try:
+                       self.actions[action]()
+               except KeyError:
+                       print "unknown action %s/%s! typo in keymap?" % (context, action)
+
+class PerServiceDisplay(GUIComponent, VariableText):
+       """Mixin for building components which display something which changes on navigation events, for example "service name" """
+       
+       def __init__(self, navcore, eventmap):
+               GUIComponent.__init__(self)
+               VariableText.__init__(self)
+               self.eventmap = eventmap
+               navcore.m_event.get().append(self.event)
+               self.navcore = navcore
+
+               # start with stopped state, so simulate that
+               self.event(pNavigation.evStopService)
+
+       def event(self, ev):
+               # loop up if we need to handle this event
+               if self.eventmap.has_key(ev):
+                       # call handler
+                       self.eventmap[ev]()
+       
+       def createWidget(self, parent, skindata):
+               # by default, we use a label to display our data.
+               g = eLabel(parent)
+               return g
+
+class EventInfo(PerServiceDisplay):
+       Now = 0
+       Next = 1
+       Now_Duration = 2
+       Next_Duration = 3
+       
+       def __init__(self, navcore, now_or_next):
+               # listen to evUpdatedEventInfo and evStopService
+               # note that evStopService will be called once to establish a known state
+               PerServiceDisplay.__init__(self, navcore, 
+                       { 
+                               pNavigation.evUpdatedEventInfo: self.ourEvent, 
+                               pNavigation.evStopService: self.stopEvent 
+                       })
+               self.now_or_next = now_or_next
+
+       def ourEvent(self):
+               info = iServiceInformationPtr()
+               service = iPlayableServicePtr()
+               
+               if not self.navcore.getCurrentService(service):
+                       if not service.info(info):
+                               ev = eServiceEventPtr()
+                               info.getEvent(ev, self.now_or_next & 1)
+                               if self.now_or_next & 2:
+                                       self.setText("%d min" % (ev.m_duration / 60))
+                               else:
+                                       self.setText(ev.m_event_name)
+               print "new event info in EventInfo! yeah!"
+
+       def stopEvent(self):
+                       self.setText("waiting for event data...");
+
+class ServiceName(PerServiceDisplay):
+       def __init__(self, navcore):
+               PerServiceDisplay.__init__(self, navcore,
+                       {
+                               pNavigation.evNewService: self.newService,
+                               pNavigation.evStopService: self.stopEvent
+                       })
+
+       def newService(self):
+               info = iServiceInformationPtr()
+               service = iPlayableServicePtr()
+               
+               if not self.navcore.getCurrentService(service):
+                       if not service.info(info):
+                               self.setText("no name known, but it should be here :)")
+       
+       def stopEvent(self):
+                       self.setText("");