Author: dmeyer
Date: Wed Oct 19 11:05:07 2005
New Revision: 7750
Added:
trunk/ui/src/games/factory.py
trunk/ui/src/games/plugins/advmame.py
trunk/ui/src/games/plugins/emulator.py
trunk/ui/src/games/plugins/fakenes.py
trunk/ui/src/games/singleton.py
Log:
re-add games patch
Added: trunk/ui/src/games/factory.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/factory.py Wed Oct 19 11:05:07 2005
@@ -0,0 +1,52 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# factory.py - the Freevo game factory
+# -----------------------------------------------------------------------------
+#
+# Returns the correct game player based on the game item.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dan Casimiro <[EMAIL PROTECTED]>
+# Maintainer: Dan Casimiro <[EMAIL PROTECTED]>
+#
+# 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
+#
+# -----------------------------------------------------------------------------
+from singleton import Singleton
+import plugin
+
+class Factory(Singleton):
+ def init(self):
+ import logging
+ self.__log = logging.getLogger('games')
+ self.__log.debug('Initiated the games factory')
+ # get a list of available emulators
+ self.__players = plugin.getbyname(plugin.GAMES, True)
+
+ def player(self, gameitem):
+ import logging
+ log = logging.getLogger('games')
+ log.debug('Loading an emulator of type %s' % gameitem.system)
+
+ for player in self.__players:
+ if gameitem.system == player.systemtype:
+ return player
+
+ return None
Added: trunk/ui/src/games/plugins/advmame.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/advmame.py Wed Oct 19 11:05:07 2005
@@ -0,0 +1,67 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# advmame.py - the Freevo advance mame support
+# -----------------------------------------------------------------------------
+#
+# Add support for the advance mame emulator
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dan Casimiro <[EMAIL PROTECTED]>
+# Maintainer: Dan Casimiro <[EMAIL PROTECTED]>
+#
+# 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
+#
+# -----------------------------------------------------------------------------
+import plugin
+from emulator import Emulator
+
+class PluginInterface(plugin.Plugin):
+ """
+ zsnes plugin for gaming. This plugin allows you to use the zsnes
+ super nintendo emulator from within freevo.
+ """
+ def __init__(self):
+ plugin.Plugin.__init__(self)
+ plugin.register(AdvanceMame(), plugin.GAMES, True)
+
+class AdvanceMame(Emulator):
+ """
+ Use this interface to control zsnes.
+ """
+ def __init__(self):
+ Emulator.__init__(self, 'advmame', 'MAME')
+
+ def title(self):
+ import logging
+ log = logging.getLogger('games')
+ log.debug('AdvanceMAME is launching the %s rom' % \
+ (self.item.filename))
+
+ try:
+ # TODO: test this on python 2.4
+ game_name = self.item.filename.rsplit('/', 1).split('.', 1)
+ except AttributeError:
+ # the string method rsplit is new in python 2.4
+ # this code is to support python 2.3
+ index = self.item.filename.rindex('/') + 1
+ game_name = self.item.filename[index:].split('.', 1)[0]
+
+ log.debug('AdvanceMAME game name is %s' % game_name)
+ return game_name
Added: trunk/ui/src/games/plugins/emulator.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/emulator.py Wed Oct 19 11:05:07 2005
@@ -0,0 +1,79 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# emulator.py - the Freevo emulator base class
+# -----------------------------------------------------------------------------
+#
+# This is a generic emulator class that all of the supported emulators extend.
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dan Casimiro <[EMAIL PROTECTED]>
+# Maintainer: Dan Casimiro <[EMAIL PROTECTED]>
+#
+# 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
+#
+# -----------------------------------------------------------------------------
+import logging
+
+from application import ChildApp
+from event import *
+
+log = logging.getLogger('games')
+
+class Emulator(ChildApp):
+ """
+ Code used by all supported emulators
+
+ This is a generic emulator class that all of the supported emulators
+ extend. It is a nice place to store all the similar code.
+ """
+ def __init__(self, executable, systype):
+ """
+ 'executable' is the path to the emulator
+ """
+ ChildApp.__init__(self, executable, 'games', True, has_display=True)
+ self.__rom = None
+ self.__cmd = executable
+ self.__sys = systype
+
+ def __get_rom(self):
+ return self.__rom
+
+ def launch(self, rom):
+ self.__rom = rom
+ log.debug('The %s emulator is launching the %s rom' % \
+ (self.__cmd, self.__rom.filename))
+ self.child_start([self.__cmd, self.title()])
+
+ def eventhandler(self, event):
+ log.debug('The emulator eventhandler got an event: %s' % event)
+ if event == STOP:
+ self.stop()
+ return True
+
+ return ChildApp.eventhandler(self, event)
+
+ def title(self):
+ return self.item.filename
+
+ def __get_systemtype(self):
+ return self.__sys
+
+ item = property(__get_rom, None)
+ systemtype = property(__get_systemtype, None)
Added: trunk/ui/src/games/plugins/fakenes.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/plugins/fakenes.py Wed Oct 19 11:05:07 2005
@@ -0,0 +1,49 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# fakenes.py - the Freevo fakenes support
+# -----------------------------------------------------------------------------
+#
+# Add support for the fakenes NES emulator
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dan Casimiro <[EMAIL PROTECTED]>
+# Maintainer: Dan Casimiro <[EMAIL PROTECTED]>
+#
+# 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
+#
+# -----------------------------------------------------------------------------
+import plugin
+from emulator import Emulator
+
+class PluginInterface(plugin.Plugin):
+ """
+ fakenes plugin for gaming. This plugin allows you to use the fakenes
+ nintendo emulator from within freevo.
+ """
+ def __init__(self):
+ plugin.Plugin.__init__(self)
+ plugin.register(FakeNES(), plugin.GAMES, True)
+
+class FakeNES(Emulator):
+ """
+ Use this interface to control fakenes.
+ """
+ def __init__(self):
+ Emulator.__init__(self, 'fakenes', 'NES')
Added: trunk/ui/src/games/singleton.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/games/singleton.py Wed Oct 19 11:05:07 2005
@@ -0,0 +1,67 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# singleton.py - the Freevo singleton object
+# -----------------------------------------------------------------------------
+#
+# singleton object based on new style classes. This object comes from the
+# the python docs found at http://www.python.org/2.2/descrintro.html
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dan Casimiro <[EMAIL PROTECTED]>
+# Maintainer: Dan Casimiro <[EMAIL PROTECTED]>
+#
+# 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
+#
+# -----------------------------------------------------------------------------
+class Singleton(object):
+ """
+ This is a new style singleton class. The original code is found in the
+ python docs at http://www.python.org/2.2/descrintro.html
+
+ To create a singleton class, you subclass from Singleton; each subclass
+ will have a single instance, no matter how many times its constructor is
+ called. To further initialize the subclass instance, subclasses should
+ override 'init' instead of __init__ - the __init__ method is called each
+ time the constructor is called. For example:
+
+ >>> class MySingleton(Singleton):
+ ... def init(self):
+ ... print "calling init"
+ ... def __init__(self):
+ ... print "calling __init__"
+ ...
+ >>> x = MySingleton()
+ calling init
+ calling __init__
+ >>> assert x.__class__ is MySingleton
+ >>> y = MySingleton()
+ calling __init__
+ >>> assert x is y
+ """
+ def __new__(cls, *args, **kwds):
+ it = cls.__dict__.get("__it__")
+ if it is not None:
+ return it
+ cls.__it__ = it = object.__new__(cls)
+ it.init(*args, **kwds)
+ return it
+
+ def init(self, *args, **kwds):
+ pass
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog