Author: dmeyer
Date: Sun Oct 16 08:00:47 2005
New Revision: 7708

Added:
   trunk/freevo/src/games/factory.py
   trunk/freevo/src/games/plugins/advmame.py
   trunk/freevo/src/games/plugins/emulator.py
   trunk/freevo/src/games/plugins/fakenes.py
   trunk/freevo/src/games/singleton.py
Modified:
   trunk/freevo/src/games/__init__.py
   trunk/freevo/src/games/gameitem.py
   trunk/freevo/src/games/interface.py
   trunk/freevo/src/games/plugins/zsnes.py
   trunk/freevo/src/plugin.py

Log:
games update by Daniel C. Casimiro

Modified: trunk/freevo/src/games/__init__.py
==============================================================================
--- trunk/freevo/src/games/__init__.py  (original)
+++ trunk/freevo/src/games/__init__.py  Sun Oct 16 08:00:47 2005
@@ -8,7 +8,7 @@
 # Todo:        
 #
 # -----------------------------------------------------------------------
-# $Log$
+# $Log: __init__.py,v $
 # Revision 1.23  2005/09/03 08:01:54  dischi
 # make it work again (patch from [EMAIL PROTECTED])
 #
@@ -49,4 +49,3 @@
 # ----------------------------------------------------------------------- */
 
 from interface import *
-from player import gamesplayer

Added: trunk/freevo/src/games/factory.py
==============================================================================
--- (empty file)
+++ trunk/freevo/src/games/factory.py   Sun Oct 16 08:00:47 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

Modified: trunk/freevo/src/games/gameitem.py
==============================================================================
--- trunk/freevo/src/games/gameitem.py  (original)
+++ trunk/freevo/src/games/gameitem.py  Sun Oct 16 08:00:47 2005
@@ -1,37 +1,69 @@
-# game item
-# Daniel Casimiro
-
-import logging
-import event
-from player import gamesplayer
-
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# emulator.py - the Freevo game item.
+# -----------------------------------------------------------------------------
+#
+# This class is used to display roms in the freevo menu.  It also connects the
+# roms to the correct emulators.
+#
+# -----------------------------------------------------------------------------
+# 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 menu import MediaItem, Action
 
-log = logging.getLogger('games')
-log.setLevel(logging.DEBUG)
-
 class GameItem(MediaItem):
-    def __init__(self, url, parent):
+    """
+    This is a virtual representation of the rom.
+    """
+    def __init__(self, parent, url, system):
         MediaItem.__init__(self, parent, type='games')
-
-        self.player = None
-        log.debug('Initialized GameItem. URL is %s' % (url))
         self.set_url(url)
+        self.__emu = None
+        self.__sys = system
+
+        # try to load a screen shot if it is available...
+        try:
+            import kaa.imlib2, zipfile, os.path
+            (path, name) = (url.dirname, url.basename)
+            # TODO: Change hard coded mame path to a more general case...
+            # TODO: cache screen shots ?
+            snaps = zipfile.ZipFile(os.path.join(path, '../snap/snap.zip'))
+            shotname = name.split('.')[0] + '.png'
+            self.image = kaa.imlib2.open_from_memory(snaps.read(shotname))
+        except:
+            pass
 
     def actions(self):
         items = [Action(_('Play'), self.play)]
         return items
 
     def play(self):
-        gamesplayer().play(self)
-
-    def stop(self):
-        gamesplayer().stop()
+        from factory import Factory
+        self.__emu = Factory().player(self)
+        self.__emu.launch(self)
 
-    def eventhandler(self, ev):
-        print "Game Item event handler:", ev
-        if ev == event.MENU:
-            self.player.stop()
-            return True
+    def get_system(self):
+        return self.__sys
 
-        return MediaItem.eventhandler(self, ev)
+    system = property(get_system, None)

Modified: trunk/freevo/src/games/interface.py
==============================================================================
--- trunk/freevo/src/games/interface.py (original)
+++ trunk/freevo/src/games/interface.py Sun Oct 16 08:00:47 2005
@@ -1,4 +1,36 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# interface.py - the Freevo interface to the games section
+# -----------------------------------------------------------------------------
+#
+# Populates the games section with the available roms
+#
+# -----------------------------------------------------------------------------
+# 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
+import config
 from gameitem import GameItem
 
 class PluginInterface(plugin.MimetypePlugin):
