Update of /cvsroot/freevo/freevo/src/application
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29404/src/application

Modified Files:
        __init__.py base.py childapp.py eventhandler.py mplayer.py 
Log Message:
fix a stupid display, focus and childapp bug

Index: childapp.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/application/childapp.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** childapp.py 21 Jul 2005 17:10:32 -0000      1.8
--- childapp.py 21 Jul 2005 18:42:50 -0000      1.9
***************
*** 155,161 ****
          when the child is finished.
          """
          self.__child = None
-         if hasattr(self, 'item') and self.item:
-             PLAY_END.post(self.item)
  
  
--- 155,164 ----
          when the child is finished.
          """
+         if self.__class__.child_finished == Application.child_finished and \
+                hasattr(self, 'item') and self.item:
+             event = Event(PLAY_END)
+             event.handler = self.eventhandler
+             event.post(self.item)
          self.__child = None
  
  

Index: mplayer.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/application/mplayer.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** mplayer.py  16 Jul 2005 09:48:21 -0000      1.5
--- mplayer.py  21 Jul 2005 18:42:50 -0000      1.6
***************
*** 55,64 ****
          init the mplayer object
          """
!         childapp.Application.__init__(self, 'mplayer', type, has_video)
          self.name = 'mplayer'
-         self.__child = None
-         self.__has_video = has_video
          self.plugins = []
          self.plugin_key = 'mplayer_' + type
  
  
--- 55,65 ----
          init the mplayer object
          """
!         self.__elapsed = 0
!         self.__stop_reason = ''
!         self.RE_TIME = re.compile("^A: *([0-9]+)").match
          self.name = 'mplayer'
          self.plugins = []
          self.plugin_key = 'mplayer_' + type
+         childapp.Application.__init__(self, 'mplayer', type, has_video)
  
  
***************
*** 73,77 ****
  
          cmd = self.correct_filter_chain(cmd)
!         self.__child = Process(cmd, self, self.__has_video)
  
  
--- 74,78 ----
  
          cmd = self.correct_filter_chain(cmd)
!         self.child_start(cmd, prio=config.MPLAYER_NICE, stop_cmd='quit')
  
  
***************
*** 105,114 ****
              p.stop()
          self.plugins = []
!         if not self.__child:
!             return
!         # proc will send a PLAY_END when it's done. At this point we
!         # will call childapp.Application.stop(self)
!         self.__child.stop('quit\n')
!         self.__child = None
  
  
--- 106,110 ----
              p.stop()
          self.plugins = []
!         self.child_stop(self)
  
  
***************
*** 117,128 ****
          Return True if mplayer is playing right now.
          """
!         return self.__child and self.__child.is_alive()
! 
! 
!     def has_child(self):
!         """
!         Return True if the application is still connected to a process
!         """
!         return self.__child
  
  
--- 113,117 ----
          Return True if mplayer is playing right now.
          """
!         return self.child_running()
  
  
***************
*** 131,136 ****
          Send a command to mplayer.
          """
!         if self.__child:
!             self.__child.write(cmd)
  
  
--- 120,124 ----
          Send a command to mplayer.
          """
!         return self.child_stdin(cmd)
  
  
***************
*** 149,152 ****
--- 137,182 ----
  
  
+     def child_stdout(self, line):
+         """
+         A line from stdout of mplayer.
+         """
+         if line.find("A:") == 0:
+             m = self.RE_TIME(line)
+             if hasattr(m,'group') and self.__elapsed != int(m.group(1))+1:
+                 self.__elapsed = int(m.group(1))+1
+                 for p in self.plugins:
+                     p.elapsed(sec)
+                 self.elapsed(self.__elapsed)
+ 
+         # startup messages
+         elif not self.__elapsed:
+             for p in self.plugins:
+                 p.message(sec)
+             self.message(line)
+ 
+ 
+     def child_stderr(self, line):
+         """
+         A line from stdout of mplayer.
+         """
+         if line.startswith('Failed to open') and not self.__elapsed:
+             self.__stop_reason = line
+         else:
+             for p in self.plugins:
+                 p.message(sec)
+             self.message(line)
+ 
+ 
+     def child_finished(self):
+         """
+         Callback when the child is finished. Override this method to react
+         when the child is finished.
+         """
+         childapp.Application.child_finished(self)
+         event = Event(PLAY_END, self.__stop_reason)
+         event.set_handler(self.eventhandler)
+         event.post()
+ 
+ 
      def eventhandler(self, event):
          """
***************
*** 161,166 ****
  
          for p in self.plugins:
!             if p.eventhandler(event):
!                 return True
  
          return False
--- 191,195 ----
  
          for p in self.plugins:
!             p.eventhandler(event)
  
          return False
***************
*** 216,269 ****
          """
          return False
