Ok,

        Here is an updated patch that is a bit cleaner.  It correctly starts
the zsnes rom and shows the menu again when the user exits the emulator.
gamesupdate.p0 is a unified diff of the directory.  emulator.py is a new
file that lives in the plugins directory.  Here are the changes:

1. Removed player.py:  emulators are launched directly by the gameitem.
2. Added an "Emulator" class that handles all the redundant effort to
launch an emulator.
3. Added the freevo headers with the GPL.
4. Removed spurious print statements and imports.

        I put emulator.py in the plugins directory because zsnes.py could not
find the file in the base games directory.  Is there another, preferred,
method to handle this?

* still only supports zsnes.  I need to write a factory that loads the
correct emulator class.  I will (try to) find some time to do that next
weekend.

~Dan

On Mon, 2005-09-05 at 17:51 +0200, Dirk Meyer wrote:
> "Daniel C. Casimiro" wrote:
> > I wasn't quite ready for that code to be checked in; 
> 
> The old code was broken, yours can't be worse :)
> 
> > It don't consider it "ready" yet, but I will take a look at the
> > changes you made. >
> 
> My changes are in the application part, not in the games stuff. 
> 
> > I actually figured out what I was doing wrong, and the menus do show
> > up now.  There is less code, and think that the "nasty" trick has
> > been removed.  I don't have time right now to compare the changes
> > that Dischii made, but I will try to look at them tonight.  I will
> > take your suggestions into account at the same time (like removing
> > the player.py).
> 
> Yes, the player.ps is not needed. A games plugin is like a video
> player. It is fullscreen and does not need an extra gui (like
> player.py is only the gui for the background running apps).
> 
> 
> 
> Dischi

? gamesupdate.p0
? plugins/emulator.py
Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/__init__.py,v
retrieving revision 1.23
diff -u -r1.23 __init__.py
--- __init__.py 3 Sep 2005 08:01:54 -0000       1.23
+++ __init__.py 6 Sep 2005 01:31:36 -0000
@@ -49,4 +49,3 @@
 # ----------------------------------------------------------------------- */
 
 from interface import *
-from player import gamesplayer
Index: gameitem.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/gameitem.py,v
retrieving revision 1.1
diff -u -r1.1 gameitem.py
--- gameitem.py 3 Sep 2005 08:01:54 -0000       1.1
+++ gameitem.py 6 Sep 2005 01:31:36 -0000
@@ -1,37 +1,53 @@
-# 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):
+    """
+    This is a virtual representation of the rom.
+    """
     def __init__(self, url, parent):
         MediaItem.__init__(self, parent, type='games')
-
-        self.player = None
-        log.debug('Initialized GameItem. URL is %s' % (url))
         self.set_url(url)
+        self.__emu = None
 
     def actions(self):
         items = [Action(_('Play'), self.play)]
         return items
 
     def play(self):
-        gamesplayer().play(self)
-
-    def stop(self):
-        gamesplayer().stop()
-
-    def eventhandler(self, ev):
-        print "Game Item event handler:", ev
-        if ev == event.MENU:
-            self.player.stop()
-            return True
-
-        return MediaItem.eventhandler(self, ev)
+        # TODO: Get a factory that returns the right emulator
+        registerd_players = plugin.getbyname(plugin.GAMES, True)
+        # Only ZSNES plugin exists for now....
+        self.__emu = registerd_players[0]
+        self.__emu.launch(self)
Index: interface.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/interface.py,v
retrieving revision 1.7
diff -u -r1.7 interface.py
--- interface.py        3 Sep 2005 08:01:54 -0000       1.7
+++ interface.py        6 Sep 2005 01:31:36 -0000
@@ -1,3 +1,34 @@
+# -*- 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
 from gameitem import GameItem
 
Index: plugins/zsnes.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/plugins/zsnes.py,v
retrieving revision 1.1
diff -u -r1.1 zsnes.py
--- plugins/zsnes.py    3 Sep 2005 08:01:54 -0000       1.1
+++ plugins/zsnes.py    6 Sep 2005 01:31:36 -0000
@@ -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')
# -*- 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):
        """
        'executable' is the path to the emulator
        """
        ChildApp.__init__(self, executable, 'games', True, has_display=True)
        self.__rom = None
        self.__cmd = executable

    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.__rom.filename])

    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)
    
    item = property(__get_rom, None)

Reply via email to