Author: dmeyer
Date: Wed Mar 28 17:58:31 2007
New Revision: 9405
Added:
trunk/ui/src/games/
trunk/ui/src/games/__init__.py
trunk/ui/src/games/config.cxml
trunk/ui/src/games/emulator.py
trunk/ui/src/games/interface.py
trunk/ui/src/games/player.py
trunk/ui/src/games/plugins/
trunk/ui/src/games/plugins/__init__.py
trunk/ui/src/games/plugins/config.cxml
trunk/ui/src/games/plugins/pcgames.py
trunk/ui/src/games/plugins/scummvm.py
trunk/ui/src/games/plugins/zsnes.py
Modified:
trunk/ui/src/gui/compat.py
Log:
add new games code from Mathias Weber
Added: trunk/ui/src/games/__init__.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/__init__.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,37 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# __init__.py - interface to games
+# -----------------------------------------------------------------------------
+# $Id: __init__.py 9151 2007-02-03 20:49:32Z dmeyer $
+#
+# This file imports everything needed to use this games module.
+# There is only one class provided for games files, the PluginInterface
+# from interface.py.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2007 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+from interface import *
+
Added: trunk/ui/src/games/config.cxml
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/config.cxml Wed Mar 28 17:58:31 2007
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<config name="games" plugin="50">
+ <desc lang="en">games plugin</desc>
+</config>
+
Added: trunk/ui/src/games/emulator.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/emulator.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,361 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# emulator.py - the plugin for the emulators
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# This is a generic emulator player. This should work with most emulators.
+# If something special is needed it should be possible to create a specialized
+# version easely. See pcgames.py for an example.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+# python imports
+import logging
+import os
+
+# kaa imports
+import kaa.notifier
+from kaa.notifier import Event
+from kaa.weakref import weakref
+import kaa.beacon
+
+# freevo imports
+import freevo.conf
+from freevo.ui.mainmenu import MainMenuItem, MainMenuPlugin
+from freevo.ui.directory import DirItem
+from freevo.ui.event import *
+from freevo.ui.menu import Item, Action, Menu
+from freevo.ui.plugins.mediamenu import MediaMenu
+
+# games imports
+import player as gameplayer
+
+log = logging.getLogger('games')
+
+
+class Plugin(MainMenuPlugin):
+ """
+ Add the emualtor items to the games menu
+ """
+ mediatype = [ 'games' ]
+
+ def roms(self, parent, listing, configitem):
+ """
+ Show all roms.
+ """
+ items = []
+ for suffix in self.suffix(configitem):
+ # if is only one object don't iterate over it.
+ if isinstance(listing, kaa.beacon.file.File):
+ filename = listing.get('name')
+ if filename.endswith(suffix):
+ # cut the fileending off the file for the displaying name
+ name = filename[:-(len(suffix)+1)]
+ items.append(EmulatorItem(parent, name, \
+ listing.filename, configitem))
+ break
+ return items
+
+
+ def suffix(self, configitem):
+ """
+ return the list of suffixes this class handles
+ """
+ return configitem.suffix.split(',')
+
+
+ def items(self, parent):
+ """
+ Return the main menu item.
+ """
+ return []
+
+
+class EmulatorItem(Item):
+ """
+ Basic Item for all emulator types
+ """
+
+ def __init__(self, parent, name, url="", configitem=None):
+ Item.__init__(self, parent)
+ self.name = name
+ self.url = url
+ self.configitem = configitem
+ log.info('create EmulatorItem name=%s, url=%s'%(name, url))
+
+
+ def play(self):
+ """
+ Start the emulator with the generic EmulatorPlayer.
+ """
+ gameplayer.play(self, EmulatorPlayer(self.configitem.bin, \
+ self.configitem.parameters))
+
+
+ def remove(self):
+ """
+ Delete Rom from the disk
+ """
+ #FIXME
+ log.info('Remove rom %s (FIXME not implemented)'%self.name)
+
+
+ def actions(self):
+ """
+ Default action for the itmes. There are two actions available play
+ and remove. Remove is for deleting a rom.
+ """
+ return [ Action(_('Play %s') % self.name, self.play),
+ Action(_('Remove %s') % self.name, self.remove)]
+
+
+class EmulatorPlayer(object):
+ """
+ Generic game player.
+ """
+ def __init__(self, command_name=None, parameters=""):
+ self.command_name = command_name
+ self.parameters = parameters
+ self.url = None
+ self.child = None
+
+ self.signals = {
+ "open": kaa.notifier.Signal(),
+ "start": kaa.notifier.Signal(),
+ "failed": kaa.notifier.Signal(),
+ "end": kaa.notifier.Signal(),
+ }
+
+ def open(self, item):
+ """
+ Open an item, prepare for playing. Load url parameter from
+ EmulatorItem
+ """
+ self.url = item.url
+
+
+ def play(self):
+ """
+ Play game. Should work with most emulators. Will start
+ [command_name] [parameters] [url]
+ """
+ self._releaseJoystick()
+ params = "%s %s" % (self.parameters, self.url)
+ log.info('Start playing EmulatorItem (%s %s)' % \
+ (self.command_name, params))
+ self.child = kaa.notifier.Process(self.command_name)
+ self.child.start(params).connect(self.completed)
+ self.signals = self.child.signals
+ stop = kaa.notifier.WeakCallback(self.stop)
+ self.child.set_stop_command(stop)
+
+
+ def is_running(self):
+ """
+ check if player is still running
+ """
+ if self.child:
+ return self.child.is_alive()
+
+ return False
+
+
+ def completed(self, child):
+ """
+ The game was quit. Send stop event to get back to the menu.
+ """
+ Event(STOP, handler=gameplayer.player.eventhandler).post()
+ self._acquireJoystick()
+ log.info('emulator completed')
+
+
+ def stop(self):
+ """
+ Stop the game from playing
+ """
+ if self.child:
+ self.child.stop()
+
+
+ def _releaseJoystick(self):
+ """
+ Release Joystick that it can be used by the game/emulator
+ """
+ #FIXME
+ pass
+
+
+ def _acquireJoystick(self):
+ """
+ Acquire Joysitck back that it can be used by freevo
+ """
+ #FIXME
+ pass
+
+
+
+class EmulatorMenuItem(MainMenuItem):
+ """
+ This is a menu entry for the different emulators in the games subdirectory.
+ This class has a lot of similarities with the MediaMenu, maybe there
+ could be some integration with this.
+ """
+
+ def __init__(self, parent, title, items, gamepluginlist, configitem,
+ image=None, root=True):
+ MainMenuItem.__init__(self,parent, title, image=image)
+ if root:
+ kaa.beacon.signals['media.add'].connect(self.media_change)
+ kaa.beacon.signals['media.remove'].connect(self.media_change)
+
+ self.menutitle = title
+ self.item_menu = None
+ self.gamepluginlist = gamepluginlist
+ self.configitem = configitem
+ self.isRoot = root
+
+ self._items = items
+
+ # add listener for the different directories
+ for filename in self._items:
+ if hasattr(filename, 'path'):
+ #replace home variable
+ filename = filename.path.replace('$(HOME)', \
+ os.environ.get('HOME'))
+ if isinstance(filename, kaa.beacon.file.File):
+ continue
+ if not isinstance(filename, (str, unicode)):
+ filename = filename[1]
+ filename = os.path.abspath(filename)
+ if os.path.isdir(filename) and \
+ not os.environ.get('NO_CRAWLER') and \
+ not filename == os.environ.get('HOME') and \
+ not filename == '/':
+ kaa.beacon.monitor(filename)
+
+
+ def main_menu_generate(self):
+ """
+ generate the itmes for the games menu. This is needed when first
+ generating the menu and if something changes by pressing the EJECT
+ button for example
+ """
+ items = []
+ for item in self._items:
+ try:
+ filename = ''
+ title = ''
+ if hasattr(item, 'path'):
+ title = unicode(item.name)
+ filename = item.path.replace('$(HOME)', \
+ os.environ.get('HOME'))
+ elif isinstance(item, (str, unicode)):
+ # only a filename is given
+ title, filename = u'', item
+ elif isinstance(item, kaa.beacon.file.File):
+ title = u''
+ filename = item.filename
+ filename = os.path.abspath(filename)
+ if os.path.isdir(filename):
+ query = kaa.beacon.query(filename=filename)
+ for d in query.get(filter='extmap').get('beacon:dir'):
+ items.append(EmulatorMenuItem(self, "[%s]"%title, \
+ d.list().get(), self.gamepluginlist, \
+ self.configitem, root=False))
+ continue
+
+ if not os.path.isfile(filename) and \
+ filename.startswith(os.getcwd()):
+ # file is in share dir
+ filename = filename[len(os.getcwd()):]
+ if filename[0] == '/':
+ filename = filename[1:]
+ filename = os.path.join(freevo.conf.SHAREDIR, filename)
+
+ query = kaa.beacon.query(filename=filename)
+ listing = query.get()
+ g_items = self.gamepluginlist(self, listing, self.configitem)
+ if g_items:
+ items += g_items
+ except:
+ log.exception('Error parsing %s' %str(item))
+ continue
+ if self.isRoot:
+ for media in kaa.beacon.media:
+ if media.mountpoint == '/':
+ continue
+ listing = kaa.beacon.wrap(media.root, filter='extmap')
+ g_items = self.gamepluginlist(self, listing, self.configitem)
+ if g_items:
+ items += g_items
+ for d in listing.get('beacon:dir'):
+ items.append(EmulatorMenuItem(self, "[%s]"%media.label, \
+ d.list().get(), self.gamepluginlist, \
+ self.configitem, root=False))
+
+ return items
+
+
+ def select(self):
+ """
+ display the emulator menu
+ """
+ items = self.main_menu_generate()
+
+ type = ""
+ item_menu = Menu(self.menutitle, items, type=type, \
+ reload_func=self.reload)
+ item_menu.autoselect = True
+ item_menu.skin_force_view = False
+ self.item_menu = item_menu
+ self.pushmenu(item_menu)
+
+
+ def reload(self):
+ """
+ Reload the menu items
+ """
+ if self.item_menu:
+ self.item_menu.set_items(self.main_menu_generate())
+
+
+ def media_change(self, media):
+ """
+ Media change from kaa.beacon
+ """
+ if self.item_menu:
+ self.item_menu.set_items(self.main_menu_generate())
+
+
+ def eventhandler(self, event):
+ """
+ Handle events, eject for a media item
+ """
+ if event == EJECT and self.item_menu and \
+ self.item_menu.selected.info['parent'] == \
+ self.item_menu.selected.info['media']:
+ self.item_menu.selected.info['media'].eject()
Added: trunk/ui/src/games/interface.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/interface.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,67 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# interface.py - interface between mediamenu and games
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# This creates the MainMenuEntry and loads all the sub plugins for the game
+# entry.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+import logging
+
+# freevo imports
+from freevo.ui.mainmenu import MainMenuItem, MainMenuPlugin
+from freevo.ui.menu import Menu
+
+log = logging.getLogger('games')
+
+class PluginInterface(MainMenuPlugin):
+ """
+ Create the GamesMenu Item.
+ """
+
+ def items(self, parent):
+ for p in MainMenuPlugin.plugins('games'):
+ if p.items(self):
+ # at least one games plugin is working
+ return [ GamesMenu(parent) ]
+ # no games plugin returns items
+ return []
+
+
+class GamesMenu(MainMenuItem):
+ """
+ The Games main menu.
+ """
+ skin_type = 'games'
+
+ def select(self):
+ items = []
+ for p in MainMenuPlugin.plugins('games'):
+ items += p.items(self)
+ self.pushmenu(Menu(_('Games Main Menu'), items, type = 'games main
menu'))
Added: trunk/ui/src/games/player.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/player.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,170 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# player.py - a generic player for the games
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# This player starts a emulator player. This class handles all the events
+# from the freevo system and sends them to the different players.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+__all__ = [ 'play', 'stop']
+
+# python imports
+import logging
+
+# kaa imports
+import kaa.utils
+import kaa.notifier
+
+# freevo imports
+from freevo.ui.event import *
+from freevo.ui.application import Application, STATUS_RUNNING, \
+ STATUS_STOPPING, STATUS_STOPPED, STATUS_IDLE, CAPABILITY_FULLSCREEN
+
+log = logging.getLogger('games')
+
+class GamesPlayer(Application):
+ """
+ Games player object.
+ """
+ def __init__(self):
+ capabilities = (CAPABILITY_FULLSCREEN, )
+ Application.__init__(self, 'gamesplayer', 'games', capabilities)
+ self.player = None
+
+
+ def play(self, item, player):
+ """
+ play an item
+ """
+ if player == None:
+ return False
+ self.player = player
+ if not self.status in (STATUS_IDLE, STATUS_STOPPED):
+ # Already running, stop the current player by sending a STOP
+ # event. The event will also get to the playlist behind the
+ # current item and the whole list will be stopped.
+ Event(STOP, handler=self.eventhandler).post()
+ # Now connect to our own 'stop' signal once to repeat this current
+ # function call without the player playing
+ self.signals['stop'].connect_once(self.play, item)
+ return True
+
+ if not kaa.notifier.running:
+ # Freevo is in shutdown mode, do not start a new player, the old
+ # only stopped because of the shutdown.
+ return False
+
+ # Try to get VIDEO and AUDIO resources. The ressouces will be freed
+ # by the system when the application switches to STATUS_STOPPED or
+ # STATUS_IDLE.
+ blocked = self.get_resources('AUDIO', 'VIDEO')
+ if 'VIDEO' in blocked:
+ # Something has the video resource blocked. The only application
+ # possible is the tv player right now. It would be possible to
+ # ask the user what to do with a popup but we assume the user
+ # does not care about the tv and just stop it. FIXME ask user
+ Event(STOP, handler=blocked['VIDEO'].eventhandler).post()
+ # Now connect to the 'stop' signal once to repeat this current
+ # function call without the player playing
+ blocked['VIDEO'].signals['stop'].connect_once(retry)
+ return True
+ if 'AUDIO' in blocked:
+ # AUDIO is blocked, VIDEO is not. This is most likely the audio
+ # player and we can pause it. Do this if possible.
+ if not blocked['AUDIO'].has_capability(CAPABILITY_PAUSE):
+ # Unable to pause, just stop it
+ Event(STOP, handler=blocked['AUDIO'].eventhandler).post()
+ # Now connect to the 'stop' signal once to repeat this current
+ # function call without the player playing
+ blocked['AUDIO'].signals['stop'].connect_once(retry)
+ return True
+ # Now pause the current player. On its pause signal this player can
+ # play again. And on the stop signal of this player (STATUS_IDLE)
+ # the other player can be resumed again.
+ in_progress = blocked['AUDIO'].pause()
+ if isinstance(in_progress, kaa.notifier.InProgress):
+ # takes some time, wait
+ in_progress.connect(retry).set_ignore_caller_args()
+ if in_progress is not False:
+ # we paused the application, resume on our stop
+ self.signals['stop'].connect_once(blocked['AUDIO'].resume)
+ return True
+
+ # store item
+ self.item = item
+ self.status = STATUS_RUNNING
+
+ self.player.open(self.item)
+ self.player.signals['failed'].connect_once(self._play_failed)
+ self.player.signals['end'].connect_once(PLAY_END.post, self.item)
+ self.player.signals['start'].connect_once(PLAY_START.post, self.item)
+ self.player.play()
+
+
+ def _play_failed(self):
+ """
+ Playing this item failed.
+ """
+ log.error('playback failed for %s', self.item)
+
+
+ def stop(self):
+ """
+ Stop playing.
+ """
+ if self.get_status() != STATUS_RUNNING:
+ return True
+ self.player.stop()
+ self.status = STATUS_STOPPING
+
+
+ def eventhandler(self, event):
+ """
+ React on events and do the right command with the game.
+ """
+ if event == STOP:
+ self.stop()
+ if not self.player.is_running():
+ self.item.eventhandler(event)
+ self.status = STATUS_IDLE
+ return True
+
+ elif event == PLAY_END:
+ self.stop()
+ self.show()
+ self.item.eventhandler(event)
+ return True
+
+ return self.item.eventhandler(event)
+
+
+player = kaa.utils.Singleton(GamesPlayer)
+play = player.play
+stop = player.stop
+
Added: trunk/ui/src/games/plugins/__init__.py
==============================================================================
Added: trunk/ui/src/games/plugins/config.cxml
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/config.cxml Wed Mar 28 17:58:31 2007
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<config name="games.plugin">
+ <desc lang="en">games plugins</desc>
+ <group name="zsnes" plugin="0">
+ <desc>
+ Set the parameters for the zsnes emulator.
+ games.plugin.zsnes.activate = 0
+ games.plugin.zsnes.path[0].path = $(HOME)/snes
+ games.plugin.zsnes.path[0].name = Main Roms
+ games.plugin.zsnes.name = SNes Games
+ games.plugin.zsnes.bin = /usr/local/bin/zsnes
+ games.plugin.zsnes.parameters = -m -r 3 -k 100
+ games.plugin.zsnes.suffix = smc,zip
+ </desc>
+ <list name="path">
+ <var name="name" type="unicode">
+ <desc>Name for the path to the roms</desc>
+ </var>
+ <var name="path" type="str">
+ <desc>The path to find the roms</desc>
+ </var>
+ </list>
+ <var name="name" type="unicode">
+ <desc>Name in the games menu</desc>
+ </var>
+ <var name="bin" type="str">
+ <desc>The binary for the zsnes emulator</desc>
+ </var>
+ <var name="parameters" type="str">
+ <desc>The parameters to give to the zsnes emulator on start</desc>
+ </var>
+ <var name="suffix" default="zip,scm">
+ <desc>The suffix of the roms</desc>
+ </var>
+ </group>
+
+ <group name="pcgames" plugin="0">
+ <desc>
+ Set the parameters for the PC games.
+ games.plugin.pcgames.activate = 20
+ games.plugin.pcgames.name = PC Games
+ games.plugin.pcgames.items[0].bin = /usr/games/bin/einstein
+ games.plugin.pcgames.items[0].parameters =
+ games.plugin.pcgames.items[0].name = Einstein
+ </desc>
+ <var name="name" type="unicode">
+ <desc>Name in the games menu</desc>
+ </var>
+ <list name="items">
+ <var name="name" type="unicode">
+ <desc>Name of the game</desc>
+ </var>
+ <var name="bin" type="str">
+ <desc>The binary for the emulator</desc>
+ </var>
+ <var name="parameters" type="str">
+ <desc>The parameters to give to the emulator on start</desc>
+ </var>
+ </list>
+ </group>
+
+ <group name="scummvm" plugin="0">
+ <desc>
+ Set the parameters for the scummvm.
+ </desc>
+ <var name="name" default="ScummVM">
+ <desc>Name in the games menu</desc>
+ </var>
+ <var name="bin" default="scummvm">
+ <desc>The binary of the scummvm (searched in PATH)</desc>
+ </var>
+ <var name="parameters" type="str">
+ <desc>The parameters to start the scummvm</desc>
+ </var>
+
+ </group>
+
+</config>
Added: trunk/ui/src/games/plugins/pcgames.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/pcgames.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,140 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# pcgames.py - the pycgames item and player
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# The PcGamesItem represents a PC game that can be started through the
+# PcGamesPlayer. Both classes are derived from the corresponding classes
+# in emulator module.
+# The PluginInterface class creates the list with all the games. The games
+# here have to be listed in the config file since there are no roms involved.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+# python imports
+import logging
+
+# Freevo imports
+from freevo.ui.mainmenu import MainMenuPlugin
+from freevo.ui.menu import ActionItem, Menu, Action
+from freevo.ui.config import config
+
+# games imports
+from freevo.ui.games.emulator import EmulatorItem, EmulatorPlayer
+import freevo.ui.games.player as gameplayer
+
+# get logging object
+log = logging.getLogger('games')
+
+# get config object
+config = config.games.plugin.pcgames
+
+
+class PcGamePlayer(EmulatorPlayer):
+ """
+ The PcGamePlayer loader.
+ """
+
+ def open(self, item):
+ """
+ Open a PcGameItem, get executable and parameters for playing
+ """
+ self.command_name = item.binary
+ self.parameters = item.parameters
+
+
+ def play(self):
+ """
+ Play PcGame
+ """
+ log.info('Start playing PcGame (%s %s)', self.command_name,
self.parameters)
+ self._releaseJoystick()
+ self.child = kaa.notifier.Process(self.command_name)
+ self.child.start(self.parameters).connect(self.completed)
+ self.signals = self.child.signals
+ stop = kaa.notifier.WeakCallback(self.stop)
+ self.child.set_stop_command(stop)
+
+
+ def completed(self, child):
+ """
+ The game was quit. Send Stop event to get back to the menu.
+ """
+ Event(STOP, handler=gameplayer.player.eventhandler).post()
+ self._acquireJoystick()
+ log.info('Game completed')
+
+
+ def actions(self):
+ """
+ The actions for the games
+ """
+ return [ Action(_('Play %s') % self.name, self.play) ]
+
+
+class PcGameItem(EmulatorItem):
+ """
+ Item for a PC game.
+ """
+
+ def __init__(self, parent, name, bin, parameters=""):
+ EmulatorItem.__init__(self, parent, name)
+ self.binary = bin
+ self.parameters = parameters
+
+
+ def play(self):
+ """
+ Start the game.
+ """
+ gameplayer.play(self, PcGamePlayer())
+
+
+class PluginInterface(MainMenuPlugin):
+ """
+ Add PC game to games menu
+ """
+
+ def roms(self, parent):
+ """
+ Show all games.
+ """
+ items = []
+ for item in config.items:
+ i = PcGameItem(parent, item.name, item.bin, item.parameters)
+ items.append(i)
+ parent.pushmenu(Menu(_('PC Games'), items, type='games'))
+
+
+ def items(self, parent):
+ """
+ Return the main menu item.
+ """
+ if not config.items:
+ # no items defined
+ return []
+ return [ ActionItem(config.name, parent, self.roms) ]
Added: trunk/ui/src/games/plugins/scummvm.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/scummvm.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,128 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# scummvm.py - the scummvm player
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# The scummvm player is a player for the scummvm. You need to have loaded
+# the game previous with the scummvm. It will find all the configured
+# games. In addition it will offer to run the scummvm without a game to
+# configure a new game.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+# python imports
+import logging
+from subprocess import Popen, PIPE
+
+# kaa imports
+import kaa.utils
+
+# Freevo imports
+from freevo.ui.mainmenu import MainMenuPlugin
+from freevo.ui.menu import ActionItem, Menu, Action
+from freevo.ui.config import config
+
+# games imports
+from pcgames import PcGamePlayer, PcGameItem
+import freevo.ui.games.player as gameplayer
+
+# get logging object
+log = logging.getLogger('games')
+
+# get config object
+config = config.games.plugin.scummvm
+
+class ScummvmPlayer(PcGamePlayer):
+ """
+ The PcGamePlayer loader.
+ """
+
+ def open(self, item):
+ """
+ Open a PcGameItem, get executable and parameters for playing
+ """
+ self.emulator_item = item.binary
+
+
+ def play(self):
+ """
+ Play PcGame
+ """
+ log.info('Start playing PcGame (Scummvm: %s)', self.emulator_item)
+ parameters = '%s %s' % (config.parameters, self.emulator_item)
+ self._releaseJoystick()
+ self.child = kaa.notifier.Process(config.bin)
+ self.child.start(parameters).connect(self.completed)
+ self.signals = self.child.signals
+ stop = kaa.notifier.WeakCallback(self.stop)
+ self.child.set_stop_command(stop)
+
+
+class ScummvmItem(PcGameItem):
+ """
+ A scummvm Item
+ """
+
+ def play(self):
+ gameplayer.play(self, ScummvmPlayer())
+
+
+class PluginInterface(MainMenuPlugin):
+ """
+ Add Scummvm games to the games menu
+ """
+ romlist = []
+ finished = False
+
+ def roms(self, parent):
+ """
+ Show all games.
+ """
+ items = []
+ # get list of scummvm
+ pipe = Popen([config.bin, '-t'], stdout=PIPE).stdout
+ # FIXME: this blocks the notifier loop. Maybe better use
+ # kaa.notifier.Process and yield_execution.
+ for item in pipe.readlines()[2:]:
+ name = item[:item.find(' ')]
+ description = item[item.find(' '):].strip()
+ items.append(ScummvmItem(parent, description, name))
+ # append the scummvm it self, to configure new games
+ items.append(ScummvmItem(parent, 'ScummVM', ''))
+ parent.pushmenu(Menu(config.name, items, type='games'))
+
+
+ def items(self, parent):
+ """
+ Return the main menu item.
+ """
+ if not config.bin or \
+ (not config.bin.startswith('/') and not
+ kaa.utils.which(config.bin)):
+ # no binary defined or not found
+ return []
+ return [ ActionItem(config.name, parent, self.roms) ]
Added: trunk/ui/src/games/plugins/zsnes.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/zsnes.py Wed Mar 28 17:58:31 2007
@@ -0,0 +1,56 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# zsnes.py - the plugin for the ZSnes player
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# This is a plugin for the zsnes player. It uses the generic emulator player.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Mathias Weber <[EMAIL PROTECTED]>
+# Maintainer: Mathias Weber <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS 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
+#
+# -----------------------------------------------------------------------------
+
+# freevo imports
+from freevo.ui.config import config
+
+# games imports
+from freevo.ui.games import emulator
+
+# get config object
+config = config.games.plugin.zsnes
+
+class PluginInterface(emulator.Plugin):
+ """
+ Add the zsnes items to the games menu
+ """
+
+ def items(self, parent):
+ """
+ Return the main menu item.
+ """
+ if not config.path:
+ # no items defined
+ return []
+ return [ emulator.EmulatorMenuItem(parent, config.name, config.path,
+ self.roms, config) ]
Modified: trunk/ui/src/gui/compat.py
==============================================================================
--- trunk/ui/src/gui/compat.py (original)
+++ trunk/ui/src/gui/compat.py Wed Mar 28 17:58:31 2007
@@ -129,6 +129,11 @@
return self.engine.canvas._window
+class _Gamesplayer(BaseApplication):
+ name = 'games'
+ areas = ()
+
+
_Tvplayer = _Videoplayer
def Application(name):
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog