Beispiel #1
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")
             
      for _ in self.waitBox("callback"):
         yield 1
      
      self.display = self.recv("callback")
      
      # in Drawing
      self.drawBG()
      self.blitToSurface()
      
      # in MouseEventHandling
      self.registerMouseListeners()
      
      done = False
      while not done:
         done = self.handleShutdown()  # in ShutdownHandling
         self.handleMouseEvents()  # in MouseEventHandling
         self.pause()
         yield 1
Beispiel #2
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"displaysignal"), displayservice)
     self.send(argd, "displaysignal")
     for _ in self.waitBox("displaycontrol"): yield 1
     display = self.recv("displaycontrol")
     self.display = display
Beispiel #3
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")
             
      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.drawBG()
      self.blitToSurface()
      
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEMOTION,
                  "surface" : self.display},
                  "display_signal")

      done = False
      while not done:
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True
         
         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if  event.button == 1:
                        self.drawing = True
                    elif event.button == 3:
                        self.oldpos = None
                        self.drawBG()
                        self.blitToSurface()

                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    self.drawing = False
                    self.oldpos = None
                elif event.type == pygame.MOUSEMOTION:
#                   print "BUTTON", event.button
                    if self.drawing and self.innerRect.collidepoint(*event.pos):
                        if self.oldpos == None:
                            self.oldpos = event.pos
                        else:
                            pygame.draw.line(self.display, (0,0,0), self.oldpos, event.pos, 3)
                            self.oldpos = event.pos
                        self.blitToSurface()
         if not done:
             self.pause()
         yield 1

      self.send(Axon.Ipc.producerFinished(message=self.display), "display_signal")
Beispiel #4
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"toDisplay"), displayservice)
     self.send(argd, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #5
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"toDisplay"), displayservice)
     self.send(argd, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1

        self.display = self.recv("callback")

        # in Drawing
        self.drawBG()
        self.blitToSurface()

        # in MouseEventHandling
        self.registerMouseListeners()

        done = False
        while not done:
            done = self.handleShutdown()  # in ShutdownHandling
            self.handleMouseEvents()  # in MouseEventHandling
            self.pause()
            yield 1
Beispiel #7
0
 def requestDisplay(self, **argd):
     # Create a Pygame display surface linked to local mailboxes
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "toDisplay"), displayservice)
     self.send(argd, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #8
0
 def requestDisplay(self, **argd):
     # Create a Pygame display surface linked to local mailboxes
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"toDisplay"), displayservice)
     self.send(argd, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #9
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "toDisplay"), displayservice)
     #argd["transparency"] = self.bgcolour # This causes problems when using OpenGL or a black background. Needs work TODO FIXME
     argd["transparency"] = (255, 255, 180)
     self.send(argd, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #10
0
 def requestDisplay(self, size=(400,300), fullscreen=0):
    displayservice = PygameDisplay.getDisplayService()
    self.link((self,"signal"), displayservice)
    self.send({ "DISPLAYREQUEST" : True,
                "callback" : (self,"control"),
                "size": size,
                "fullscreen" : fullscreen,
                "scaling" : 1.0},
                "signal")
Beispiel #11
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")
             
      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.drawBG()
      self.blitToSurface()
      
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEMOTION,
                  "surface" : self.display},
                  "display_signal")

      done = False
      while not done:
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True
         
         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if  event.button == 1:
                        self.drawing = True
                    elif event.button == 3:
                        self.oldpos = None
                        self.drawBG()
                        self.blitToSurface()

                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    self.drawing = False
                    self.oldpos = None
                elif event.type == pygame.MOUSEMOTION:
#                   print "BUTTON", event.button
                    if self.drawing and self.innerRect.collidepoint(*event.pos):
                        if self.oldpos == None:
                            self.oldpos = event.pos
                        else:
                            pygame.draw.line(self.display, (0,0,0), self.oldpos, event.pos, 3)
                            self.oldpos = event.pos
                        self.blitToSurface()
         self.pause()
         yield 1
