Пример #1
0
    def handleNewChild(self):
        if self.dataReady("next"):
            arg = self.recv("next")

            # purge old child and any control messages that may have come from the old child
            while self.dataReady("_control"):
                self.recv("_control")

            self.unplugChildren()

            # create new child
            newChild = self.factory(arg)
            self.addChildren(newChild)

            # set flag for handleFinishedChild's sake
            self.childDone = False

            # wire it in
            self.link((self, "inbox"), (newChild, "inbox"), passthrough=1)
            self.link((self, "_signal"), (newChild, "control"))

            self.link((newChild, "outbox"), (self, "outbox"), passthrough=2)
            self.link((newChild, "signal"), (self, "_control"))

            # return it to be yielded
            return newComponent(*(self.children))
        return 1
Пример #2
0
    def handleNewChild(self):
        if self.dataReady("next"):
            arg = self.recv("next")

            # purge old child and any control messages that may have come from the old child
            while self.dataReady("_control"):
                self.recv("_control")

            self.unplugChildren()

            # create new child
            newChild = self.factory(arg)
            self.addChildren( newChild )
            
            # set flag for handleFinishedChild's sake
            self.childDone = False

            # wire it in
            self.link( (self,     "inbox"),   (newChild, "inbox"),  passthrough=1 )
            self.link( (self,     "_signal"), (newChild, "control")  )
            
            self.link( (newChild, "outbox"),  (self,     "outbox"), passthrough=2 )
            self.link( (newChild, "signal"),  (self,     "_control") )
            
            # return it to be yielded
            return newComponent(*(self.children))
        return 1
Пример #3
0
 def runClient(self, sock=None):
     # The various numbers yielded here indicate progress through the function, and
     # nothing else specific.
     try:
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         yield 0.3
         # Print( "GOT SOCK" )
         self.sock = sock  # We need this for shutdown later
         try:
             sock.setblocking(0)
             yield 0.6
             # Print( "GOT A NON BLOCK" )
             try:
                 tryUntil = time.time() + self.connect_timeout
                 # Print( "GOT A ODD SOCK" )
                 while not self.safeConnect(sock, (self.host, self.port)):
                     if self.shutdown():
                         return
                     if time.time() >= tryUntil:
                         self.howDied = "timeout"
                         raise Finality
                     yield 1
                 # Print( "CONNECTED" )
                 yield newComponent(*self.setupCSA(sock))
                 while self.waitCSAClose():
                     self.pause()
                     yield 2
                 raise Finality
             except Exception:
                 x = sys.exc_info()[1]
                 # Print(  "SHUTTING SOCK",x )
                 result = sock.shutdown(2)
                 yield 3
                 raise x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
                 # The logical place to send the error is to the signal outbox
         except Exception:
             x = sys.exc_info()[1]
             # Print(  "CLOSING SOCK",x )
             sock.close()
             yield 4, x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
             raise x
     except Finality:
         # Print( "LOOKING GOOD SOCK" )
         yield 5
     except socket.error:
         e = sys.exc_info()[1]
         # We now do the flipside of setupCSA, whether we had an error or not
         # A safe error relates to a disconnected server, and unsafe error is generally
         # bad. However either way, it's gone, let's let the person using this
         # component know, shutdown everything, and get outta here.
         #
         # FIXME: Set self.howDied here as well
         #
         # Print(  "SMELLY SOCK", e )
         pass
     self.send(producerFinished(self, self.howDied), "signal")
