Hi,

I was using my new remote and just had to make do some changes ;-)
lircd : http://freevo.sourceforge.net/cgi-bin/freevo-2.0/Lirc

Patch outline :
0: added events to events.py and mapped some more in eventmap.py

1:Menu events: (menu.py)
MENU_GOTO_AUDIOMENU 
MENU_GOTO_VIDEOMENU 
MENU_GOTO_IMAGEMENU 
*selects main menu,iterates over choice,select()on item
*please review:Is there a better way to do this?

2:
SHUTDOWN event (shutdown.py)

3:detach.py
Added an "else_handler" to the "popup audio player"
All unknown events get Reposted to the audio player.
Play/Prev/Next/FFw/Rew/Pause buttons work right now.
---
These are "relatively" simple changes so i guess its ok to put them
all into 1 patch.
Please tell me if you want separate patches/improvements.

Martijn.
Index: src/controlpanel.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/controlpanel.py,v
retrieving revision 1.5
diff -a -u -r1.5 controlpanel.py
--- src/controlpanel.py	5 May 2005 17:33:40 -0000	1.5
+++ src/controlpanel.py	16 May 2005 17:59:28 -0000
@@ -219,7 +219,7 @@
     """
     def __init__(self, name, handlers=[], button_size=(32,32),
                  button_spacing=2, default_action=0,
-                 hide_when_run=False):
+                 hide_when_run=False,else_handler=None):
 
         self.name          = name
         self.p_action      = default_action
@@ -231,6 +231,8 @@
         self.objects       = []
         self.buttons       = []
         self.visible       = False
+        
+        self.else_handler = else_handler #post all unknown events to this handler
 
 
 
@@ -275,6 +277,10 @@
                 eventhandler.post(TOGGLE_CONTROL)
 
             return True
+            
+        elif self.else_handler: #unknown event:post to else_handler
+            self.else_handler(event)
+            return True
 
         return False
 
Index: src/event.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/event.py,v
retrieving revision 1.55
diff -a -u -r1.55 event.py
--- src/event.py	27 Sep 2004 18:42:10 -0000	1.55
+++ src/event.py	16 May 2005 17:59:29 -0000
@@ -137,6 +137,7 @@
 MIXER_VOLDOWN          = Event('MIXER_VOLDOWN', arg=5)
 MIXER_MUTE             = Event('MIXER_MUTE')
 TOGGLE_CONTROL         = Event('TOGGLE_CONTROL')
+SHUTDOWN               = Event('SHUTDOWN')
 
 # To change the step size, but the following code in your
 # local_conf.py (setting VOL+ step size to 2)
@@ -163,6 +164,9 @@
 MENU_REBUILD           = Event('MENU_REBUILD')
                        
 MENU_GOTO_MAINMENU     = Event('MENU_GOTO_MAINMENU')
+MENU_GOTO_AUDIOMENU     = Event('MENU_GOTO_AUDIOMENU')
+MENU_GOTO_VIDEOMENU     = Event('MENU_GOTO_VIDEOMENU')
+MENU_GOTO_IMAGEMENU     = Event('MENU_GOTO_IMAGEMENU')
 MENU_BACK_ONE_MENU     = Event('MENU_BACK_ONE_MENU')
                        
 MENU_SELECT            = Event('MENU_SELECT')
Index: src/menu.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/menu.py,v
retrieving revision 1.119
diff -a -u -r1.119 menu.py
--- src/menu.py	5 May 2005 17:33:41 -0000	1.119
+++ src/menu.py	16 May 2005 17:59:32 -0000
@@ -315,6 +315,30 @@
         menu = self.menustack[0]
         gui.set_theme(menu.theme)
         self.refresh()
+        
+                
+    def goto_media_menu(self,media='audio'):
+        """
+        Go to a media menu
+        media = 'audio' or 'video' or 'image'
+        used for events:
+            MENU_GOTO_AUDIOMENU
+            MENU_GOTO_VIDEOMENU
+            MENU_GOTO_IMAGEMENU
+        """        
+        #1:goto main menu.
+        #2:loop through main menu items.
+        #the arg of a media menu item is 'audio' or 'video' or 'image'
+        #select.
+        self.goto_main_menu()
+        for menuitem in self.menustack[0].choices:                        
+            if menuitem.arg and menuitem.arg[0] == media:
+                menuitem.select(menuw=self)
+                return
+        
+        
 
 
     def pushmenu(self, menu):
@@ -444,6 +468,20 @@
             self.goto_main_menu()
             return True
 
+        if event == MENU_GOTO_AUDIOMENU:
+            self.goto_media_menu('audio')
+            return True
+
+        if event == MENU_GOTO_VIDEOMENU:
+            self.goto_media_menu('video')
+            return True
+
+        if event == MENU_GOTO_IMAGEMENU:
+            self.goto_media_menu('image')
+            return True
+
+
+
         if event == MENU_BACK_ONE_MENU:
             self.back_one_menu()
             return True
Index: src/audio/plugins/detach.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/audio/plugins/detach.py,v
retrieving revision 1.26
diff -a -u -r1.26 detach.py
--- src/audio/plugins/detach.py	5 May 2005 17:33:42 -0000	1.26
+++ src/audio/plugins/detach.py	16 May 2005 17:59:34 -0000
@@ -145,7 +145,7 @@
         # set up a controlbar
         a_handler = audioplayer().eventhandler
         path = os.path.join(config.ICON_DIR, 'misc','audio_')
-
+        
         handlers = [ ( _('Prev'), '%sprev.png' % path,
                        a_handler, PLAYLIST_PREV),
                      ( _('Rew'), '%srew.png'  % path,
@@ -165,8 +165,9 @@
 
         self.controlbar = ButtonPanel( _('Audio Player'),
                                        handlers,
-                                       default_action=3)
-
+                                       default_action=3
+                                       ,else_handler=a_handler)
+                                       
         controlpanel().register(self.controlbar)
 
         self.w       = self.max_width
@@ -252,8 +253,7 @@
     def eventhandler(self, event, menuw=None):
         """
         Catches the play events