Beispiel #12
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"toDisplay"), displayservice)
     #argd["transparency"] = self.bgcolour
     self.send(argd, "toDisplay")
     self.send(argd, "toApp") # MODIFICATION
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #13
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "toDisplay"), displayservice)
     #argd["transparency"] = self.bgcolour
     self.send(argd, "toDisplay")
     self.send(argd, "toApp")  # MODIFICATION
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #14
0
 def requestDisplay(self, **argd):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"toDisplay"), displayservice)
     #argd["transparency"] = self.bgcolour # This causes problems when using OpenGL or a black background. Needs work TODO FIXME
     argd["transparency"] = (255,255,180)
     self.send(argd, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #15
0
    def requestDisplay(self, **argd):
        displayRequest = dict(argd)
        if self.displayExtra:
            displayRequest.update(self.displayExtra)
        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"toDisplay"), displayservice)
#        self.send(argd, "toDisplay")
        self.send(displayRequest, "toDisplay")
        for _ in self.waitBox("fromDisplay"):
            yield 1
        self.surface = self.recv("fromDisplay")
Beispiel #16
0
 def requestDisplay(self, **argd):
     displayRequest = dict(argd)
     if self.displayExtra:
         displayRequest.update(self.displayExtra)
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "toDisplay"), displayservice)
     #        self.send(argd, "toDisplay")
     self.send(displayRequest, "toDisplay")
     for _ in self.waitBox("fromDisplay"):
         yield 1
     self.surface = self.recv("fromDisplay")
Beispiel #17
0
 def requestDisplay(self, size=(400, 300), fullscreen=0):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "signal"), displayservice)
     self.send(
         {
             "DISPLAYREQUEST": True,
             "callback": (self, "control"),
             "size": size,
             "fullscreen": fullscreen,
             "scaling": 1.0
         }, "signal")
Beispiel #18
0
   def requestDisplay(self, **argd):
      """\
      Generator. Gets a display surface from the PygameDisplay service.

      Makes the request, then yields 1 until a display surface is returned.
      """
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"signal"), displayservice)
      self.send(argd, "signal")
      for _ in self.waitBox("control"): yield 1
      display = self.recv("control")
      self.display = display
Beispiel #19
0
    def requestDisplay(self, **argd):
        """\
      Generator. Gets a display surface from the PygameDisplay service.

      Makes the request, then yields 1 until a display surface is returned.
      """
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "signal"), displayservice)
        self.send(argd, "signal")
        for _ in self.waitBox("control"):
            yield 1
        display = self.recv("control")
        self.display = display
Beispiel #20
0
        self.send("Backward", "infomover_commands")
        self.send("Play", "infomover_commands")


if __name__ == "__main__":
    from Kamaelia.Chassis.Graphline import Graphline
    from Kamaelia.Util.Console import ConsoleReader
    from Kamaelia.UI.PygameDisplay import PygameDisplay
    from Kamaelia.Community.THF.Kamaelia.UI.OpenGL.OpenGLDisplay import OpenGLDisplay
    from Kamaelia.Community.RJL.Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
    from Kamaelia.Community.RJL.Kamaelia.Protocol.Torrent.TorrentPatron import TorrentPatron

    ogl_display = OpenGLDisplay(limit_fps=100).activate()
    OpenGLDisplay.setDisplayService(ogl_display)
    # override pygame display service
    PygameDisplay.setDisplayService(ogl_display)

    Graphline(reader=ConsoleReader(prompt="Enter torrent location:", eol=""),
              httpclient=SimpleHTTPClient(),
              gui=TorrentOpenGLGUI(),
              backend=TorrentPatron(),
              linkages={
                  ("gui", "outbox"): ("backend", "inbox"),
                  ("reader", "outbox"): ("gui", "torrent_url"),
                  ("gui", "fetcher"): ("httpclient", "inbox"),
                  ("httpclient", "outbox"): ("gui", "torrent_file"),
                  ("backend", "outbox"): ("gui", "inbox")
              }).run()

# Licensed to the BBC under a Contributor Agreement: THF
Beispiel #21
0
 def overridePygameDisplay():
     PygameDisplay.setDisplayService(Display3D.getDisplayService()[0])
Beispiel #22
0
        self.send("Backward", "infomover_commands")
        self.send("Play", "infomover_commands")
        
        