@@ -9,22 +41,42 @@
         plugin.MimetypePlugin.__init__(self)
         self.display_type = [ 'games' ]
 
+        import logging
+        self.__log = logging.getLogger('games')
+
         # activate the mediamenu for video
         plugin.activate('mediamenu', level=plugin.is_active('games')[2],
                         args='games')
 
     def suffix(self):
-        return ['smc']
+        """
+        the suffixes are specified in the config file.
+        """
+        suf = []
+        for item in config.GAMES_ITEMS:
+            suf += item[2][4]
+
+        self.__log.debug('The supported suffixes are %s' % suf)
+        return suf
 
     def get(self, parent, listing):
         items = []
 
-        all_files = listing.match_suffix('smc')
+        self.__log.info('Adding %s to menu' % listing)
+
+        systemmarker = None
+        dirname = listing.dirname[:-1]
+        for item in config.GAMES_ITEMS:
+            if item[1] == dirname:
+                systemmarker = item[2][0]
+                break
+
+        all_files = listing.match_suffix(self.suffix())
         all_files.sort(lambda l, o: cmp(l.basename.upper(),
-                                         o.basename.upper()))
+                                        o.basename.upper()))
 
         for file in all_files:
             # TODO: Build snapshots of roms.
-            items.append(GameItem(file, parent))
+            items.append(GameItem(parent, file, systemmarker))
             
         return items

Added: trunk/freevo/src/games/plugins/advmame.py
==============================================================================
--- (empty file)
+++ trunk/freevo/src/games/plugins/advmame.py   Sun Oct 16 08:00:47 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/freevo/src/games/plugins/emulator.py
==============================================================================
--- (empty file)
+++ trunk/freevo/src/games/plugins/emulator.py  Sun Oct 16 08:00:47 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/freevo/src/games/plugins/fakenes.py
==============================================================================
--- (empty file)
+++ trunk/freevo/src/games/plugins/fakenes.py   Sun Oct 16 08:00:47 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')

Modified: trunk/freevo/src/games/plugins/zsnes.py
==============================================================================
--- trunk/freevo/src/games/plugins/zsnes.py     (original)
+++ trunk/freevo/src/games/plugins/zsnes.py     Sun Oct 16 08:00:47 2005
@@ -1,11 +1,36 @@
-# ZSNES plugin
-# Daniel Casimiro <[EMAIL PROTECTED]>
-
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# zsnes.py - the Freevo zsnes support
+# -----------------------------------------------------------------------------
+#
+# Add support for the zsnes 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
-import config
-from event import *
-
-from application import ChildApp
+from emulator import Emulator
 
 class PluginInterface(plugin.Plugin):
     """
@@ -15,27 +40,10 @@
     def __init__(self):
         plugin.Plugin.__init__(self)
         plugin.register(Zsnes(), plugin.GAMES, True)
-        print 'zsnes activated!'
 
-class Zsnes(ChildApp):
+class Zsnes(Emulator):
     """
     Use this interface to control zsnes.
     """
     def __init__(self):
-        ChildApp.__init__(self, 'zsnes', 'games', True, False, True)
-    
-
-    def play(self, item, player):
-        self.player = player
-        cmd = 'zsnes'
-        self.child_start([cmd, item.filename], stop_cmd='quit\n')
-
-    def eventhandler(self, event):
-        print 'zsnes eventhandler:', event
-
-        if event == PLAY_END:
-            self.stop()
-            self.player.eventhandler(event)
-            return True
-
-        return False
+        Emulator.__init__(self, 'zsnes', 'SNES')

Added: trunk/freevo/src/games/singleton.py
==============================================================================
--- (empty file)
+++ trunk/freevo/src/games/singleton.py Sun Oct 16 08:00:47 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

Modified: trunk/freevo/src/plugin.py
==============================================================================
--- trunk/freevo/src/plugin.py  (original)
+++ trunk/freevo/src/plugin.py  Sun Oct 16 08:00:47 2005
@@ -241,7 +241,7 @@
 VIDEO_PLAYER   = 'VIDEO_PLAYER'
 TV             = 'TV'
 RECORD         = 'RECORD'
-
+GAMES          = 'GAMES'
 
 def event(name, *args):
     """


-------------------------------------------------------
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

Reply via email to