Ejemplo n.º 1
0
    def do_expose_event(self, event, widget):
        """Handle exposure event (trigger redraw by gst)"""
        log.info("Expose event: %s", event)
        from olpcgames import eventwrap

        eventwrap.post(eventwrap.Event(eventwrap.pygame.VIDEOEXPOSE))
        return True
 def addBuddy(self, handle, buddy):
     """Add a new buddy to internal structures
     
     Note: this is called in the GObject thread!
     """
     try:
         current = self._buddies.get(handle)
         if current is False:
             self.removeBuddy(handle)
             return  # we left before we got our metadata
         text = textsprite.TextSprite(
             text=buddy.props.nick,
             color=(255, 255, 255),
             size=11,
         )
         self._buddies[handle] = (buddy, text)
         for group in self.groups:
             group.add(text)
         #log.info( '''Created text for buddy: %s (%s)''', buddy.props.nick, handle )
         # send event to trigger a rendering/processing cycle...
         eventwrap.post(eventwrap.Event(
             pygame.USEREVENT,
             code=1,
         ))
         #log.debug( 'Sent user event' )
     except Exception, err:
         log.error("""Failure setting up buddy %s: %s""", buddy,
                   get_traceback(err))
Ejemplo n.º 3
0
 def write_file( self, file_path ):
     """Handle request to write to the given file on the Pygame side 
     
     This is rather complicated by the need to have the file complete by the 
     time the function returns.  Very poor API, after all, if I have to write a 
     multi-hundred-megabyte file it might take many minutes to complete 
     writing.
     """
     log.info( 'write_file: %s %s', file_path, self.metadata )
     if os.path.exists( file_path ):
         self.read_file( file_path )
     import olpcgames, pygame
     from olpcgames import eventwrap
     event = eventwrap.Event(
         type = pygame.USEREVENT,
         code = olpcgames.FILE_WRITE_REQUEST,
         filename = file_path,
         metadata = self.metadata,
     )
     eventwrap.post( event )
     event.block()
     if not os.path.exists( file_path ):
         log.warn( '''No file created in %r''', file_path )
         raise NotImplementedError( """Pygame Activity code did not produce a file for %s"""%( file_path, ))
     else:
         log.info( '''Stored file in %r''', file_path )
Ejemplo n.º 4
0
 def _post(self, evt):
     try:
         eventwrap.post(evt)
     except pygame.error, e:
         if str(e) == "Event queue full":
             print "Event queue full!"
             pass
         else:
             raise e
Ejemplo n.º 5
0
 def _post(self, evt):
     try:
         eventwrap.post(evt)
     except pygame.error, e:
         if str(e) == 'Event queue full':
             print "Event queue full!"
             pass
         else:
             raise e
Ejemplo n.º 6
0
 def _background_snap( 
     self,
     token = None,
 ):
     """Process gst messages until pipe is finished
     
     pipe -- gstreamer pipe definition for parse_launch, normally it will 
         produce a file into which the camera should store an image
     
     We consider pipe to be finished when we have had two "state changed"
     gstreamer events where the pending state is VOID, the first for when 
     we begin playing, the second for when we finish.
     """
     log.debug( 'Background thread kicking off gstreamer capture begun' )
     from olpcgames import eventwrap 
     from pygame.event import Event
     filename, pipe = self._create_pipe()
     bus = pipe.get_bus()
     bus.add_signal_watch()
     def _background_snap_onmessage( bus, message ):
         """Handle messages from the picture-snapping bus"""
         log.debug( 'Message handler for gst messages: %s', message )
         t = message.type
         if t == gst.MESSAGE_EOS:
             pipe.set_state(gst.STATE_NULL)
             try:
                 image = self._load_and_clean( filename )
                 success = True
             except Exception, err:
                 success = False
                 image = None 
             else:
                 err = None
             log.debug( 'Success loading file %r', token )
             eventwrap.post(Event(
                 CAMERA_LOAD, 
                 filename=filename, 
                 success = success,
                 token = token, 
                 image=image, 
                 err=err
             ))
             
         elif t == gst.MESSAGE_ERROR:
             log.warn( 'Failure loading file %r: %s', token, message )
             pipe.set_state(gst.STATE_NULL)
             err, debug = message.parse_error()
             eventwrap.post(Event(
                 CAMERA_LOAD_FAIL, 
                 filename=filename, 
                 success = False,
                 token = token, 
                 image=None, 
                 err=err
             ))
             return False