if __name__ == "__main__":
    from Kamaelia.Chassis.Graphline import Graphline
    from Kamaelia.Util.Console import ConsoleReader
    from Kamaelia.UI.PygameDisplay import PygameDisplay
    from Kamaelia.UI.OpenGL.OpenGLDisplay import OpenGLDisplay
    from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
    from Kamaelia.Protocol.Torrent.TorrentPatron import TorrentPatron
    
    ogl_display = OpenGLDisplay(limit_fps=100).activate()  
    OpenGLDisplay.setDisplayService(ogl_display)
    # override pygame display service
    PygameDisplay.setDisplayService(ogl_display)
    
    Graphline(
        reader = ConsoleReader(prompt="Enter torrent location:", eol=""),
        httpclient = SimpleHTTPClient(),
        gui = TorrentOpenGLGUI(),
        backend = TorrentPatron(),
        linkages = {
            ("gui", "outbox") : ("backend", "inbox"),
            ("reader", "outbox") : ("gui", "torrent_url"),
            ("gui", "fetcher") : ("httpclient", "inbox"),
            ("httpclient", "outbox") : ("gui", "torrent_file"),
            ("backend", "outbox"): ("gui", "inbox")
        }
    ).run()
Beispiel #23
0
    def main(self):
        # START SHARD : Setup Display =================================================

        # START SHARD : Get Display Surface -------------------------------------------
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")
        # END SHARD : Get Display Surface ---------------------------------------------

        # START SHARD : drawBG ========================================================
        #    Dependency: self.drawBG defined
        self.drawBG()
        # END SHARD : drawBG ========================================================
        # START SHARD : Blit Display --------------------------------------------------
        #    Dependency: self.blitToSurface defined
        self.blitToSurface()
        # END SHARD : Blit Display ----------------------------------------------------

        # START SHARD : Set Event Options ---------------------------------------------
        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEMOTION,
                "surface": self.display
            }, "display_signal")
        # END SHARD : Set Event Options -----------------------------------------------
        # END SHARD : Setup Display ===================================================

        # START SHARD : mainloop ======================================================
        done = False
        while not done:
            # START SHARD : Handle Shutdown --------------------------------------------
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, Axon.Ipc.producerFinished) or \
                   isinstance(cmsg, Axon.Ipc.shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    done = True
            # END SHARD : Handle Shutdown ----------------------------------------------

            while self.dataReady("inbox"):
                # START SHARD : Loop over Pygame Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                for event in self.recv("inbox"):
                    # START SHARD : Handle Event ========================================
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        # START SHARD : Mouse dn button 1 -------------------------------
                        if event.button == 1:
                            self.drawing = True
                        elif event.button == 3:
                            self.oldpos = None
                            # START SHARD : drawBG ......................................
                            #    Dependency: self.drawBG defined
                            self.drawBG()
                            # END SHARD : drawBG ........................................
                            # START SHARD : Blit Display ................................
                            #    Dependency: self.blitToSurface defined
                            self.blitToSurface()
                            # END SHARD : Blit Display ..................................

                        # END SHARD : Mouse dn button 1 ---------------------------------
                    elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                        # START SHARD : Mouse up button 1 -------------------------------
                        self.drawing = False
                        self.oldpos = None
                        # END SHARD : Mouse up button 1 ---------------------------------
                    elif event.type == pygame.MOUSEMOTION:
                        # START SHARD : Mouse move --------------------------------------
                        if self.drawing and self.innerRect.collidepoint(
                                *event.pos):
                            if self.oldpos == None:
                                self.oldpos = event.pos
                            else:
                                pygame.draw.line(self.display, (0, 0, 0),
                                                 self.oldpos, event.pos, 3)
                                self.oldpos = event.pos
                            # START SHARD : Blit Display ................................
                            #    Dependency: self.blitToSurface defined
                            self.blitToSurface()
                            # END SHARD : Blit Display ..................................
                        # END SHARD : Mouse move ----------------------------------------
                    # END SHARD : Handle Event ==========================================
                # END SHARD : Loop over Pygame Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            self.pause()
            yield 1
Beispiel #24
0
 def main(self):
     # START SHARD: RequestDisplay --------------------------------------------------
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"display_signal"), displayservice)
     self.send( self.disprequest, "display_signal")
     # END SHARD: RequestDisplay ----------------------------------------------------
     
     # START SHARD: wait ------------------------------------------------------------
     for _ in self.waitBox("callback"):
         # START SHARD: wait.shard3 -----------------------------------------------------
         yield 1
         # END SHARD: wait.shard3 -------------------------------------------------------
         
     # END SHARD: wait --------------------------------------------------------------
     
     # START SHARD: GrabDisplay -----------------------------------------------------
     self.display = self.recv("callback")
     # END SHARD: GrabDisplay -------------------------------------------------------
     
     # START SHARD: main.shard5 -----------------------------------------------------
     self.drawBG()
     self.blitToSurface()
     # END SHARD: main.shard5 -------------------------------------------------------
     
     # START SHARD: SetEventOptions -------------------------------------------------
     self.addListenEvent("MOUSEBUTTONDOWN")
     self.addListenEvent("MOUSEBUTTONUP")
     self.addListenEvent("MOUSEMOTION")
     # END SHARD: SetEventOptions ---------------------------------------------------
     
     # START SHARD: main.shard6 -----------------------------------------------------
     done = False
     # END SHARD: main.shard6 -------------------------------------------------------
     
     # START SHARD: mainLoop --------------------------------------------------------
     while not done:
         # START SHARD: ShutdownHandler -------------------------------------------------
         while self.dataReady("control"):
             cmsg = self.recv("control")
             if isinstance(cmsg, Axon.Ipc.producerFinished) or \
                isinstance(cmsg, Axon.Ipc.shutdownMicroprocess):
                 self.send(cmsg, "signal")
                 done = True
         # END SHARD: ShutdownHandler ---------------------------------------------------
         
         # START SHARD: LoopOverPygameEvents --------------------------------------------
         while self.dataReady("inbox"):
             # START SHARD: eventhandler ----------------------------------------------------
             for event in self.recv("inbox"):
                 # START SHARD: shard0 ----------------------------------------------------------
                 # START SHARD: shard0.shard1 ---------------------------------------------------
                 if event.type == pygame.MOUSEBUTTONDOWN:
                     # START SHARD: MOUSEBUTTONDOWN_handler -----------------------------------------
                     #print 'down'
                     if  event.button == 1:
                         self.drawing = True
                     elif event.button == 3:
                         self.oldpos = None
                         self.drawBG()
                         self.blitToSurface()
                     # END SHARD: MOUSEBUTTONDOWN_handler -------------------------------------------
                     
                 elif event.type == pygame.MOUSEBUTTONUP:
                     # START SHARD: MOUSEBUTTONUP_handler -------------------------------------------
                     #print 'up'
                     if event.button == 1:
                         self.drawing = False
                         self.oldpos = None
                     # END SHARD: MOUSEBUTTONUP_handler ---------------------------------------------
                     
                 elif event.type == pygame.MOUSEMOTION:
                     # START SHARD: MOUSEMOTION_handler ---------------------------------------------
                     #print 'move'
                     if self.drawing and self.innerRect.collidepoint(*event.pos):
                         if self.oldpos == None:
                             self.oldpos = event.pos
                         else:
                             pygame.draw.line(self.display, (0,0,0), self.oldpos, event.pos, 3)
                             self.oldpos = event.pos
                         self.blitToSurface()
                     # END SHARD: MOUSEMOTION_handler -----------------------------------------------
                     
                 # END SHARD: shard0.shard1 -----------------------------------------------------
                 
                 # END SHARD: shard0 ------------------------------------------------------------
                 
             # END SHARD: eventhandler ------------------------------------------------------
             
         # END SHARD: LoopOverPygameEvents ----------------------------------------------
         
         # START SHARD: mainLoop.shard4 -------------------------------------------------
         self.pause()
         yield 1