- 
- 
- class Process(childapp.Process):
-     """
-     Internal childapp instance for the mplayer process.
-     """
-     def __init__(self, cmd, handler, has_display):
-         self.elapsed = 0
-         self.stop_reason = ''
-         self.RE_TIME = re.compile("^A: *([0-9]+)").match
-         childapp.Process.__init__(self, cmd, handler, config.MPLAYER_NICE,
-                                   has_display)
- 
- 
-     def stop_event(self):
-         """
-         Return the stop event send through the eventhandler
-         """
-         event = Event(PLAY_END, self.stop_reason)
-         event.set_handler(self.handler.eventhandler)
-         return event
-     
- 
-     def stdout_cb(self, line):
-         """
-         Handle mplayer stdout lines.
-         """
-         if line.find("A:") == 0:
-             m = self.RE_TIME(line)
-             if hasattr(m,'group') and self.elapsed != int(m.group(1))+1:
-                 self.elapsed = int(m.group(1))+1
-                 for p in self.handler.plugins:
-                     p.elapsed(sec)
-                 self.handler.elapsed(self.elapsed)
- 
-         # startup messages
-         elif not self.elapsed:
-             for p in self.handler.plugins:
-                 p.message(sec)
-             self.handler.message(line)
- 
- 
-     def stderr_cb(self, line):
-         """
-         Handle mplayer stderr lines.
-         """
-         if line.startswith('Failed to open') and not self.elapsed:
-             self.stop_reason = line
-         else:
-             for p in self.handler.plugins:
-                 p.message(sec)
-             self.handler.message(line)
--- 245,246 ----

Index: eventhandler.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/application/eventhandler.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** eventhandler.py     16 Jul 2005 15:00:33 -0000      1.5
--- eventhandler.py     21 Jul 2005 18:42:50 -0000      1.6
***************
*** 102,105 ****
--- 102,108 ----
  
  
+ # Signals
+ app_change_signal = kaa.notifier.Signal()
+ 
  # 
-----------------------------------------------------------------------------
  
***************
*** 112,128 ****
          self.popups       = []
          self.applications = []
-         self.stack_change = None
          # callback for events
          kaa.notifier.EventHandler(self.handle).register()
          
  
!     def set_focus(self):
          """
          change the focus
          """
!         if self.stack_change:
!             previous, app = self.stack_change
!         else:
!             previous, app = None, self.applications[-1]
          if not self.popups:
              input.set_mapping(app.get_eventmap())
--- 115,127 ----
          self.popups       = []
          self.applications = []
          # callback for events
          kaa.notifier.EventHandler(self.handle).register()
          
  
!     def set_focus(self, previous, app):
          """
          change the focus
          """
!         log.info('set focus from %s to %s' % (previous, app))
          if not self.popups:
              input.set_mapping(app.get_eventmap())
***************
*** 133,142 ****
          if previous:
              if previous.visible:
                  previous.hide()
              fade = fade or previous.animated
!         log.info('SCREEN_CONTENT_CHANGE')
!         Event(SCREEN_CONTENT_CHANGE, (app, app.fullscreen, fade)).post()
!         self.stack_change = None
          if not app.visible:
              app.show()
          
--- 132,144 ----
          if previous:
              if previous.visible:
+                 log.info('hide previous app')
                  previous.hide()
              fade = fade or previous.animated
! 
!         log.info('signal screen content change')
!         app_change_signal.emit(app, app.fullscreen, fade)
! 
          if not app.visible:
+             log.info('make current app visible')
              app.show()
          