Пример #4
0
 def runClient(self, sock=None):
     # The various numbers yielded here indicate progress through the function, and
     # nothing else specific.
     try:
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         yield 0.3
         # Print( "GOT SOCK" )
         self.sock = sock  # We need this for shutdown later
         try:
             sock.setblocking(0)
             yield 0.6
             # Print( "GOT A NON BLOCK" )
             try:
                 tryUntil = time.time() + self.connect_timeout
                 # Print( "GOT A ODD SOCK" )
                 while not self.safeConnect(sock, (self.host, self.port)):
                     if self.shutdown():
                         return
                     if time.time() >= tryUntil:
                         self.howDied = "timeout"
                         raise Finality
                     yield 1
                 # Print( "CONNECTED" )
                 yield newComponent(*self.setupCSA(sock))
                 while self.waitCSAClose():
                     self.pause()
                     yield 2
                 raise Finality
             except Exception:
                 x = sys.exc_info()[1]
                 # Print(  "SHUTTING SOCK",x )
                 result = sock.shutdown(2)
                 yield 3
                 raise x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
                 # The logical place to send the error is to the signal outbox
         except Exception:
             x = sys.exc_info()[1]
             # Print(  "CLOSING SOCK",x )
             sock.close()
             yield 4, x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
             raise x
     except Finality:
         # Print( "LOOKING GOOD SOCK" )
         yield 5
     except socket.error:
         e = sys.exc_info()[1]
         # We now do the flipside of setupCSA, whether we had an error or not
         # A safe error relates to a disconnected server, and unsafe error is generally
         # bad. However either way, it's gone, let's let the person using this
         # component know, shutdown everything, and get outta here.
         #
         # FIXME: Set self.howDied here as well
         #
         # Print(  "SMELLY SOCK", e )
         pass
     self.send(producerFinished(self, self.howDied), "signal")
Пример #5
0
   def initialiseComponent(self):
      """\
      Initialises component. Sets up a ReadFileAdapter to read the result of
      running 'fortune'.
      """
      myDataSource = ReadFileAdaptor(command="fortune -a",readmode="bitrate", bitrate=320, chunkrate=40)
      assert self.debugger.note("FortuneCookieProtocol.main", 1, self.name, "File Opened...")

      self.link(source=(myDataSource,"outbox"), sink=(self,"outbox"), passthrough=2)
      self.link((myDataSource,"signal"), sink=(self,"control"))
      assert self.debugger.note("FortuneCookieProtocol.main", 1, self.name, "Linked in")

      self.addChildren(myDataSource)
      assert self.debugger.note("FortuneCookieProtocol.main", 1, self.name, "Added Child", myDataSource)
      return newComponent(  myDataSource  )
Пример #6
0
   def initialiseComponent(self):
      """\
      Initialises component. Sets up a ReadFileAdapter to read in the contents
      of an audio file at 95.2kbit/s and wires it to fire the contents out
      """
      myDataSource = ReadFileAdaptor(command="./afortune.pl",
                              readmode="bitrate",
                              bitrate=95200, chunkrate=25)
      assert self.debugger.note("AudioCookieProtocol.initialiseComponent", 1, "Initialising AudioCookieProtocol protocol handler ", self.name)
      self.link(	source=(myDataSource,"outbox"),
               sink=(self,"outbox"),
               passthrough=2)
      self.addChildren(myDataSource)

      return newComponent(  myDataSource  )
Пример #7
0
 def initialiseComponent(self):
     """Finds the splitter and connects to it and passes the data through the
     SubtitleFilterComponent to produce the right output which is passed out
     of the outbox to be sent to the client.
     
     Note:  The Filtering should be moved to the input so that it only has to
     be done once.""" 
     cat = coordinatingassistanttracker.getcat()
     # Find the splitter.
     self.splitter,self.splitterbox = cat.retrieveService("thesource")
     self.link((self, "splittercontrol"),(self.splitter,self.splitterbox))
     # Why is the filter here?  It should be in the receiver so that it only
     # gets done only once instead of once/client.  DOHHH!
     self.filter = SubtitleFilterComponent()
     self.link((self.filter, "outbox"), (self, "outbox"),passthrough = 2)
     self.send(Kamaelia.Util.Splitter.addsink(self.filter, "inbox"),"splittercontrol")
     return newComponent(self.filter)
