示例#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
示例#2
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")
示例#3
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
示例#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")
示例#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")
示例#6
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
示例#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")
示例#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")
示例#9
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")
示例#10
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")
示例#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
示例#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")
示例#13
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")
示例#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")
示例#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")
示例#16
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")
示例#17
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")
示例#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
示例#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
示例#20
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
示例#21
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
示例#22
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
示例#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
示例#24
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