***************
*** 146,149 ****
--- 148,152 ----
          Add app the list of applications and set the focus
          """
+         log.info('new application %s' % app)
          # make sure the app is not stopped
          app.stopped = False
***************
*** 152,171 ****
              # just add the application
              self.applications.append(app)
!             return self.set_focus()
          # check about the old app if it is marked as removed
          # or if it is the same application as before
          previous = self.applications[-1]
          if previous == app:
              previous.stopped = False
          else:
              # hide the application and mark the application change
              previous.hide()
-             self.stack_change = previous, app
              if previous.stopped:
                  # the previous application is stopped, remove it
                  self.applications.remove(previous)
-             self.stack_change = previous, app
              self.applications.append(app)
!             self.set_focus()
  
  
--- 155,174 ----
              # just add the application
              self.applications.append(app)
!             self.set_focus(None, app)
!             return True
          # check about the old app if it is marked as removed
          # or if it is the same application as before
          previous = self.applications[-1]
          if previous == app:
+             # It is the same app, just remove the stopped flag
              previous.stopped = False
          else:
              # hide the application and mark the application change
              previous.hide()
              if previous.stopped:
                  # the previous application is stopped, remove it
                  self.applications.remove(previous)
              self.applications.append(app)
!             self.set_focus(previous, app)
  
  
***************
*** 233,241 ****
  
              # now do some checking if the focus needs to be changed
!             if self.stack_change:
!                 # our stack has changed, reset the focus
!                 self.set_focus()
!             elif self.applications[-1].stopped or \
!                      not self.applications[-1].visible:
                  # the current application wants to be removed, either
                  # because stop() is called or the hide() function was
--- 236,242 ----
  
              # now do some checking if the focus needs to be changed
!             if self.applications[-1].stopped or \
!                    not self.applications[-1].visible:
!                 log.info('current application is stopped')
                  # the current application wants to be removed, either
                  # because stop() is called or the hide() function was
***************
*** 243,248 ****
                  previous, current = self.applications[-2:]
                  self.applications.remove(current)
!                 self.stack_change = current, previous
!                 self.set_focus()
  
              if _TIME_DEBUG:
--- 244,248 ----
                  previous, current = self.applications[-2:]
                  self.applications.remove(current)
!                 self.set_focus(current, previous)
  
              if _TIME_DEBUG:

Index: base.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/application/base.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** base.py     16 Jul 2005 15:02:45 -0000      1.11
--- base.py     21 Jul 2005 18:42:50 -0000      1.12
***************
*** 64,68 ****
          self.animated   = animated
          self.visible    = False
!         self.stopped    = False
          self.fullscreen = fullscreen
  
--- 64,68 ----
          self.animated   = animated
          self.visible    = False
!         self.stopped    = True
          self.fullscreen = fullscreen
  
***************
*** 72,76 ****
          Eventhandler for this application
          """
!         print 'Error, no eventhandler defined for %s' % self.application
  
  
--- 72,77 ----
          Eventhandler for this application
          """
!         error = 'Error, no eventhandler defined for %s' % self.application
!         raise AttributeError(error)
  
  
***************
*** 82,86 ****
          display.
          """
-         self.stopped = False
          if self.visible:
              # already visible
--- 83,86 ----
***************
*** 88,92 ****
          # Set visible and append to the eventhandler
          self.visible = True
!         self.__handler.append(self)
          # Check if the new app uses animation to show itself
          if not self.animated:
--- 88,94 ----
          # Set visible and append to the eventhandler
          self.visible = True
!         if self.stopped:
!             self.__handler.append(self)
!             self.stopped = False
          # Check if the new app uses animation to show itself
          if not self.animated:
***************
*** 151,152 ****
--- 153,161 ----
          return self.__name
      
+ 
+     def __str__(self):
+         """
+         String for debugging.
+         """
+         return self.__name
+         

Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/application/__init__.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** __init__.py 16 Jul 2005 15:00:32 -0000      1.5
--- __init__.py 21 Jul 2005 18:42:50 -0000      1.6
***************
*** 2,4 ****
  from menuapp import MenuApplication
  from childapp import Application as ChildApp
! from eventhandler import add_window, remove_window, get_active
--- 2,8 ----
  from menuapp import MenuApplication
  from childapp import Application as ChildApp
! from eventhandler import add_window, remove_window, get_active, \
!      app_change_signal
! 
! # signals defined by the application base code
! signals = { 'application change': app_change_signal }



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to