Пример #8
0
 def runClient(self, sock=None):
     # The various numbers yielded here indicate progress through the function, and
     # nothing else specific.
     try:
         sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                              socket.IPPROTO_UDP)
         yield 0.3
         self.sock = sock  # We need this for shutdown later
         try:
             sock.setblocking(0)
             yield 0.6
             try:
                 while not self.safeConnect(sock):
                     if self.shutdown():
                         return
                     yield 1
                 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL,
                                 255)
                 status = sock.setsockopt(
                     socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP,
                     socket.inet_aton(self.remote[0]) +
                     socket.inet_aton("0.0.0.0"))
                 yield newComponent(*self.setupCSA(sock))
                 while self.waitCSAClose():
                     self.pause()
                     yield 2
                 raise Finality
             except Exception, x:
                 result = sock.shutdown(2)
                 yield 3
                 raise x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
                 # The logical place to send the error is to the signal outbox
         except Exception, x:
             sock.close()
             yield 4, x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
             raise x
     except Finality:
         yield 5
     except socket.error, e:
         # We now do the flipside of setupCSA, whether we had an error or not
         # A safe error relates to a disconnected server, and unsafe error is generally
         # bad. However either way, it's gone, let's let the person using this
         # component know, shutdown everything, and get outta here.
         #
         pass
         self.send(shutdownMicroprocess(self), "signal")
Пример #9
0
    def main(self):
        """Main loop."""
        self.link((self, "control"), (self.splitter, "control"), passthrough=1)
        self.link((self.splitter, "signal"), (self, "signal"), passthrough=2)

        yield newComponent(self.splitter)
        self.addChildren(self.splitter)
        self.splitter = None
        # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
        # FIXME: then this while loop here would be irrelevent, which would be cool.
        while not self.childrenDone():
            self.pause()
            yield 1

        cat = CAT.getcat()
        cat.deRegisterService("Backplane_I_" + self.name)
        cat.deRegisterService("Backplane_O_" + self.name)
Пример #10
0
 def main(self):
     """Main loop."""
     self.link((self,"control"),(self.splitter,"control"), passthrough=1)
     self.link((self.splitter,"signal"),(self,"signal"), passthrough=2)
     
     yield newComponent(self.splitter)
     self.addChildren(self.splitter)
     self.splitter = None
     # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
     # FIXME: then this while loop here would be irrelevent, which would be cool.
     while not self.childrenDone():
         self.pause()
         yield 1
         
     cat = CAT.getcat()
     cat.deRegisterService("Backplane_I_"+self.name)
     cat.deRegisterService("Backplane_O_"+self.name)
Пример #11
0
    def enter(self, actorName):
        self.send("ENTER: "+actorName+"\n", "outbox")
        if actorName not in self.actors:
            actor = self.makeActor(actorName)

            outboxes = dict()
            linkages = dict()

            for (o,i) in [("outbox","inbox"),("signal","control"),("topic","topic")]:
                outboxes[o] = self.addOutbox(o)
                linkages[o] = self.link( (self, outboxes[o]), (actor,i) )

            self.actors[actorName] = (actor, outboxes, linkages)
            
            self.addChildren(actor)
            return newComponent(actor)
        else:
            return 1
Пример #12
0
    def initialiseComponent(self):
        """\
      Initialises component. Sets up a ReadFileAdapter to read in the contents
      of an audio file at 95.2kbit/s and wires it to fire the contents out
      """
        myDataSource = ReadFileAdaptor(command="./afortune.pl",
                                       readmode="bitrate",
                                       bitrate=95200,
                                       chunkrate=25)
        assert self.debugger.note(
            "AudioCookieProtocol.initialiseComponent", 1,
            "Initialising AudioCookieProtocol protocol handler ", self.name)
        self.link(source=(myDataSource, "outbox"),
                  sink=(self, "outbox"),
                  passthrough=2)
        self.addChildren(myDataSource)

        return newComponent(myDataSource)
Пример #13
0
    def enter(self, actorName):
        self.send("ENTER: " + actorName + "\n", "outbox")
        if actorName not in self.actors:
            actor = self.makeActor(actorName)

            outboxes = dict()
            linkages = dict()

            for (o, i) in [("outbox", "inbox"), ("signal", "control"),
                           ("topic", "topic")]:
                outboxes[o] = self.addOutbox(o)
                linkages[o] = self.link((self, outboxes[o]), (actor, i))

            self.actors[actorName] = (actor, outboxes, linkages)

            self.addChildren(actor)
            return newComponent(actor)
        else:
            return 1
