help: improve key description, a bit.
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
index 8314182..b883272 100644 (file)
@@ -1,34 +1,39 @@
 from Screen import Screen
-from Components.ActionMap import ActionMap
+from Components.ActionMap import ActionMap, HelpableActionMap
 from Components.ActionMap import NumberActionMap
 from Components.Label import Label
-from Components.config import configfile
+from Components.config import configfile, configsequencearg
+from Components.config import config, configElement, ConfigSubsection, configSequence
 from ChannelSelection import ChannelSelection
 
-
 from Components.ServiceName import ServiceName
 from Components.EventInfo import EventInfo
-from Components.ServicePosition import ServicePosition
 
+from ServiceReference import ServiceReference
 from EpgSelection import EPGSelection
 
 from Screens.MessageBox import MessageBox
-from Screens.MovieSelection import MovieSelection
 from Screens.Volume import Volume
 from Screens.Mute import Mute
 from Screens.Standby import Standby
+from Screens.EventView import EventView
 
 #from enigma import eTimer, eDVBVolumecontrol, quitMainloop
 from enigma import *
 
+import time
+import os
+
 # hack alert!
 from Menu import MainMenu, mdom
 
 class InfoBarVolumeControl:
        """Volume control, handles volUp, volDown, volMute actions and display 
        a corresponding dialog"""
-       
        def __init__(self):
+               config.audio = ConfigSubsection()
+               config.audio.volume = configElement("config.audio.volume", configSequence, [5], configsequencearg.get("INTEGER", (0, 100)))
+
                self["VolumeActions"] = ActionMap( ["InfobarVolumeActions"] ,
                        {
                                "volumeUp": self.volUp,
@@ -41,17 +46,27 @@ class InfoBarVolumeControl:
 
                self.hideVolTimer = eTimer()
                self.hideVolTimer.timeout.get().append(self.volHide)
+
+               vol = config.audio.volume.value[0]
+               self.volumeDialog.setValue(vol)
+               eDVBVolumecontrol.getInstance().setVolume(vol, vol)
        
+       def volSave(self):
+               config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
+               config.audio.volume.save()
+               
        def     volUp(self):
                eDVBVolumecontrol.getInstance().volumeUp()
                self.volumeDialog.instance.show()
                self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
+               self.volSave()
                self.hideVolTimer.start(3000)
 
        def     volDown(self):
                eDVBVolumecontrol.getInstance().volumeDown()
                self.volumeDialog.instance.show()
                self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
+               self.volSave()
                self.hideVolTimer.start(3000)
                
        def volHide(self):
@@ -81,11 +96,16 @@ class InfoBarShowHide:
                                "hide": self.hide,
                        })
 
-               self.state = self.STATE_HIDDEN
+               self.state = self.STATE_SHOWN
+               
+               self.onClose.append(self.delHideTimer)
                
                self.hideTimer = eTimer()
                self.hideTimer.timeout.get().append(self.doTimerHide)
-               #self.hideTimer.start(1000)
+               self.hideTimer.start(1000)
+
+       def delHideTimer(self):
+               del self.hideTimer
 
        def hide(self): 
                self.instance.hide()
@@ -119,12 +139,11 @@ class InfoBarShowHide:
 class NumberZap(Screen):
        def quit(self):
                self.Timer.stop()
-               self.close()
+               self.close(0)
 
        def keyOK(self):
                self.Timer.stop()
-               print "do the action here"
-               self.close()
+               self.close(int(self["number"].getText()))
 
        def keyNumberGlobal(self, number):
                self.Timer.start(3000)          #reset timer
@@ -133,8 +152,8 @@ class NumberZap(Screen):
                if len(self.field) >= 4:
                        self.keyOK()
 
-       def __init__(self, number):
-               Screen.__init__(self)
+       def __init__(self, session, number):
+               Screen.__init__(self, session)
                self.field = str(number)
                
                self["number"] = Label(self.field)
