Hi,

after quite some time of thinking how to connect to other programs like Misterhouse I started to do some real tests on Freevo side. As python and Freevo newcomer I'd be really glad to receive some advice with this simple example:
- One main menu item with five subitems (speak, speak2, ...) - each of them having two possibilities to run.


I'm attaching file since it's quite small...

Regards,

Robert.



#if 0 /*
# -----------------------------------------------------------------------
# tinia.py - a simple plugin to connect to Misterhouse
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2003 Krister Lagerstrom, et al. 
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif

#python modules
import os, time, stat, re, copy


#freevo modules
import config, menu, rc, plugin, skin, osd, util
from gui.PopupBox import PopupBox
from item import Item


#get the singletons so we get skin info and access the osd
skin = skin.get_singleton()
osd  = osd.get_singleton()

class PluginInterface(plugin.MainMenuPlugin):
    """
    A plugin to list menus for House devices.

    To activate, put the following lines in local_conf.py:

plugin.activate('tinia', args=('mhsend ',))
TINIA_COMMANDS = [ ("Speak", "mhsend -speak 'Hi there!'"), 
 ("Speak1 ", "mhsend -speak 'Hi there! 1'"),
 ("Speak2", "mhsend -speak 'Hi there! 2'"), 
 ("Speak3", "mhsend -speak 'Hi there! 3'"), 
 ("Speak4", "mhsend -speak 'Hi there! 4'"), 
 ("Speak5", "mhsend -speak 'Hi there! 5'") ] 

    """
    # make an init func that creates the cache dir if it don't exist
    
    def __init__(self):
    
        if not hasattr(config, 'TINIA_COMMANDS'):
            self.reason = 'TINIA_COMMANDS not defined'
            return
        plugin.MainMenuPlugin.__init__(self)
        
    def config(self):
        return [('TINIA_COMMANDS', [ ("Speak1", "mhsend -speak 'Hi there! 1'"), 
("Speak2", "mhsend -speak 'Hi there! 2'") ], 'where to get the tinia commands')]

    def items(self, parent):
        menu_items = skin.settings.mainmenu.items

        item = TiniaMainMenuItem()
        item.name = _('Tinia')
        item.parent = parent
        return [ item ]

        
class TiniaSiteItem(Item):
    """
    Menu item for one device
    """
    def __init__(self, parent):
        Item.__init__(self, parent)
        self.command = ''
        self.location_index = None
        

    def actions(self):
        """
        return a list of actions for this item
        """
        items = [ ( self.run("on") , _('Run TINIA Command On') ),
                ( self.run("off") , _('Run TINIA Command Off') ) ]
        return items

    def run(self, arg=None, menuw=None):
        popup = PopupBox(text=_('%s : Running MHSEND command line: %s ' % 
(arg,self.command)))
        popup.show()
        print '%s : Running MHSEND command line: %s' % (arg,self.command )
        os.system('%s ' % (self.command ) )
#       sleep(2)
        popup.destroy()
        

        rc.app(None)


class TiniaMainMenuItem(Item):
    """
    this is the item for the main menu and creates the list
    of Tinia in a submenu.
    """
    def actions(self):
        """
        return a list of actions for this item
        """
        items = [ ( self.create_menu , _('Tinia Commands' )) ]
        return items
 
    def create_menu(self, arg=None, menuw=None):
        devices = []
        for location in config.TINIA_COMMANDS:
            devices_item = TiniaSiteItem(self)
            devices_item.name = location[0]
            devices_item.command = location[1]
            devices_item.location_index = config.TINIA_COMMANDS.index(location)
            devices += [ devices_item ]
        if (len(devices) == 0):
            devices += [menu.MenuItem(_('No Tinia Commands found'),
                                              menuw.goto_prev_page, 0)]
        devices_menu = menu.Menu(_('Tinia Commands'), devices)
        menuw.pushmenu(devices_menu)
        menuw.refresh()


Reply via email to