Beispiel #25
0
   def main(self):
      # START SHARD : Setup Display =================================================

      # START SHARD : Get Display Surface -------------------------------------------
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest, "display_signal")
             
      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      # END SHARD : Get Display Surface ---------------------------------------------

      # START SHARD : drawBG ========================================================
      #    Dependency: self.drawBG defined
      self.drawBG()
      # END SHARD : drawBG ========================================================
      # START SHARD : Blit Display --------------------------------------------------
      #    Dependency: self.blitToSurface defined
      self.blitToSurface()
      # END SHARD : Blit Display ----------------------------------------------------
      
      # START SHARD : Set Event Options ---------------------------------------------
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEMOTION,
                  "surface" : self.display},
                  "display_signal")
      # END SHARD : Set Event Options -----------------------------------------------
      # END SHARD : Setup Display ===================================================

      # START SHARD : mainloop ======================================================
      done = False
      while not done:
         # START SHARD : Handle Shutdown --------------------------------------------
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, Axon.Ipc.producerFinished) or \
               isinstance(cmsg, Axon.Ipc.shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True
         # END SHARD : Handle Shutdown ----------------------------------------------
         
         while self.dataReady("inbox"):
            # START SHARD : Loop over Pygame Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            for event in self.recv("inbox"):
                # START SHARD : Handle Event ========================================
                if event.type == pygame.MOUSEBUTTONDOWN:
                    # START SHARD : Mouse dn button 1 -------------------------------
                    if  event.button == 1:
                        self.drawing = True
                    elif event.button == 3:
                        self.oldpos = None
                        # START SHARD : drawBG ......................................
                        #    Dependency: self.drawBG defined
                        self.drawBG()
                        # END SHARD : drawBG ........................................
                        # START SHARD : Blit Display ................................
                        #    Dependency: self.blitToSurface defined
                        self.blitToSurface()
                        # END SHARD : Blit Display ..................................

                    # END SHARD : Mouse dn button 1 ---------------------------------
                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    # START SHARD : Mouse up button 1 -------------------------------
                    self.drawing = False
                    self.oldpos = None
                    # END SHARD : Mouse up button 1 ---------------------------------
                elif event.type == pygame.MOUSEMOTION:
                    # START SHARD : Mouse move --------------------------------------
                    if self.drawing and self.innerRect.collidepoint(*event.pos):
                        if self.oldpos == None:
                            self.oldpos = event.pos
                        else:
                            pygame.draw.line(self.display, (0,0,0), self.oldpos, event.pos, 3)
                            self.oldpos = event.pos
                        # START SHARD : Blit Display ................................
                        #    Dependency: self.blitToSurface defined
                        self.blitToSurface()
                        # END SHARD : Blit Display ..................................
                    # END SHARD : Mouse move ----------------------------------------
                # END SHARD : Handle Event ==========================================
            # END SHARD : Loop over Pygame Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         self.pause()
         yield 1
Beispiel #26
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")
             
      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.drawBG()
      self.blitToSurface()
      
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEMOTION,
                  "surface" : self.display},
                  "display_signal")
		  
      self.send({ "ADDLISTENEVENT" : pygame.KEYDOWN,
		  "surface" : self.display},
		  "display_signal")


      done = False
      while not done:
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True
         while self.dataReady("drawn"):
                print "drawn"
                for x in self.recv("drawn"):
                    if x == "c":
                        self.oldpos = None
                        self.drawBG()
                        self.blitToSurface()
         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
  #              print event
                if isinstance(event, tuple):