@@ -165,10 +184,12 @@ class InfoBarPowerKey:
        def __init__(self):
                self.powerKeyTimer = eTimer()
                self.powerKeyTimer.timeout.get().append(self.powertimer)
-               self["PowerKeyActions"] = ActionMap( ["PowerKeyActions"],
+               self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
                        {
                                "powerdown": self.powerdown,
                                "powerup": self.powerup,
+                               "discreteStandby": (self.standby, "Go standby"),
+                               "discretePowerOff": (self.quit, "Go to deep standby"),
                        })
 
        def powertimer(self):   
@@ -183,13 +204,14 @@ class InfoBarPowerKey:
                self.powerKeyTimer.stop()
                if self.standbyblocked == 0:
                        self.standbyblocked = 1
-                       self.session.open(Standby, self)
+                       self.standby()
 
-       def quit(self):
-               #       self.session.open(Standby, self)
-               configfile.save()
-               quitMainloop(0)
+       def standby(self):
+               self.session.open(Standby, self)
 
+       def quit(self):
+               # halt
+               quitMainloop(1)
 
 class InfoBarNumberZap:
        """ Handles an initial number for NumberZapping """
@@ -209,8 +231,13 @@ class InfoBarNumberZap:
                        })
 
        def keyNumberGlobal(self, number):