Пример #14
0
 def main(self):
     """Main loop."""
     cat = CAT.getcat()
     splitter, configbox = cat.retrieveService("Backplane_O_" + self.source)
     p = PassThrough()
     plug = Plug(splitter, p)
     self.link((self, "control"), (plug, "control"), passthrough=1)
     self.link((plug, "outbox"), (self, "outbox"), passthrough=2)
     self.link((plug, "signal"), (self, "signal"), passthrough=2)
     self.addChildren(plug)
     yield newComponent(plug)
     # wait until all child component has terminated
     # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
     # FIXME: then this while loop here would be irrelevent, which would be cool.
     # FIXME: especially if we could exec in such a way that passthrough linkages
     # FIXME: still operated as you'd expect.
     while not self.childrenDone():
         self.pause()
         yield 1
Пример #15
0
 def main(self):
     """Main loop."""
     cat = CAT.getcat()
     splitter,configbox = cat.retrieveService("Backplane_O_"+self.source)
     p = PassThrough()
     plug = Plug(splitter, p)
     self.link( (self, "control"), (plug, "control"), passthrough=1)
     self.link( (plug,"outbox"), (self,"outbox"), passthrough=2)
     self.link( (plug,"signal"), (self,"signal"), passthrough=2)
     self.addChildren(plug)
     yield newComponent(plug)
     # wait until all child component has terminated
     # FIXME: If we had a way of simply getting this to "exec" a new component in our place,
     # FIXME: then this while loop here would be irrelevent, which would be cool.
     # FIXME: especially if we could exec in such a way that passthrough linkages
     # FIXME: still operated as you'd expect.
     while not self.childrenDone():
         self.pause()
         yield 1
Пример #16
0
 def runClient(self,sock=None):
    # The various numbers yielded here indicate progress through the function, and
    # nothing else specific.
    try:
       sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
       yield 0.3
       self.sock = sock # We need this for shutdown later
       try:
          sock.setblocking(0); yield 0.6
          try:
             while not self.safeConnect(sock):
                if self.shutdown():
                    return
                yield 1
             sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
             status = sock.setsockopt(socket.IPPROTO_IP,
                                      socket.IP_ADD_MEMBERSHIP,
                                      socket.inet_aton(self.remote[0]) + socket.inet_aton("0.0.0.0"))
             yield newComponent(*self.setupCSA(sock))
             while self.waitCSAClose():
                self.pause()
                yield 2
             raise Finality
          except Exception, x:
             result = sock.shutdown(2) ; yield 3
             raise x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
             # The logical place to send the error is to the signal outbox
       except Exception, x:
          sock.close() ;  yield 4,x # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
          raise x
    except Finality:
       yield 5
    except socket.error, e:
       # We now do the flipside of setupCSA, whether we had an error or not
       # A safe error relates to a disconnected server, and unsafe error is generally
       # bad. However either way, it's gone, let's let the person using this
       # component know, shutdown everything, and get outta here.
       #
       pass
       self.send(shutdownMicroprocess(self), "signal")
Пример #17
0
    def initialiseComponent(self):
        """\
      Initialises component. Sets up a ReadFileAdapter to read the result of
      running 'fortune'.
      """
        myDataSource = ReadFileAdaptor(command="fortune -a",
                                       readmode="bitrate",
                                       bitrate=320,
                                       chunkrate=40)
        assert self.debugger.note("FortuneCookieProtocol.main", 1, self.name,
                                  "File Opened...")

        self.link(source=(myDataSource, "outbox"),
                  sink=(self, "outbox"),
                  passthrough=2)
        self.link((myDataSource, "signal"), sink=(self, "control"))
        assert self.debugger.note("FortuneCookieProtocol.main", 1, self.name,
                                  "Linked in")

        self.addChildren(myDataSource)
        assert self.debugger.note("FortuneCookieProtocol.main", 1, self.name,
                                  "Added Child", myDataSource)
        return newComponent(myDataSource)
