Esempio n. 1
0
    def __init__(self):
        # 初始化窗口
        super().__init__()
        self.setupUi(self)

        # 定义线程
        self.mainThread = MainThread()
        self.monitor = MonitorThread(self.mainThread)

        # 绑定信号
        self.monitor.img_signal.connect(self._on_update_image_display)
        self.monitor.voice_ready_signal.connect(self._on_voice_ready)

        self.startButton.clicked.connect(self._on_start_button_clicked)
        self.buttonVoice.clicked.connect(self._on_voice_button_clicked)
        self.buttonCalibrate.clicked.connect(self._on_calibrate_button_clicked)
        self.exitButton.clicked.connect(self._on_exit_button_clicked)

        # 启动monitor
        self.monitor.start()

        self.buttonVoice.setEnabled(False)

        # self._on_start_button_clicked()
        self.show()
        Printer.print("Window ready", Printer.green)
Esempio n. 2
0
def main():
    initialitation("RayCast")
    conn = DataBaseHandle.__conn__()
    display = py.display.set_mode([400, 400])
    time = py.time.Clock()
    running = 1
    wall = Boundary(300, 100, 300, 300)
    ray = Ray(100, 200)
    hilo = MainThread(
        [[display.fill, [colors.BLACK]], [wall.show, [display, colors.WITHE]],
         [ray.show, [display, colors.WITHE]], [py.display.flip, []],
         [time.tick, [5]]], py)

    t1 = Thread(name="non-block", target=updateActionsThread, args=(hilo, ))
    t1.start()
    hilo.mainThread()
Esempio n. 3
0
    def start_server(self):
        server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_socket.bind((self.ip, self.port))
        server_socket.listen(2)
        # server_socket.listen(2) # number of clients at a time
        connected = True
        while connected:
            # starting server
            conn, address = server_socket.accept()
            print(f"[NEW CONECTION] {conn} {address} connected")
            data_received = conn.recv(2048).decode()
            if len(data_received) == 0:
                continue
            else:
                print("#######################")
                modMessage = ast.literal_eval(
                    data_received.split('Connection: close')[1].strip())
                pprint(modMessage)
                messageType = self.main_filter(modMessage)
                MainThreadObj = MainThread()
                MainThreadObj.run_main_thread(messageType=messageType,
                                              inMsg=modMessage)

        conn.close()
Esempio n. 4
0
class MyMainWindow(QWidget, Ui_MainWindow):
    def __init__(self):
        # 初始化窗口
        super().__init__()
        self.setupUi(self)

        # 定义线程
        self.mainThread = MainThread()
        self.monitor = MonitorThread(self.mainThread)

        # 绑定信号
        self.monitor.img_signal.connect(self._on_update_image_display)
        self.monitor.voice_ready_signal.connect(self._on_voice_ready)

        self.startButton.clicked.connect(self._on_start_button_clicked)
        self.buttonVoice.clicked.connect(self._on_voice_button_clicked)
        self.buttonCalibrate.clicked.connect(self._on_calibrate_button_clicked)
        self.exitButton.clicked.connect(self._on_exit_button_clicked)

        # 启动monitor
        self.monitor.start()

        self.buttonVoice.setEnabled(False)

        # self._on_start_button_clicked()
        self.show()
        Printer.print("Window ready", Printer.green)

    def _on_start_button_clicked(self):
        print('start button clicked')
        self.startButton.setEnabled(False)

        self.mainThread.start()
        Printer.print('Main thread started.', Printer.green)

        self.startButton.setText('Started')

        self.buttonVoice.setEnabled(True)
        QApplication.processEvents()

    def _on_voice_button_clicked(self):
        print('voice button clicked')
        # TODO set flag(先判断)
        if self.mainThread.isVoiceGet == 0:
            self.mainThread.audioT()
            self.buttonVoice.setEnabled(False)
        else:
            pass

    def _on_calibrate_button_clicked(self):
        print('calibrate button clicked')
        # TODO set flag
        self.mainThread.needCali = 1

    def _on_exit_button_clicked(self):
        self.mainThread.quit()  # 退出线程  TODO 改成MainThread的
        self.monitor.quit()
        self.close()  # 关闭窗口
        Printer.print("exit", Printer.green)

    def _on_voice_ready(self):
        self.buttonVoice.setEnabled(True)

    def _on_update_image_display(self, image):
        # print("update image")
        try:
            if isinstance(image, int):
                return
            w = self.imgLabel_r.width()
            h = self.imgLabel_r.height()
            print('w=%d, h=%h' % (w, h))
            cv2.resize(image, (w, h))
            bytesPerLine = 3 * w
            self.qImg = QImage(image.data, w, h, bytesPerLine,
                               QImage.Format_RGB888).rgbSwapped()
            # 将Qimage显示出来
            self.imgLabel_r.setPixmap(QPixmap.fromImage(self.qImg))
        except Exception as e:
            Printer.print('update image error: ' + e.__str__(), Printer.red)

    def _on_slider_change_value(self, value):
        self.slider_lable.setText('%f' % (self.thresholdSlider.value() / 255))
        self.main_thread.value = self.thresholdSlider.value() / 255
Esempio n. 5
0
def initThreads(pool, threadNumber):
    for i in range(threadNumber):
        thread = MainThread()
        thread.start()
        pool.append(thread)
Esempio n. 6
0
 def test_set2(self):
 	thread = MainThread()
 	setDict = thread.setDict('b','')
 	self.assertEquals("OK", setDict)
def initThreads(pool,threadNumber):
	for i in range(threadNumber):
		thread = MainThread()
		thread.start()
		pool.append(thread)