-               print "You pressed number " + str(number)
-               self.session.open(NumberZap, number)
+#              print "You pressed number " + str(number)
+               self.session.openWithCallback(self.numberEntered, NumberZap, number)
+
+       def numberEntered(self, retval):
+#              print self.servicelist
+               if retval > 0:
+                       self.servicelist.zapToNumber(retval)
 
 class InfoBarChannelSelection:
        """ ChannelSelection - handles the channelSelection dialog and the initial 
@@ -219,12 +246,12 @@ class InfoBarChannelSelection:
                #instantiate forever
                self.servicelist = self.session.instantiateDialog(ChannelSelection)
 
-               self["ChannelSelectActions"] = ActionMap( ["InfoBarChannelSelection"],
+               self["ChannelSelectActions"] = HelpableActionMap(self, "InfobarChannelSelection",
                        {
                                "switchChannelUp": self.switchChannelUp,
                                "switchChannelDown": self.switchChannelDown,
-                               "zapUp": self.zapUp,
-                               "zapDown": self.zapDown,
+                               "zapUp": (self.zapUp, _("next channel")),
+                               "zapDown": (self.zapDown, _("previous channel")),
                        })
                        
        def switchChannelUp(self):      
@@ -246,9 +273,9 @@ class InfoBarChannelSelection:
 class InfoBarMenu:
        """ Handles a menu action, to open the (main) menu """
        def __init__(self):
-               self["MenuActions"] = ActionMap( [ "InfoBarMenuActions" ]
+               self["MenuActions"] = HelpableActionMap(self, "InfobarMenuActions"
                        {
-                               "mainMenu": self.mainMenu,
+                               "mainMenu": (self.mainMenu, "Enter main menu..."),
                        })
 
        def mainMenu(self):
@@ -260,9 +287,9 @@ class InfoBarMenu:
 class InfoBarEPG:
        """ EPG - Opens an EPG list when the showEPGList action fires """
        def __init__(self):
-               self["EPGActions"] = ActionMap( [ "InfobarEPGActions" ]
+               self["EPGActions"] = HelpableActionMap(self, "InfobarEPGActions"
                        {
-                               "showEPGList": self.showEPGList,
+                               "showEPGList": (self.showEPGList, _("show EPG...")),
                        })
 
        def showEPGList(self):
@@ -270,10 +297,31 @@ class InfoBarEPG:
                ptr=eEPGCache.getInstance()
                if ptr.startTimeQuery(ref) != -1:
                        self.session.open(EPGSelection, ref)
-               else:
+               else: # try to show now/next
                        print 'no epg for service', ref.toString()
-
-class InfoBarEvent:    
+                       try:
+                               self.epglist = [ ]
+                               service = self.session.nav.getCurrentService()
+                               info = service.info()
+                               ptr=info.getEvent(0)
+                               if ptr:
+                                       self.epglist.append(ptr)
+                               ptr=info.getEvent(1)
+                               if ptr:
+                                       self.epglist.append(ptr)
+                               if len(self.epglist) > 0:
+                                       self.session.open(EventView, self.epglist[0], ServiceReference(ref), self.eventViewCallback)
+                       except:
+                               pass
+
+       def eventViewCallback(self, setEvent, val): #used for now/next displaying
+               if len(self.epglist) > 1:
+                       tmp = self.epglist[0]
+                       self.epglist[0]=self.epglist[1]
+                       self.epglist[1]=tmp
+                       setEvent(self.epglist[0])
+
+class InfoBarEvent:
        """provides a current/next event info display"""
        def __init__(self):
                self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
@@ -292,13 +340,13 @@ class InfoBarServiceName:
 class InfoBarPVR:
        """handles PVR specific actions like seeking, pause"""
        def __init__(self):
-               self["PVRActions"] = ActionMap( [ "InfobarPVRActions" ]
+               self["PVRActions"] = HelpableActionMap(self, "InfobarPVRActions"
                        {
-                               "pauseService": self.pauseService,
-                               "unPauseService": self.unPauseService,
+                               "pauseService": (self.pauseService, "pause"),
+                               "unPauseService": (self.unPauseService, "continue"),
                                
-                               "seekFwd": self.seekFwd,
-                               "seekBack": self.seekBack,
+                               "seekFwd": (self.seekFwd, "skip forward"),
+                               "seekBack": (self.seekBack, "skip backward"),
                        })
                
        def pauseService(self):
@@ -318,18 +366,18 @@ class InfoBarPVR:
                seekable.seekRelative(dir, 90 * seektime)
 
        def seekFwd(self):
-               self.doSeek(+1, 10000)
+               self.doSeek(+1, 60000)
        
        def seekBack(self):
-               self.doSeek(-1, 10000)
+               self.doSeek(-1, 60000)
 
 class InfoBarInstantRecord:
        """Instant Record - handles the instantRecord action in order to 
        start/stop instant records"""
        def __init__(self):
-               self["InstnantRecordActions"] = ActionMap( [ "InfoBarInstantRecord" ],
+               self["InstnantRecordActions"] = HelpableActionMap(self, "InfobarInstantRecord",
                        {
-                               "instantRecord": self.instantRecord,
+                               "instantRecord": (self.instantRecord, "Instant Record..."),
                        })
                self.recording = None
 
@@ -352,6 +400,7 @@ class InfoBarInstantRecord:
                
                # fix me, description. 
                self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
+               self.recording.dontSave = True
 
        def recordQuestionCallback(self, answer):
                if answer == False:
@@ -363,7 +412,29 @@ class InfoBarInstantRecord:
                        self.startInstantRecording()
 
        def instantRecord(self):
+               try:
+                       stat = os.stat("/hdd/movies")
+               except:
+                       self.session.open(MessageBox, "No HDD found!")
+                       return
+       
                if self.recording != None:
                        self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
                else:
                        self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
+
+from Screens.AudioSelection import AudioSelection
+
+class InfoBarAudioSelection:
+       def __init__(self):
+               self["AudioSelectionAction"] = HelpableActionMap(self, "InfobarAudioSelectionActions", 
+                       {
+                               "audioSelection": (self.audioSelection, "Audio Options..."),
+                       })
+
+       def audioSelection(self):
+               service = self.session.nav.getCurrentService()
+               audio = service.audioTracks()
+               n = audio.getNumberOfTracks()
+               if n > 0:
+                       self.session.open(AudioSelection, audio)