-        """
-
+        """        
         if event == STOP and self.detached:
             # this event STOP has nothing to do with the normal stop because
             # this eventhandler is only called for the registered events
 
Index: src/plugins/shutdown.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/plugins/shutdown.py,v
retrieving revision 1.10
diff -a -u -r1.10 shutdown.py
--- src/plugins/shutdown.py	8 Jan 2005 11:12:20 -0000	1.10
+++ src/plugins/shutdown.py	16 May 2005 17:59:37 -0000
@@ -37,6 +37,8 @@
 from mainmenu import MainMenuItem
 from plugin import MainMenuPlugin
 from cleanup import shutdown
+from event import *
+import eventhandler
 
 
 class ShutdownItem(MainMenuItem):
@@ -46,7 +48,7 @@
     def __init__(self, parent=None):
         MainMenuItem.__init__(self, parent, skin_type='shutdown')
         self.menuw = None
-
+        eventhandler.register(self, SHUTDOWN)        
 
     def actions(self):
         """
@@ -65,16 +67,15 @@
 
         return items
 
-
     def confirm_freevo(self, arg=None, menuw=None):
         """
         Pops up a ConfirmBox.
         """
         self.menuw = menuw
         what = _('Do you really want to shut down Freevo?')
-        ConfirmBox(text=what, handler=self.shutdown_freevo,
-                   default_choice=1).show()
-
+        ConfirmBox(text=what, handler=self.shutdown_freevo
+            ,default_choice=1).show()
+            
 
     def confirm_system(self, arg=None, menuw=None):
         """
@@ -82,17 +83,17 @@
         """
         self.menuw = menuw
         what = _('Do you really want to shut down the system?')
-        ConfirmBox(text=what, handler=self.shutdown_system,
-                   default_choice=1).show()
+        ConfirmBox(text=what, handler=self.shutdown_system                   
+                   ,default_choice=1).show()
 
     def confirm_system_restart(self, arg=None, menuw=None):
         """
         Pops up a ConfirmBox.
-        """
-        self.menuw = menuw
+        """        
         what = _('Do you really want to restart the system?')
         ConfirmBox(text=what, handler=self.shutdown_system_restart,
                    default_choice=1).show()
+        
 
 
     def shutdown_freevo(self, arg=None, menuw=None):
@@ -115,6 +116,26 @@
         """
         shutdown(menuw=menuw, argshutdown=False, argrestart=True)
 
+    def eventhandler(self, event,menuw=None):
+        """
+        Catch events 
+        """         
+        if event == SHUTDOWN:
+            
+            #TODO
+            #If the confirm box pops up, AND it press the shutdown button again
+            #a new popup box will open.
+            #this is confusing,I want freevo to shutdow.
+            #not possible, need a "No" event for popupbox first.
+            
+            if config.CONFIRM_SHUTDOWN:
+                self.confirm_freevo()
+            else:
+                self.shutdown_freevo()            
+            
+        
+        
+
 
 
 

Reply via email to