#                    print "here"
                    if event[0] == 'circle':
                        pygame.draw.circle(self.display, (255,0,0), event[1], event[2], 0)
                        self.blitToSurface()
                    if event[0] == 'line':
                        pygame.draw.line(self.display, (0,0,0), event[1], event[2], 3)
                        self.blitToSurface()
                    break
                if event == "clear":
                    print "YAY!"
                    self.oldpos = None
                    self.drawBG()
                    self.blitToSurface()
                    break
                if event.type == pygame.MOUSEBUTTONDOWN:
     #               self.send(event, "outbox")
                    if self.shape == "circle":
                        if event.button == 1:
                            self.oldpos = event.pos
                #            print event.pos
                            self.drawing = True
                     #       self.send(event, "outbox")
                    if self.shape == "line":
                        if event.button == 1:
                            self.drawing = True
                    if event.button == 3:
                        self.oldpos = None
                        self.drawBG()
                        self.blitToSurface()
                        self.send(("clear",), "outbox")
                        print "I'm here!"
                elif event.type == (pygame.KEYDOWN):
                    if event.key == pygame.K_c:
                       self.shape = "circle"
                    elif event.key == pygame.K_l:
                       self.shape = "line"


                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    if self.shape == "circle":
                        rad = math.sqrt(((event.pos[0]-self.oldpos[0])**2)+((event.pos[1]-self.oldpos[1])**2))
          #              print event.pos
          #              print rad
                        pygame.draw.circle(self.display, (0,0,0), self.oldpos, rad, 0)
                        circle = ("circle", self.oldpos, rad)
                        self.send((circle,), "outbox")
                        self.blitToSurface()
                    self.drawing = False
                    self.oldpos = None
                elif event.type == pygame.MOUSEMOTION:
#                   print "BUTTON", event.button
                    if self.shape == "line":
                        if self.drawing and self.innerRect.collidepoint(*event.pos):
                              if self.oldpos == None:
                                 self.oldpos = event.pos
                              else:
                                 pygame.draw.line(self.display, (0,0,0), self.oldpos, event.pos, 3)
                                 line = ("line", self.oldpos, event.pos)
                                 self.send((line,), "outbox")
                                 self.oldpos = event.pos
                              self.blitToSurface()
         self.pause()
         yield 1
Beispiel #27
0
            for i in range(0,4):
                pygame.draw.arc(surface, (255,255,255), pygame.Rect(x-self.arcradius, y-self.arcradius, self.arcradius2, self.arcradius2), startangle, stopangle, self.arcwidth)
                startangle = startangle + 1.57
                stopangle  = stopangle  + 1.57
        yield 4
        yield oldrenderer.next()                                                    

particleTypes = { "component" : PComponent2,
                    "inbox"     : PPostbox.Inbox,
                    "outbox"    : PPostbox.Outbox
                }
                
from Kamaelia.UI.PygameDisplay import PygameDisplay

pgd = PygameDisplay(width=800,height=600).activate()
PygameDisplay.setDisplayService(pgd)

TVC = TopologyViewerComponent(position=(0,48), laws = AxonLaws(), particleTypes=particleTypes)

SANDBOX = Sandbox()

Graphline(
    CONSOLEINPUT = pipeline(
                     ConsoleReader(">>> "),
                     chunks_to_lines(),
                     lines_to_tokenlists(),
                   ),
    DEBUG = ConsoleEchoer(forwarder=True),
    TVC = TVC,
    INTROSPECTOR = pipeline(Introspector(SANDBOX), chunks_to_lines(), lines_to_tokenlists()),
    SANDBOX = SANDBOX,
Beispiel #28
0
                    stopangle, self.arcwidth)
                startangle = startangle + 1.57
                stopangle = stopangle + 1.57
        yield 4
        yield oldrenderer.next()


particleTypes = {
    "component": PComponent2,
    "inbox": PPostbox.Inbox,
    "outbox": PPostbox.Outbox
}

from Kamaelia.UI.PygameDisplay import PygameDisplay

pgd = PygameDisplay(width=800, height=600).activate()
PygameDisplay.setDisplayService(pgd)

TVC = TopologyViewerComponent(position=(0, 48),
                              laws=AxonLaws(),
                              particleTypes=particleTypes)

SANDBOX = Sandbox()

