Update of /cvsroot/freevo/freevo/src/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27989

Modified Files:
        command.py 
Log Message:
make it possible to put command fxd files in every menu

Index: command.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/plugins/command.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** command.py  13 Jan 2004 20:40:55 -0000      1.4
--- command.py  14 Feb 2004 15:05:49 -0000      1.5
***************
*** 15,18 ****
--- 15,21 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.5  2004/02/14 15:05:49  dischi
+ # make it possible to put command fxd files in every menu
+ #
  # Revision 1.4  2004/01/13 20:40:55  mikeruelle
  # We now use childapp2 to run the commands and store our output. We now have
***************
*** 20,64 ****
  # plugin).
  #
- # Revision 1.3  2003/11/30 14:35:43  dischi
- # new skin handling
- #
- # Revision 1.2  2003/11/29 11:41:04  dischi
- # use the given menuw and not a global one
- #
- # Revision 1.1  2003/11/24 17:12:03  dischi
- # rename commands.py to command.py to avoid name problems with the global python 
commands.py
- #
- # Revision 1.10  2003/11/03 18:08:14  dischi
- # oops
- #
- # Revision 1.9  2003/11/03 18:04:43  dischi
- # cleanup, only show dialog when needed, image support
- #
- # Revision 1.8  2003/10/27 20:15:58  mikeruelle
- # make use of outicon
- #
- # Revision 1.7  2003/10/16 17:49:59  mikeruelle
- # put in a small i18n change
- #
- # Revision 1.6  2003/09/30 17:09:56  mikeruelle
- # add a default dir for commands
- #
- # Revision 1.5  2003/09/14 20:09:36  dischi
- # removed some TRUE=1 and FALSE=0 add changed some debugs to _debug_
- #
- # Revision 1.4  2003/09/13 10:08:22  dischi
- # i18n support
- #
- # Revision 1.3  2003/09/09 18:54:59  dischi
- # Add some doc
- #
- # Revision 1.2  2003/09/01 19:46:02  dischi
- # add menuw to eventhandler, it may be needed
- #
- # Revision 1.1  2003/08/06 00:25:40  rshortt
- # Update the commands plugin from Mike Ruelle and move it into the main
- # plugins directory.
- #
- #
  # -----------------------------------------------------------------------
  # Freevo - A Home Theater PC framework
--- 23,26 ----
***************
*** 88,98 ****
  
  #freevo modules
! import config, menu, rc, plugin, util
  import childapp
  import osd
  from event import *
  from item import Item
! from gui import AlertBox, RegionScroller, ListBox, PopupBox, Align
! import traceback
  
  
--- 50,64 ----
  
  #freevo modules
! import config
! import menu
! import plugin
! import util
  import childapp
  import osd
+ import fxditem
+ 
  from event import *
  from item import Item
! from gui import RegionScroller, ListBox, PopupBox, Align
  
  
***************
*** 128,132 ****
          self.file = file
          self.filetext = open(self.file, 'rb').read()
-         #print  self.filetext
  
          PopupBox.__init__(self, parent, text, handler, left, top, width, height,
--- 94,97 ----
***************
*** 135,148 ****
  
          self.set_h_align(Align.CENTER)
-         test = 'AAAAAAAAAA'
          myfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, 
config.OSD_DEFAULT_FONTSIZE)
!         surf_w = myfont.stringsize(test*8) 
          data = self.osd.drawstringframed(self.filetext, 0, 0, surf_w, 1000000,
!                                          myfont,
!                                          align_h='left',
!                                          align_v='top',
                                           fgcolor=self.osd.COL_BLACK,
!                                          mode='hard',
!                                          layer='')[1]
          (ret_x0,ret_y0, ret_x1, ret_y1) = data
          surf_h = ret_y1 - ret_y0
--- 100,109 ----
  
          self.set_h_align(Align.CENTER)
          myfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, 
config.OSD_DEFAULT_FONTSIZE)
!         surf_w = myfont.stringsize('AAAAAAAAAA'*8) 
          data = self.osd.drawstringframed(self.filetext, 0, 0, surf_w, 1000000,
!                                          myfont, align_h='left', align_v='top',
                                           fgcolor=self.osd.COL_BLACK,
!                                          mode='hard', layer='')[1]
          (ret_x0,ret_y0, ret_x1, ret_y1) = data
          surf_h = ret_y1 - ret_y0
***************
*** 177,180 ****
--- 138,144 ----
  
  class CommandOptions(PopupBox):