Пример #18
0
 def runClient(self,sock=None):
    # The various numbers yielded here indicate progress through the function, and
    # nothing else specific.
    try:
       sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); yield 0.3
       self.sock = sock # We need this for shutdown later
       try:
          sock.setblocking(0); yield 0.6
          try:
             while not self.safeConnect(sock,(self.host, self.port)):
                if self.shutdown():
                    return
                yield 1
             yield newComponent(*self.setupCSA(sock))
             while self.waitCSAClose():
                self.pause()
                yield 2
             raise Finality
          except Exception, x:
             result = sock.shutdown(2) ; yield 3
             raise x  # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
             # The logical place to send the error is to the signal outbox
       except Exception, x:
          sock.close() ;  yield 4,x # XXXX If X is not finality, an error message needs to get sent _somewhere_ else
          raise x
    except Finality:
       yield 5
    except socket.error, e:
       # We now do the flipside of setupCSA, whether we had an error or not
       # A safe error relates to a disconnected server, and unsafe error is generally
       # bad. However either way, it's gone, let's let the person using this
       # component know, shutdown everything, and get outta here.
       #
       # FIXME: Set self.howDied here as well
       #
       pass
Пример #19
0
   def mainBody(self):
      if self.demo_mode == True:
         if self.displaySet == False:                           
            try: self.start_button = pygame.image.load("UI_Pics/Start button.jpg")             
            except: raise "ErrorLoadingImage", "couldn't load start button"

            self.start_buttonRect = self.start_button.get_rect()               
            self.start_buttonRect = self.start_buttonRect.move(100, 100)

            try: self.reset_button = pygame.image.load("UI_Pics/Reset button.jpg")             
            except: raise "ErrorLoadingImage", "couldn't load start button"
            
            self.reset_buttonRect = self.reset_button.get_rect()               
            self.reset_buttonRect = self.reset_buttonRect.move(100, 100)

            self.screen.fill(self.black)
            self.screen.blit(self.start_button, self.start_buttonRect)
#            self.screen.blit(reset_button, self.reset_buttonRect)
                
            pygame.display.flip()
            self.displaySet = True

         for event in pygame.event.get():
           if event.type == pygame.QUIT:
              pygame.quit()
              raise "QUIT"
              return 0
           if event.type == pygame.MOUSEBUTTONDOWN:
              pos = pygame.mouse.get_pos()
              mouseRect = [[pos[0],pos[1]],[5,5]]
              mouseRect = pygame.Rect(mouseRect)
                  
              if pygame.mouse.get_pressed() == (1,0,0):                     
                 clickedStart = mouseRect.colliderect(self.start_buttonRect)
                 clickedReset = mouseRect.colliderect(self.reset_buttonRect)
                     
                 if clickedStart == True:
                    clickedStart = False

#                    try: self.reset_button = pygame.image.load("UI_Pics/Reset button.jpg")             
#                    except: raise "ErrorLoadingImage", "couldn't load start button"
#
#                    self.reset_buttonRect = self.reset_button.get_rect()               
#                    self.reset_buttonRect = self.reset_buttonRect.move(350, 350)

                    self.screen.fill(self.black)
#                    self.screen.blit(self.start_button, self.start_buttonRect)
                    self.screen.blit(self.reset_button, self.reset_buttonRect)
                
                    pygame.display.flip()

                    myServer = SimpleServer(self.protocol, self.port)
                    self.addChildren(myServer)
                    return newComponent(myServer)
                    
                 elif clickedReset == True:
                    clickedReset = False
                    sys.exit()
                
      elif self.demo_mode == False:
         myServer = SimpleServer(self.protocol, self.port)
         self.addChildren(myServer)
         return newComponent(myServer)
      return 1       
Пример #20
0
   def mainBody(self):