Graphline(CONSOLEINPUT=pipeline(
    ConsoleReader(">>> "),
    chunks_to_lines(),
    lines_to_tokenlists(),
),
          DEBUG=ConsoleEchoer(forwarder=True),
          TVC=TVC,
Beispiel #29
0
#
# HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK
#


try:
   path = sys.argv[1]
except IndexError:
   path = "Slides"

extns = [ ".png",".gif", ".jpg" ]
files = os.listdir(path)
files = [ os.path.join(path,fname) for fname in files if fname[-4:] in extns ]
files.sort()

pygamedisplay = PygameDisplay(width=1024, height=768, fullscreen=1)
pygamedisplay.activate()
PygameDisplay.setDisplayService(pygamedisplay)

Graphline(
     EXIT = ExceptionRaiser("FORCED SYSTEM QUIT"),
     MOUSE = Multiclick(caption="", 
                        position=(0,0), 
                        transparent=True,
                        msgs = [ "", "NEXT", "FIRST", "PREV", "PREV","NEXT" ],
                        size=(1024,768)),
     KEYS = KeyEvent(outboxes = { "slidecontrol" : "Normal place for message",
                                  "shutdown" : "Place to send some shutdown messages",
                                  "trace" : "Place for trace messages to go",
                                },
                     key_events = {112: ("PREV", "slidecontrol"), 
Beispiel #30
0
 def overridePygameDisplay():
     PygameDisplay.setDisplayService(Display3D.getDisplayService()[0])
Beispiel #31
0
    def main(self):
        # START SHARD: RequestDisplay --------------------------------------------------
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)
        self.send(self.disprequest, "display_signal")
        # END SHARD: RequestDisplay ----------------------------------------------------

        # START SHARD: wait ------------------------------------------------------------
        for _ in self.waitBox("callback"):
            # START SHARD: wait.shard3 -----------------------------------------------------
            yield 1
            # END SHARD: wait.shard3 -------------------------------------------------------

        # END SHARD: wait --------------------------------------------------------------

        # START SHARD: GrabDisplay -----------------------------------------------------
        self.display = self.recv("callback")
        # END SHARD: GrabDisplay -------------------------------------------------------

        # START SHARD: main.shard5 -----------------------------------------------------
        self.drawBG()
        self.blitToSurface()
        # END SHARD: main.shard5 -------------------------------------------------------

        # START SHARD: SetEventOptions -------------------------------------------------
        self.addListenEvent("MOUSEBUTTONDOWN")
        self.addListenEvent("MOUSEBUTTONUP")
        self.addListenEvent("MOUSEMOTION")
        # END SHARD: SetEventOptions ---------------------------------------------------

        # START SHARD: main.shard6 -----------------------------------------------------
        done = False
        # END SHARD: main.shard6 -------------------------------------------------------

        # START SHARD: mainLoop --------------------------------------------------------
        while not done:
            # START SHARD: ShutdownHandler -------------------------------------------------
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, Axon.Ipc.producerFinished) or \
                   isinstance(cmsg, Axon.Ipc.shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    done = True
            # END SHARD: ShutdownHandler ---------------------------------------------------

            # START SHARD: LoopOverPygameEvents --------------------------------------------
            while self.dataReady("inbox"):
                # START SHARD: eventhandler ----------------------------------------------------
                for event in self.recv("inbox"):
                    # START SHARD: shard0 ----------------------------------------------------------
                    # START SHARD: shard0.shard1 ---------------------------------------------------
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        # START SHARD: MOUSEBUTTONDOWN_handler -----------------------------------------
                        #print 'down'
                        if event.button == 1:
                            self.drawing = True
                        elif event.button == 3:
                            self.oldpos = None
                            self.drawBG()
                            self.blitToSurface()
                        # END SHARD: MOUSEBUTTONDOWN_handler -------------------------------------------

                    elif event.type == pygame.MOUSEBUTTONUP:
                        # START SHARD: MOUSEBUTTONUP_handler -------------------------------------------
                        #print 'up'
                        if event.button == 1:
                            self.drawing = False
                            self.oldpos = None
                        # END SHARD: MOUSEBUTTONUP_handler ---------------------------------------------

                    elif event.type == pygame.MOUSEMOTION:
                        # START SHARD: MOUSEMOTION_handler ---------------------------------------------
                        #print 'move'
                        if self.drawing and self.innerRect.collidepoint(
                                *event.pos):
                            if self.oldpos == None:
                                self.oldpos = event.pos
                            else:
                                pygame.draw.line(self.display, (0, 0, 0),
                                                 self.oldpos, event.pos, 3)
                                self.oldpos = event.pos
                            self.blitToSurface()
                        # END SHARD: MOUSEMOTION_handler -----------------------------------------------

                    # END SHARD: shard0.shard1 -----------------------------------------------------

                    # END SHARD: shard0 ------------------------------------------------------------

                # END SHARD: eventhandler ------------------------------------------------------

            # END SHARD: LoopOverPygameEvents ----------------------------------------------

            # START SHARD: mainLoop.shard4 -------------------------------------------------
            self.pause()
            yield 1