+     """
+     Show the command results
+     """
      def __init__(self, parent='osd', text=None, handler=None,
                   left=None, top=None, width=600, height=300, bg_color=None,
***************
*** 208,212 ****
  
      def eventhandler(self, event, menuw=None):
!                                                                                 
          if event in (INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT):
              return self.results.eventhandler(event)
--- 172,178 ----
  
      def eventhandler(self, event, menuw=None):
!         """
!         eventhandler to browse the result popup
!         """
          if event in (INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT):
              return self.results.eventhandler(event)
***************
*** 237,289 ****
      and for displaying stdout and stderr of last command run.
      """
!     def __init__(self, command=None, directory=None, xmlfile=None):
          Item.__init__(self)
        self.stoposd = 0
!       self.use_wm = None
        self.spawnwm = config.COMMAND_SPAWN_WM
!       self.killwm = config.COMMAND_KILL_WM
        if command and directory:
              self.name = command
              self.cmd  = os.path.join(directory, command)
              self.image = util.getimage(self.cmd)
-         elif xmlfile:
-           #create using xmlfile
-             try:
-               self.xml_file = xmlfile
-                 parser = util.fxdparser.FXD(self.xml_file)
-                 parser.set_handler('command', self.read_command_fxd)
-               parser.parse()
-           except:
-               print "fxd file %s corrupt" % self.xml_file
-                 traceback.print_exc()
-       else:
-           print "bad things...."
-       
- 
-     def read_command_fxd(self, fxd, node):
-         '''
-         parse the file for command settings
-                                                                                 
-         <?xml version="1.0" ?>
-         <freevo>
-           <command title="Mozilla">
-             <cmd>/usr/local/bin/mozilla</cmd>
-             <stoposd>1</stoposd>
-           <spawnwm>1</spawnwm>
-             <info>
-               <content>Unleash mozilla on the www</content>
-             </info>
-           </command>
-         </freevo>
-         '''
-         self.name = fxd.getattr(node, 'title')
-         self.cmd = fxd.childcontent(node, 'cmd')
-         self.image = util.getimage(self.cmd)
-         self.stoposd = fxd.childcontent(node, 'stoposd')
-         self.use_wm = fxd.childcontent(node, 'spawnwm')
  
-         # parse <info> tag
-         fxd.parse_info(fxd.get_children(node, 'info', 1), self,
-                        {'description': 'content', 'content': 'content' })
  
      def actions(self):
--- 203,217 ----
      and for displaying stdout and stderr of last command run.
      """
!     def __init__(self, command=None, directory=None):
          Item.__init__(self)
        self.stoposd = 0
!       self.use_wm  = None
        self.spawnwm = config.COMMAND_SPAWN_WM
!       self.killwm  = config.COMMAND_KILL_WM
        if command and directory:
              self.name = command
              self.cmd  = os.path.join(directory, command)
              self.image = util.getimage(self.cmd)
  
  
      def actions(self):
***************
*** 291,298 ****
          return a list of actions for this item
          """
!         items = [ ( self.flashpopup , _('Run Command') ) ]
!         return items
  
      def flashpopup(self, arg=None, menuw=None):
          if self.stoposd:
            if self.use_wm:
--- 219,229 ----
          return a list of actions for this item
          """
!         return [ ( self.flashpopup , _('Run Command') ) ]
! 
  
      def flashpopup(self, arg=None, menuw=None):
+         """
+         start popup and execute command
+         """
          if self.stoposd:
            if self.use_wm:
***************
*** 327,330 ****
--- 258,291 ----
          
  
+ def fxdparser(fxd, node):
+     '''
+     parse commands out of a fxd file
+                                                                                 
+     <?xml version="1.0" ?>
+     <freevo>
+       <command title="Mozilla">
+         <cmd>/usr/local/bin/mozilla</cmd>
+         <stoposd>1</stoposd>
+         <spawnwm>1</spawnwm>
+         <info>
+           <description>Unleash mozilla on the www</description>
+         </info>
+       </command>
+     </freevo>
+     '''
+     item = CommandItem()
+     item.name    = fxd.getattr(node, 'title')
+     item.cmd     = fxd.childcontent(node, 'cmd')
+     item.image   = util.getimage(item.cmd)
+     item.stoposd = fxd.childcontent(node, 'stoposd')
+     item.use_wm  = fxd.childcontent(node, 'spawnwm')
+     
+     # parse <info> tag
+     fxd.parse_info(fxd.get_children(node, 'info', 1), item)
+     fxd.getattr(None, 'items', []).append(item)
+     if fxd.getattr(None, 'parent'):
+         item.name = Unicode(_('Execute command: ')) + item.name
+     
+ 
  class CommandMainMenuItem(Item):
      """
***************
*** 346,366 ****
   
      def create_commands_menu(self, arg=None, menuw=None):
          command_items = []
!         commands = os.listdir(config.COMMANDS_DIR)
!         commands.sort(lambda l, o: cmp(l.upper(), o.upper()))
!         for command in commands:
              if os.path.splitext(command)[1] in ('.jpg', '.png'):
                  continue
              if os.path.splitext(command)[1] in ('.fxd', '.xml'):
!               myxmlfile=os.path.join(config.COMMANDS_DIR, command)
!                 cmd_item = CommandItem(xmlfile=myxmlfile)
            else:
                  cmd_item = CommandItem(command, config.COMMANDS_DIR)
!             command_items += [ cmd_item ]
!         if (len(command_items) == 0):
!             command_items += [menu.MenuItem(_('No Commands found'),
!                                             menuw.goto_main_menu, 0)]
          command_menu = menu.Menu(_('Commands'), command_items)
-         rc.app(None)
          menuw.pushmenu(command_menu)
          menuw.refresh()
--- 307,337 ----
   
      def create_commands_menu(self, arg=None, menuw=None):
+         """
+         create a list with commands
+         """
          command_items = []
!         for command in os.listdir(config.COMMANDS_DIR):
              if os.path.splitext(command)[1] in ('.jpg', '.png'):
                  continue
              if os.path.splitext(command)[1] in ('.fxd', '.xml'):
!               fxd_file=os.path.join(config.COMMANDS_DIR, command)
! 
!                 # create a basic fxd parser
!                 parser = util.fxdparser.FXD(fxd_file)
! 
!                 # create items to add
!                 parser.setattr(None, 'items', command_items)
! 
!                 # set handler
!                 parser.set_handler('command', fxdparser)
!                 
!                 # start the parsing
!                 parser.parse()
            else:
                  cmd_item = CommandItem(command, config.COMMANDS_DIR)
!                 command_items.append(cmd_item)
! 
!         command_items.sort(lambda l, o: cmp(l.name.upper(), o.name.upper()))
          command_menu = menu.Menu(_('Commands'), command_items)
          menuw.pushmenu(command_menu)
          menuw.refresh()
***************
*** 377,381 ****
      to activate it, put the following in your local_conf.py:
  
!     plugin.activate('commands', level=45) 
      COMMANDS_DIR = '/usr/local/freevo_data/Commands' 
  
--- 348,352 ----
      to activate it, put the following in your local_conf.py:
  
!     plugin.activate('command', level=45) 
      COMMANDS_DIR = '/usr/local/freevo_data/Commands' 
  
***************
*** 384,387 ****
--- 355,364 ----
      in a particular location.
      """
+     def __init__(self):
+         # register command to normal fxd item parser
+         # to enable <command> tags in fxd files in every menu
+         plugin.register_callback('fxditem', [], 'command', fxdparser)
+         plugin.MainMenuPlugin.__init__(self)
+         
      def items(self, parent):
          return [ CommandMainMenuItem(parent) ]
***************
*** 393,394 ****
--- 370,402 ----
        ]
  
+ 
+ class fxdhandler(plugin.Plugin):
+     """
+     Small plugin to enable <command> tags inside fxd files in every menu. You
+     don't need this plugin if you activate the complete 'command' plugin.
+ 
+     to activate it, put the following in your local_conf.py:
+     plugin.activate('command.fxdhandler')
+ 
+     Sample fxd file starting mozilla:
+     <?xml version="1.0" ?>
+     <freevo>
+       <command title="Mozilla">
+         <cmd>/usr/local/bin/mozilla</cmd>
+         <stoposd>1</stoposd>
+         <spawnwm>1</spawnwm>
+         <info>
+           <description>Unleash mozilla on the www</description>
+         </info>
+       </command>
+     </freevo>
+     """
+     def __init__(self):
+         # register command to normal fxd item parser
+         # to enable <command> tags in fxd files in every menu
+         plugin.register_callback('fxditem', [], 'command', fxdparser)
+         plugin.Plugin.__init__(self)
+         
+     def config(self):
+         return [ ('COMMAND_SPAWN_WM', '', 'command to start window manager.'),
+                  ('COMMAND_KILL_WM', '', 'command to stop window manager.') ]



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to