#      print "ServerProtocolHandler: Checking mail..."
      if self.dataReady("control"):
         print "ServerProtocolHandler: Message received (control)"
         self.controlMessage = self.recv("control")

         if isinstance(self.controlMessage, socketShutdown):
             print "ServerProtocolHandler: Message from control is", socketShutdown
             return 0
            
      if self.dataReady("inbox"):
         print "ServerProtocolHandler: Message received (inbox)"
         self.requestMessage = self.recv("inbox")
         print "ServerProtocolHandler: Message contained this...", self.requestMessage

         self.file_type, self.number_of_files_to_find, self.clientConnect = self.checkMessage(self.requestMessage, self.number_of_files_to_find)

         if self.file_type == None:
            print "ServerProtocolHandler: Invalid request made" 
            self.send("Invalid request", "outbox")
            return 0
  
         print "ServerProtocolHandler: going to look in this directory", self.directory

         if self.file_type == ".mpg":
            FileChooser = random_file_selector(self.directory, self.file_type, self.number_of_files_to_find)
            ImageGrabber = grab_image_from_video(self.tempFileDirectory, self.delay, self.number_of_snapshots_to_get)
            MyFileReader = char_count_and_read(self.clientConnect)

            self.link(source=(FileChooser, "outbox"), sink=(ImageGrabber, "inbox"), passthrough=0)

            self.link(source=(ImageGrabber, "outbox"), sink=(MyFileReader, "inbox"), passthrough=0)
            self.link(source=(ImageGrabber, "signal"), sink=(MyFileReader, "control"), passthrough=0)
            self.link(source=(ImageGrabber, "tempFilesList"), sink=(self, "_tempFilesList"), passthrough=0)
            
            self.link(source=(MyFileReader, "outbox"), sink=(self, "outbox"), passthrough=2)
            self.link(source=(MyFileReader, "signal"), sink=(self, "_readFinished"), passthrough=0)
            
            self.addChildren(FileChooser, ImageGrabber, MyFileReader)
            return newComponent( FileChooser, ImageGrabber, MyFileReader )
         else:
            FileChooser = random_file_selector(self.directory, self.file_type, self.number_of_files_to_find)
            MyFileReader = char_count_and_read(self.clientConnect, self.delay)

            self.link(source=(FileChooser, "outbox"), sink=(MyFileReader, "inbox"), passthrough=0)
            self.link(source=(FileChooser, "signal"), sink=(MyFileReader, "control"), passthrough=0)

            self.link(source=(MyFileReader, "outbox"), sink=(self, "outbox"), passthrough=2)
            self.link(source=(MyFileReader, "signal"), sink=(self, "_readFinished"), passthrough=0)
            
            self.addChildren(FileChooser, MyFileReader)
            return newComponent( FileChooser, MyFileReader )             
        
      if self.dataReady("_readFinished"):
         print "ServerProtocolHandler: Message received (_readFinished)"
         self.readFinished = self.recv("_readFinished")
         for child in self.childComponents():
           self.postoffice.deregister(component=child)

           
         if isinstance(self.readFinished, producerFinished): 
            self.send(producerFinished("Done"), "signal")
            return 0
      return 1  
Пример #21
0
    def mainBody(self):
        if self.demo_mode == True:
            if self.displaySet == False:
                try:
                    self.start_button = pygame.image.load(
                        "UI_Pics/Start button.jpg")
                except:
                    raise "ErrorLoadingImage", "couldn't load start button"

                self.start_buttonRect = self.start_button.get_rect()
                self.start_buttonRect = self.start_buttonRect.move(100, 100)

                try:
                    self.reset_button = pygame.image.load(
                        "UI_Pics/Reset button.jpg")
                except:
                    raise "ErrorLoadingImage", "couldn't load start button"

                self.reset_buttonRect = self.reset_button.get_rect()
                self.reset_buttonRect = self.reset_buttonRect.move(100, 100)

                self.screen.fill(self.black)
                self.screen.blit(self.start_button, self.start_buttonRect)
                #            self.screen.blit(reset_button, self.reset_buttonRect)

                pygame.display.flip()
                self.displaySet = True

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    raise "QUIT"
                    return 0
                if event.type == pygame.MOUSEBUTTONDOWN:
                    pos = pygame.mouse.get_pos()
                    mouseRect = [[pos[0], pos[1]], [5, 5]]
                    mouseRect = pygame.Rect(mouseRect)

                    if pygame.mouse.get_pressed() == (1, 0, 0):
                        clickedStart = mouseRect.colliderect(
                            self.start_buttonRect)
                        clickedReset = mouseRect.colliderect(
                            self.reset_buttonRect)

                        if clickedStart == True:
                            clickedStart = False

                            #                    try: self.reset_button = pygame.image.load("UI_Pics/Reset button.jpg")
                            #                    except: raise "ErrorLoadingImage", "couldn't load start button"
                            #
                            #                    self.reset_buttonRect = self.reset_button.get_rect()
                            #                    self.reset_buttonRect = self.reset_buttonRect.move(350, 350)

                            self.screen.fill(self.black)
                            #                    self.screen.blit(self.start_button, self.start_buttonRect)
                            self.screen.blit(self.reset_button,
                                             self.reset_buttonRect)

                            pygame.display.flip()

                            myServer = SimpleServer(self.protocol, self.port)
                            self.addChildren(myServer)
                            return newComponent(myServer)

                        elif clickedReset == True:
                            clickedReset = False
                            sys.exit()

        elif self.demo_mode == False:
            myServer = SimpleServer(self.protocol, self.port)
            self.addChildren(myServer)
            return newComponent(myServer)
        return 1
