def run(self):
        logger.info("Listen to GameController")
        while not self.__cancel.is_set():
            try:
                # receive GC data
                data, address = self.socket.recvfrom(8192)

                if len(data) > 0:
                    message = GameControlData(data)
                    # one of the teams is invisible
                    Event.fire(Event.GameControllerMessage(message))

            except socket.timeout:
                Event.fire(Event.GameControllerTimedout())
                #statusMonitor.setDidntReceivedMessageFromGC(1)
                logger.warning(format(datetime.datetime.now() + datetime.timedelta(hours=8), '%H:%M:%S') + " Not connected to GameController?")
                self.message = None
                continue
            except Exception as ex:
                self.message = None
                print(ex)
                continue

        self.socket.close()
Example #2
0
    def run(self):
        try:
            # Start pipeline
            self.pipeline.start()
            time.sleep(2)
            self.startPipeline()

            self.updateSettings()
            while not self.__cancel.is_set():
                if not self.checkUpload():
                    self.stop()
                    exit(-1)

                if self.pipeline.get_state() != Gst.State.PLAYING:
                    self.startPipeline()

                start = datetime.datetime.now()
                with self.overlay_lock:
                    if not self.gc_data and not self.TESTING:
                        self.img = Image.new('RGBA', (self.WIDTH, self.HEIGHT))
                        draw = ImageDraw.Draw(self.img)

                        ##############################
                        ### Actual Time -> TopRight ###
                        ##############################
                        marginTime = 20 * self.heightFactor
                        actualTime = self.timeToString()
                        text_size = self.fontThin.getsize(actualTime)
                        actualTimeRightX = self.WIDTH - (5 * self.widthFactor)
                        actualTimeLeftX = actualTimeRightX - (text_size[0] +
                                                              marginTime)
                        actualTimeTopY = 5 * self.heightFactor
                        actualTimeBottomY = actualTimeTopY + self.maxFontHeight + marginTime
                        draw.font = self.fontThin
                        draw.rectangle([(actualTimeLeftX, actualTimeTopY),
                                        (actualTimeRightX, actualTimeBottomY)],
                                       fill=self.WHITE,
                                       outline=self.WHITE)
                        draw.text((actualTimeLeftX + marginTime / 2,
                                   actualTimeTopY + marginTime / 2),
                                  actualTime,
                                  fill=self.BLACK)

                        #############################
                        ### Live Text -> TopLeft ###
                        #############################
                        if self.live_text != "":
                            marginLiveText = 20 * self.heightFactor
                            text_size = self.fontThin.getsize(self.live_text)
                            liveTextLeftX = marginLiveText
                            liveTextRightX = liveTextLeftX + (text_size[0] +
                                                              marginLiveText)
                            liveTextTopY = 5 * self.heightFactor
                            liveTextBottomY = liveTextTopY + self.maxFontHeight + marginLiveText
                            draw.font = self.fontThin
                            draw.rectangle([(liveTextLeftX, liveTextTopY),
                                            (liveTextRightX, liveTextBottomY)],
                                           fill=self.WHITE,
                                           outline=self.WHITE)
                            draw.text((liveTextLeftX + marginLiveText / 2,
                                       liveTextTopY + marginLiveText / 2),
                                      self.live_text,
                                      fill=self.BLACK)

                if self.TESTING:
                    self.receivedGC(
                        Event.GameControllerMessage(
                            GameControlData(testing=True)))

                self.overlay_element.overlay = from_pil(self.img)

                end = datetime.datetime.now()
                time.sleep(max(0.0, 1.0 - (end - start).total_seconds()))

            self.pipeline.stop()
        except Exception as e:
            logger.warning("Camera broke!")
            print("-" * 60)
            logger.warning(str(e))
            traceback.print_exc(file=sys.stdout)
            print("-" * 60)