Ejemplo n.º 7
0
    def _background_snap(
        self,
        token=None,
    ):
        """Process gst messages until pipe is finished
        
        pipe -- gstreamer pipe definition for parse_launch, normally it will 
            produce a file into which the camera should store an image
        
        We consider pipe to be finished when we have had two "state changed"
        gstreamer events where the pending state is VOID, the first for when 
        we begin playing, the second for when we finish.
        """
        log.debug('Background thread kicking off gstreamer capture begun')
        from olpcgames import eventwrap
        from pygame.event import Event
        filename, pipe = self._create_pipe()
        bus = pipe.get_bus()
        bus.add_signal_watch()

        def _background_snap_onmessage(bus, message):
            """Handle messages from the picture-snapping bus"""
            log.debug('Message handler for gst messages: %s', message)
            t = message.type
            if t == gst.MESSAGE_EOS:
                pipe.set_state(gst.STATE_NULL)
                try:
                    image = self._load_and_clean(filename)
                    success = True
                except Exception, err:
                    success = False
                    image = None
                else:
                    err = None
                log.debug('Success loading file %r', token)
                eventwrap.post(
                    Event(CAMERA_LOAD,
                          filename=filename,
                          success=success,
                          token=token,
                          image=image,
                          err=err))

            elif t == gst.MESSAGE_ERROR:
                log.warn('Failure loading file %r: %s', token, message)
                pipe.set_state(gst.STATE_NULL)
                err, debug = message.parse_error()
                eventwrap.post(
                    Event(CAMERA_LOAD_FAIL,
                          filename=filename,
                          success=False,
                          token=token,
                          image=None,
                          err=err))
                return False
Ejemplo n.º 8
0
 def __call__(self, *args, **named):
     """PyGTK-side callback operation"""
     log.info('Callback %s return value *%s, **%s', self.callable, args,
              named)
     from olpcgames import eventwrap
     args = [wrap(a) for a in args]
     named = dict([(k, wrap(v)) for k, v in named.items()])
     eventwrap.post(
         eventwrap.CallbackResult(self.callable,
                                  args,
                                  named,
                                  callContext=self.callContext))
Ejemplo n.º 9
0
 def __call__( self, *args, **named ):
     """PyGTK-side callback operation"""
     log.info( 'Callback %s return value *%s, **%s', self.callable, args, named )
     from olpcgames import eventwrap
     args = [wrap(a) for a in args]
     named = dict([
         (k,wrap(v)) for k,v in named.items()
     ])
     eventwrap.post( 
         eventwrap.CallbackResult( 
             self.callable, args, named, callContext = self.callContext 
         )
     )
Ejemplo n.º 10
0
 def read_file(self, file_path):
     """Handle request to read the given file on the Pygame side
     
     This is complicated rather noticeably by the silly semantics of the Journal
     where it unlinks the file as soon as this method returns.  We either have to 
     handle the file-opening in PyGTK (not acceptable), block this thread until 
     the Pygame thread handles the event (which it may never do) or we have 
     to make the silly thing use a non-standard file-opening interface.
     """
     log.info( 'read_file: %s %s', file_path, self.metadata )
     import olpcgames, pygame
     from olpcgames import eventwrap
     event = eventwrap.Event(
         type = pygame.USEREVENT,
         code = olpcgames.FILE_READ_REQUEST,
         filename = file_path,
         metadata = self.metadata,
     )
     eventwrap.post( event )
     event.block()
Ejemplo n.º 11
0
 def _background_snap_onmessage(bus, message):
     """Handle messages from the picture-snapping bus"""
     log.debug('Message handler for gst messages: %s', message)
     t = message.type
     if t == gst.MESSAGE_EOS:
         pipe.set_state(gst.STATE_NULL)
         try:
             image = self._load_and_clean(filename)
             success = True
         except Exception, err:
             success = False
             image = None
         else:
             err = None
         log.debug('Success loading file %r', token)
         eventwrap.post(
             Event(CAMERA_LOAD,
                   filename=filename,
                   success=success,
                   token=token,
                   image=image,
                   err=err))
Ejemplo n.º 12
0
 def _background_snap_onmessage( bus, message ):
     """Handle messages from the picture-snapping bus"""
     log.debug( 'Message handler for gst messages: %s', message )
     t = message.type
     if t == gst.MESSAGE_EOS:
         pipe.set_state(gst.STATE_NULL)
         try:
             image = self._load_and_clean( filename )
             success = True
         except Exception, err:
             success = False
             image = None 
         else:
             err = None
         log.debug( 'Success loading file %r', token )
         eventwrap.post(Event(
             CAMERA_LOAD, 
             filename=filename, 
             success = success,
             token = token, 
             image=image, 
             err=err
         ))
Ejemplo n.º 13
0
 def _quit(self, data=None):
     self.__stopped = True
     eventwrap.post(eventwrap.Event(pygame.QUIT))
Ejemplo n.º 14
0
 def _quit(self, data=None):
     self.__stopped = True
     eventwrap.post(eventwrap.Event(pygame.QUIT))
Ejemplo n.º 15
0
 def do_expose_event(self, event, widget):
     """Handle exposure event (trigger redraw by gst)"""
     log.info('Expose event: %s', event)
     from olpcgames import eventwrap
     eventwrap.post(eventwrap.Event(eventwrap.pygame.VIDEOEXPOSE))
     return True
Ejemplo n.º 16
0
 def _quit(self, data=None):
     self.__stopped = True
     PCevent.post(Pevent.Event(pygame.QUIT))