Пример #22
0
    def mainBody(self):
        #      print "ServerProtocolHandler: Checking mail..."
        if self.dataReady("control"):
            print "ServerProtocolHandler: Message received (control)"
            self.controlMessage = self.recv("control")

            if isinstance(self.controlMessage, socketShutdown):
                print "ServerProtocolHandler: Message from control is", socketShutdown
                return 0

        if self.dataReady("inbox"):
            print "ServerProtocolHandler: Message received (inbox)"
            self.requestMessage = self.recv("inbox")
            print "ServerProtocolHandler: Message contained this...", self.requestMessage

            self.file_type, self.number_of_files_to_find, self.clientConnect = self.checkMessage(
                self.requestMessage, self.number_of_files_to_find)

            if self.file_type == None:
                print "ServerProtocolHandler: Invalid request made"
                self.send("Invalid request", "outbox")
                return 0

            print "ServerProtocolHandler: going to look in this directory", self.directory

            if self.file_type == ".mpg":
                FileChooser = random_file_selector(
                    self.directory, self.file_type,
                    self.number_of_files_to_find)
                ImageGrabber = grab_image_from_video(
                    self.tempFileDirectory, self.delay,
                    self.number_of_snapshots_to_get)
                MyFileReader = char_count_and_read(self.clientConnect)

                self.link(source=(FileChooser, "outbox"),
                          sink=(ImageGrabber, "inbox"),
                          passthrough=0)

                self.link(source=(ImageGrabber, "outbox"),
                          sink=(MyFileReader, "inbox"),
                          passthrough=0)
                self.link(source=(ImageGrabber, "signal"),
                          sink=(MyFileReader, "control"),
                          passthrough=0)
                self.link(source=(ImageGrabber, "tempFilesList"),
                          sink=(self, "_tempFilesList"),
                          passthrough=0)

                self.link(source=(MyFileReader, "outbox"),
                          sink=(self, "outbox"),
                          passthrough=2)
                self.link(source=(MyFileReader, "signal"),
                          sink=(self, "_readFinished"),
                          passthrough=0)

                self.addChildren(FileChooser, ImageGrabber, MyFileReader)
                return newComponent(FileChooser, ImageGrabber, MyFileReader)
            else:
                FileChooser = random_file_selector(
                    self.directory, self.file_type,
                    self.number_of_files_to_find)
                MyFileReader = char_count_and_read(self.clientConnect,
                                                   self.delay)

                self.link(source=(FileChooser, "outbox"),
                          sink=(MyFileReader, "inbox"),
                          passthrough=0)
                self.link(source=(FileChooser, "signal"),
                          sink=(MyFileReader, "control"),
                          passthrough=0)

                self.link(source=(MyFileReader, "outbox"),
                          sink=(self, "outbox"),
                          passthrough=2)
                self.link(source=(MyFileReader, "signal"),
                          sink=(self, "_readFinished"),
                          passthrough=0)

                self.addChildren(FileChooser, MyFileReader)
                return newComponent(FileChooser, MyFileReader)

        if self.dataReady("_readFinished"):
            print "ServerProtocolHandler: Message received (_readFinished)"
            self.readFinished = self.recv("_readFinished")
            for child in self.childComponents():
                self.postoffice.deregister(component=child)

            if isinstance(self.readFinished, producerFinished):
                self.send(producerFinished("Done"), "signal")
                return 0
        return 1