show shutdown menu on long power button press
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 8 Nov 2007 14:10:32 +0000 (14:10 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 8 Nov 2007 14:10:32 +0000 (14:10 +0000)
the old behavior (immediate shutdown) is choosable in usage config

data/keymap.xml
data/setup.xml
lib/python/Components/UsageConfig.py
mytest.py

index 3b2185d..94e19e1 100644 (file)
                <key id="KEY_VOLUMEUP" mapto="volumeUp" flags="mr" />
                <key id="KEY_VOLUMEDOWN" mapto="volumeDown" flags="mr" />
                <key id="KEY_MUTE" mapto="volumeMute" flags="mr" />
-               <key id="KEY_POWER" mapto="powerdown" flags="m" />
-               <key id="KEY_POWER" mapto="powerup" flags="b" />
+               <key id="KEY_POWER" mapto="power_down" flags="m" />
+               <key id="KEY_POWER" mapto="power_up" flags="b" />
+               <key id="KEY_POWER" mapto="power_long" flags="l" />
        </map>
        
        <map context="PowerKeyActions">
index 3648420..894a2b8 100644 (file)
@@ -24,6 +24,7 @@
                        <item level="1" text="Enable multiple bouquets">config.usage.multibouquet</item>
                        <item level="1" text="Change bouquets in quickzap">config.usage.quickzap_bouquet_change</item>
                        <item level="1" text="Alternative radio mode">config.usage.e1like_radio_mode</item>
+                       <item level="1" text="Action on long powerbutton press">config.usage.on_long_powerpress</item>
                        <item level="0" text="Infobar timeout">config.usage.infobar_timeout</item>
                        <item level="1" text="12V output">config.usage.output_12V</item>
                        <item level="2" text="Show infobar on channel change">config.usage.show_infobar_on_zap</item>
index 581e7ce..b365801 100644 (file)
@@ -34,6 +34,10 @@ def InitUsageConfig():
                ("intermediate", _("Intermediate")),
                ("expert", _("Expert")) ])
 
+       config.usage.on_long_powerpress = ConfigSelection(default = "show_menu", choices = [
+               ("show_menu", _("show shutdown menu")),
+               ("shutdown", _("immediate shutdown")) ] )
+
        def setHDDStandby(configElement):
                os.system("hdparm -S" + configElement.value + " /dev/ide/host0/bus0/target0/lun0/disc")
        config.usage.hdd_standby.addNotifier(setHDDStandby)
index 3a5ec3e..79dd627 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -393,36 +393,51 @@ class VolumeControl:
                                self.volumeDialog.setValue(vol)
 
 import Screens.Standby
+from Screens.Menu import MainMenu, mdom
+import xml.dom.minidom
 
 class PowerKey:
        """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
 
        def __init__(self, session):
                self.session = session
-               self.powerKeyTimer = eTimer()
-               self.powerKeyTimer.timeout.get().append(self.powertimer)
-               globalActionMap.actions["powerdown"]=self.powerdown
-               globalActionMap.actions["powerup"]=self.powerup
+               globalActionMap.actions["power_down"]=self.powerdown
+               globalActionMap.actions["power_up"]=self.powerup
+               globalActionMap.actions["power_long"]=self.powerlong
                self.standbyblocked = 1
-#              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):
-               print "PowerOff - Now!"
-               if not Screens.Standby.inTryQuitMainloop:
-                       self.session.open(Screens.Standby.TryQuitMainloop, 1)
+
+       def MenuClosed(self, *val):
+               self.session.infobar = None
+
+       def powerlong(self):
+               self.standbyblocked = 1
+               action = config.usage.on_long_powerpress.value
+               if action == "shutdown":
+                       print "PowerOff - Now!"
+                       if not Screens.Standby.inTryQuitMainloop:
+                               self.session.open(Screens.Standby.TryQuitMainloop, 1)
+               elif action == "show_menu":
+                       print "Show shutdown Menu"
+                       menu = mdom.childNodes[0]
+                       for x in menu.childNodes:
+                               if x.nodeType != xml.dom.minidom.Element.nodeType:
+                                   continue
+                               elif x.tagName == 'menu':
+                                       for y in x.childNodes:
+                                               if y.nodeType != xml.dom.minidom.Element.nodeType:
+                                                       continue
+                                               elif y.tagName == 'id':
+                                                       id = y.getAttribute("val")
+                                                       if id and id == "shutdown":
+                                                               self.session.infobar = self
+                                                               menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, menu, x.childNodes)
+                                                               menu_screen.setTitle(_("Standby Menu"))
+                                                               return
 
        def powerdown(self):
                self.standbyblocked = 0
-               self.powerKeyTimer.start(3000, True)
 
        def powerup(self):
-               self.powerKeyTimer.stop()
                if self.standbyblocked == 0:
                        self.standbyblocked = 1
                        self.standby()