def InstallAllOptioned(self): self.Install.setDisabled(True) self.InstallThread = Thread({ 'vc2015-2019_x86.exe': self.vc2015to19x86.isChecked(), 'vc2015-2019_x64.exe': self.vc2015to19x64.isChecked(), 'vc2013_x86.exe': self.vc2013x86.isChecked(), 'vc2013_x64.exe': self.vc2013x64.isChecked(), 'vc2012_x86.exe': self.vc2012x86.isChecked(), 'vc2012_x64.exe': self.vc2012x64.isChecked(), 'vc2010_x86.exe': self.vc2010x86.isChecked(), 'vc2010_x64.exe': self.vc2010x64.isChecked(), 'vc2008_x86.exe': self.vc2008x86.isChecked(), 'vc2008_x64.exe': self.vc2008x64.isChecked() }) self.InstallThread.EmptyOption.connect(self.EmptyOptionTip) self.InstallThread.UnzipFile.connect(self.UnzipFileTip) self.InstallThread.Installing.connect(self.InstallingTip) self.InstallThread.InstallFinish.connect(self.InstallFinishTip) self.InstallThread.start()
def screen(self): #loading Ui file named untitled.ui. It contains a label box named screen uic.loadUi('untitled.ui', self) self.myThread = Thread(self) self.myThread.stream = 0 self.myThread.changePixmap.connect(self.screen.setPixmap) self.myThread.start()
def Open(self): SwitchWindow(self.masterFrame, self.root) self.Refresh() if self.refreshingThread == None: self.refreshingThread = Thread('refreshingThread', self.SensorRefresh, 0.5) self.refreshingThread.start()
def Start(): Sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) Sock.bind((SERVER_HOST, SERVER_PORT)) Sock.listen(Max) print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}") while True: client, address = Sock.accept() data = client.recv(BUFFER_SIZE).decode() if data == "code": ClientFile = open('__Client.py', 'r', encoding='utf-8') while True: Byte = ClientFile.read(BUFFER_SIZE) if not Byte: ClientFile.close() break client.send(Byte.encode()) client.send("--||--".encode()) print(f"[+] {address} is connecting.") t = Thread(target=Command, args=(client, address), daemon=True) t.start() t.join()
def makeThreads(self, numberOfTracks, divisionConstant): threadProbability = 100 / divisionConstant #threadProbability for first thread (see note below at divisionConstant decleration) self.threads = [] #array of threadObjects that will be used for each in range(0, numberOfTracks): #making one Thread object for each possible numberOfTracks that will play at one time self.threads.append(Thread((threading.Thread()), (threadProbability))) #First parameter for Thread() - a new thread #Second parameter - the probability that the thread will play when it is checked, calculated on the next line threadProbability = (self.threads[each].getProbability() / 2) #to be used for the next thread to be created return
def Open(self): #retour = Popup(self, 2, texte= "ATTENTION: Ce menu est reservé au personnel habilité", valider= "Continuer", fermer= "Retour") #if retour == False: # return SwitchWindow(self.masterFrame, self.root) self.Refresh() if self.refreshingThread == None: self.refreshingThread = Thread('refreshingThread', self.SensorRefresh, 0.1) self.refreshingThread.start()
def run(self): try: old_path = self.lineEdit_old.text() new_path = self.lineEdit_new.text() if not all([old_path, new_path]): return self.t = Thread(self, old_path, new_path) self.t.sig_msg.connect(self.update_label) self.t.finished.connect(self.t.deleteLater) self.t.start() QMessageBox.information(self, '提示', '运行完成') except Exception as e: QMessageBox.warning(self, '错误', str(e))
def start_btn_clicked(self): btn = self.sender() prob_rule4 = int(self._prob_rule4.text()) self._mesh.set_prob_for_rule4(prob_rule4) if self._mesh.is_running(): btn.setText("START") else: btn.setText("STOP") self._thread = Thread(self._mesh) self._thread.update_ui.connect(self._update_UI) self._thread.update_btn.connect(self._update_button) self._thread.start() self._mesh.change_started()
def startThread(self): if self.__thread is None: thread = Thread(self.__trackers) self.__thread = thread self.__thread.start() print("Thread enabled") else: print("Thread already enabled")
def init(self): Logger.debug("SlaveServer init") if not self.communication.initialize(): Logger.error( "SlaveServer: unable to initialize communication class") return False self.communication.ovd_thread = Thread(name="Communication", target=self.communication.run) self.threads.append(self.communication.ovd_thread) for role in self.roles: try: if not role.init(): raise Exception() except Exception, e: Logger.error("SlaveServer: unable to initialize role '%s' %s" % (role.getName(), str(e))) return False role.thread = Thread(name="role_%s" % (role.getName()), target=role.run) self.threads.append(role.thread)
def __init__(self): super(base, self).__init__() # default setup self.setupUi(self) # create thread for updating the GUI self.thread = Thread() # connect thread of incoming data to updateData method self.thread.newData.connect(self.updateData) # start thread self.thread.start() # handle button clicks self.buttonPlayPause.clicked.connect(onPlayPauseClick) self.buttonPreviousTrack.clicked.connect(onPreviousTrackClick) self.buttonNextTrack.clicked.connect(onNextTrackClick)
def run_simulation(self): """ Iniciar el simulador de ICESym """ # TODO: Verificar si hay componentes desconectados simulator = None if 'linux' in platform: simulator = os.path.join(SIMULATOR_PATH,"exec") elif 'win' in platform: simulator = os.path.join(SIMULATOR_PATH,"exec.exe") if not simulator or not os.path.isfile(simulator): show_message('Cannot find exec file. Please, create this file to run the simulator') return # Salvar el caso self.save_data_f(None,True) logfile = os.path.join(SIMULATOR_PATH,'run.log') errorlogfile = os.path.join(SIMULATOR_PATH,'error.log') if 'linux' in platform: command = "%s %s %s 1> %s 2> %s"%(simulator,self.case_dir,self.case_name,logfile,errorlogfile) elif 'win' in platform: command = "echo.> %s"%logfile os.system(command) while not os.path.isfile(logfile): None command_ex = "%s %s %s 1^> %s 2^> %s"%(simulator,self.case_dir,self.case_name,logfile,errorlogfile) execwfile = os.path.join(SIMULATOR_PATH,'execw.bat') command = "echo %s > %s"%(command_ex,execwfile) os.system(command) while not os.path.isfile(execwfile): None command = os.path.join(SIMULATOR_PATH,'execw.bat') self.thread_runSimulation = Thread(command) # limpio el log y agrego el archivo al watcher self.ui_tab_widget.logPlainTextEdit.clear() self.thread_runSimulation.started.connect(lambda: self.init_log(logfile)) self.thread_runSimulation.started.connect(self.show_info) self.thread_runSimulation.finished.connect(self.reset_log) self.thread_runSimulation.finished.connect(self.reset_pid) self.thread_runSimulation.finished.connect(self.success_simulation) # inicio el thread self.thread_runSimulation.start() return
def parse_thread(thread_num, visualize): """ Given a thread_num of a thread on /biz/ on 4chan, this function creates a Thread representation of that thread. Useful for revealing sub thread conversations on a given thread. If visualize is enabled, creates a pdf file of the graph output, titled thread_thread_num.pdf. :param thread_num: the number of the thread to create :param visualize: boolean for visualization :return: the Thread object for future use """ pg2 = requests.get('https://a.4cdn.org/biz/thread/{}.json'.format(thread_num)).json() # Maps all of the post JSON into threads posts = list(map(make_post, pg2['posts'])) # Updates the posts to have responses attached to them list(map(lambda x: x.add_responses(list(filter(lambda y: x.title in y.resto, posts))), posts)) # If the visualize argument is true, then render a graphviz digraph of the Thread if visualize: graph = gv.Digraph() list(map(lambda x: graph.node(name=str(x.title), label=str(x.content)), posts)) for post in posts: for res in post.resto: graph.edge(str(post.title), str(res)) graph.render('thread_{}'.format(thread_num)) with open("thread_{}.json".format(thread_num), 'w+') as f: f.write(str(pg2)) # Create the thread object, and mark the OP as the post that is a resto 0 print('======================================================================') for post in posts: print(post) t = Thread(start_date=pg2.get('time'), title=pg2.get('title'), op=head(list(filter(lambda x: x.resto == {'0'} or x.resto == {0}, posts)))) return t
def main(): global FACE_DETECTOR, stepper_index, CURRENT_FACE, DELAY_IMAGES, NEXT_TIME, IMAGE, DEFINITION_MULTIPLIER, TRACKING_SCREEN, CAPTURE, DELAY_DELETE_IMAGES, LOW_RES_STREAM, index, servo_index_x, gray # Init script STEPPER.start() STEPPER.enable(False) # LOCK = threading.Lock() # CONTROL_THREAD = Thread() # CONTROL_THREAD.setRunFunction(control_loop) # CONTROL_THREAD.start() # Global variables CURRENT_TIME = time.time() DELAY_IMAGES = 5 NEXT_TIME = CURRENT_TIME + DELAY_IMAGES # Camera IMAGE = None DEFINITION_MULTIPLIER = 1 CAMERA = PiCamera() CAMERA.resolution = (int(1024 * 1.5), int(768 * 1.5)) CAMERA.framerate = 32 TRACKING_SCREEN = [ int(160 * DEFINITION_MULTIPLIER), int(120 * DEFINITION_MULTIPLIER) ] CAPTURE = PiRGBArray(CAMERA, size=(int(160 * DEFINITION_MULTIPLIER), int(120 * DEFINITION_MULTIPLIER))) DELAY_DELETE_IMAGES = 60 # seconds -> 2min LOW_RES_STREAM = CAMERA.capture_continuous( CAPTURE, format="bgr", use_video_port=True, splitter_port=2, resize=(int(160 * DEFINITION_MULTIPLIER), int(120 * DEFINITION_MULTIPLIER))) time.sleep(2.0) print("done warming up") # Remove all old images CAN_TAKE_A_PHOTO = False SYNC_FOLDER_PATH = "/home/pi/Desktop/RPI_3_sync/" file_list = glob.glob(SYNC_FOLDER_PATH + "*.jpg") for image in file_list: os.remove(image) # Run the min loop run = True try: while run: # Update current time CURRENT_TIME = time.time() if FACES is not None: if len(FACES) > 0: #print("photo") CAN_TAKE_A_PHOTO = True # Take pictures every DELAY_IMAGES if CURRENT_TIME >= NEXT_TIME and CAN_TAKE_A_PHOTO: CAMERA.capture(SYNC_FOLDER_PATH + str(int(math.floor(time.time() * 1000))) + '.jpg') file_list = glob.glob(SYNC_FOLDER_PATH + "*.jpg") #print("Image taken: " + str(len(file_list))) for image in file_list: name = float( image.split("/")[len(image.split("/")) - 1].replace( ' ', '')[:-4].upper()) # Delete images that are older than the DELAY_DELETE_IMAGES if name < CURRENT_TIME - DELAY_DELETE_IMAGES: os.remove(image) for i in range(len(file_list), 0): if len(file_list) - i > 20: os.remove(file_list[i]) NEXT_TIME += DELAY_IMAGES CAN_TAKE_A_PHOTO = False low_res = LOW_RES_STREAM.next() IMAGE = low_res.array gray = cv2.cvtColor(IMAGE, cv2.COLOR_BGR2GRAY) # Run face detection as soon as one has ended if FACE_DETECTOR is None: FACE_DETECTOR = Thread() FACE_DETECTOR.setRunFunction(face_detection) FACE_DETECTOR.start() else: if FACE_DETECTOR.isAlive() is not True: FACE_DETECTOR = None if FACES is not None: if len(FACES) > 0: if CURRENT_FACE is None: CURRENT_FACE = FACES[0] # Always check for the closer face to the last one # in order not to jump from a face to another min_distance = float("inf") for face in FACES: distance = math.sqrt( math.pow(CURRENT_FACE[0] - face[0], 2) + math.pow(CURRENT_FACE[1] - face[1], 2)) if distance < min_distance: min_distance = distance CURRENT_FACE = face #print(CURRENT_FACE) cv2.circle(IMAGE, (CURRENT_FACE[0] + CURRENT_FACE[2] / 2, CURRENT_FACE[1] + CURRENT_FACE[3] / 2), int(CURRENT_FACE[2] / 3), (255, 255, 255), 1) else: CURRENT_FACE = None # Motors control #SERVO.set(0, 0.5 - math.sin(index) * 0.1) #SERVO.set(0, 0.5) stepper_index += 0.001 # Check if there is a current face to track if CURRENT_FACE is not None: # print("face") face_pos_x = CURRENT_FACE[0] + CURRENT_FACE[2] / 2 delta_x = (face_pos_x - TRACKING_SCREEN[0] * 0.5) / ( TRACKING_SCREEN[0] * 0.5) servo_index_x += delta_x * -0.02 STEPPER.enable(True) face_pos_y = CURRENT_FACE[1] + CURRENT_FACE[3] / 2 delta_y = (face_pos_y - TRACKING_SCREEN[1] * 0.5) / ( TRACKING_SCREEN[1] * 0.5) STEPPER.setVelocity(delta_y * 2) else: STEPPER.enable(False) index += 0.03 servo_target = 0.5 - math.sin(index) * 0.3 servo_index_x += (servo_target - servo_index_x) * 0.1 SERVO.set(0, servo_index_x) time.sleep(0.001) CAPTURE.truncate(0) # cv2.imshow("Frame", IMAGE) key = cv2.waitKey(1) & 0xFF if key == ord("q"): STEPPER.stop() STEPPER.enable(False) CONTROL_THREAD.stop() run = False break elif key == ord("r"): servo_index_x = 0.45 except KeyboardInterrupt: STEPPER.stop() STEPPER.enable(False) CONTROL_THREAD.stop() run = False
CAPTURE.truncate(0) # cv2.imshow("Frame", IMAGE) key = cv2.waitKey(1) & 0xFF if key == ord("q"): STEPPER.stop() STEPPER.enable(False) CONTROL_THREAD.stop() run = False break elif key == ord("r"): servo_index_x = 0.45 except KeyboardInterrupt: STEPPER.stop() STEPPER.enable(False) CONTROL_THREAD.stop() run = False def waitUntilBoot(): print("Waiting 20 sec") time.sleep(20) print("Start") main() waitThread = Thread() waitThread.setRunFunction(waitUntilBoot) waitThread.start()
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setGeometry(250, 250, 600, 300) self.setWindowTitle("TenElevenGames OXO") self.setWindowIcon(QIcon("icon.jpg")) self.show() # NERDZONE # implement a simple help menu # create QAction buttons for the menu Instructions = QAction("How to play", self) AboutGame = QAction("About", self) More = QAction("More", self) # add the buttons to the menu menu = QMenuBar() menu.addAction(Instructions) menu.addAction(AboutGame) menu.addAction(More) # connect the buttons to their respective methods # when clicked, each button is supposed to show a popup dialogue # with the relevant information as per the name of the button suggests Instructions.triggered.connect(self.instructions) AboutGame.triggered.connect(self.about) More.triggered.connect(self.more) # images self.cross = QPixmap("cross.gif") self.nought = QPixmap("nought.gif") self.blank = QtGui.QIcon("blank.gif") # create a thread to run parallel to the gui self.messageThread = Thread() self.messageThread.signalLine.connect(self.threadLine) # Game board # create game buttons and set their sizes when window changes size # connect each button to it's OWN method self.buttonArray = [] # first row self.button1 = QPushButton() self.button1.setIcon(QtGui.QIcon('blank.gif')) self.button1.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button1) self.button1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button1.clicked.connect(self.button1Event) self.button2 = QPushButton() self.button2.setIcon(QtGui.QIcon('blank.gif')) self.button2.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button2) self.button2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button2.clicked.connect(self.button2Event) self.button3 = QPushButton() self.button3.setIcon(QtGui.QIcon('blank.gif')) self.button3.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button3) self.button3.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button3.clicked.connect(self.button3Event) # # second row self.button4 = QPushButton() self.button4.setIcon(QtGui.QIcon('blank.gif')) self.button4.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button4) self.button4.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button4.clicked.connect(self.button4Event) self.button5 = QPushButton() self.button5.setIcon(QtGui.QIcon('blank.gif')) self.button5.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button5) self.button5.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button5.clicked.connect(self.button5Event) self.button6 = QPushButton() self.button6.setIcon(QtGui.QIcon('blank.gif')) self.button6.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button6) self.button6.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button6.clicked.connect(self.button6Event) # # third row self.button7 = QPushButton() self.button7.setIcon(QtGui.QIcon('blank.gif')) self.button7.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button7) self.button7.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button7.clicked.connect(self.button7Event) self.button8 = QPushButton() self.button8.setIcon(QtGui.QIcon('blank.gif')) self.button8.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button8) self.button8.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button8.clicked.connect(self.button8Event) self.button9 = QPushButton() self.button9.setIcon(QtGui.QIcon('blank.gif')) self.button9.setIconSize(QtCore.QSize(60, 85)) self.buttonArray.append(self.button9) self.button9.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button9.clicked.connect(self.button9Event) # self.Quit = QPushButton("Quit") self.Quit.setShortcut("ctrl+v") self.Quit.setToolTip("Exit the game: ctrl+v") self.Quit.resize(10, 10) # self.Quit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.Quit.clicked.connect(self.quit) self.connectServer = QPushButton("Connect") self.connectServer.setShortcut("ctrl+e") self.connectServer.setToolTip("Connect to the server: ctrl+e") self.connectServer.clicked.connect(self.connectEvent) self.messageBox = QTextEdit() self.messageBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # ensure that the QTextEdit allows for reading messages only, no typing/editing. "lock" the QTextEdit. self.messageBox.setReadOnly(True) # server entry self.label = QLabel("Enter server: ") self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.getServer = QLineEdit('127.0.0.1') # player character display self.character = QLabel("Game Character: ") self.pixmap = QPixmap('cross.gif') self.pixmap2 = QPixmap("nought.gif") self.picLabel = QLabel() self.picLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # enhancement # will most probably remove this later on self.comboBox = QComboBox() self.comboBox.addItems( ['Pink', 'Grey', 'Red', 'Orange', 'Yellow', 'Purple']) self.comboBox.activated.connect(self.setColour) self.setStyleSheet("background-color: pink") self.messageBox.setStyleSheet('background-color: white') self.getServer.setStyleSheet('background-color: white') # self.comboBox.setStyleSheet('background-color: white') hbox = QHBoxLayout() hbox.addWidget(menu) hbox2 = QWidget() hbox2.setLayout(hbox) # present everything in a Gridlayout # making sure to set span width and length (rows, columns) to avoid overlapping grid = QGridLayout() grid.addWidget(hbox2, 0, 4, 1, 3) grid.addWidget(self.label, 1, 0, 1, 1) grid.addWidget(self.getServer, 1, 1, 1, 1) grid.addWidget(self.connectServer, 1, 2, 1, 1) grid.addWidget(self.comboBox, 1, 3, 1, 1) # grid.addWidget(self.button1, 2, 0, 1, 1) grid.addWidget(self.button2, 2, 1, 1, 1) grid.addWidget(self.button3, 2, 2, 1, 1) # grid.addWidget(self.button4, 3, 0, 1, 1) grid.addWidget(self.button5, 3, 1, 1, 1) grid.addWidget(self.button6, 3, 2, 1, 1) # grid.addWidget(self.button7, 4, 0, 1, 1) grid.addWidget(self.button8, 4, 1, 1, 1) grid.addWidget(self.button9, 4, 2, 1, 1) # grid.addWidget(self.messageBox, 2, 3, 3, 4) grid.addWidget(self.character, 5, 1, 1, 1) grid.addWidget(self.picLabel, 5, 2, 1, 1) grid.addWidget(self.Quit, 5, 5, 1, 1) # self.setLayout(grid)
servo_index_x += (servo_target - servo_index_x) * 0.005 LOCK.release() SERVO.set(0, servo_index_x) time.sleep(0.001) except KeyboardInterrupt: print("Control thread ended!") # Init script STEPPER.start() STEPPER.enable(False) LOCK = threading.Lock() CONTROL_THREAD = Thread() CONTROL_THREAD.setRunFunction(control_loop) CONTROL_THREAD.start() # Global variables CURRENT_TIME = time.time() DELAY_IMAGES = 5 NEXT_TIME = CURRENT_TIME + DELAY_IMAGES # Camera IMAGE = None DEFINITION_MULTIPLIER = 1 CAMERA = PiCamera() CAMERA.resolution = (int(1024 * 1.5), int(768 * 1.5)) CAMERA.framerate = 32 TRACKING_SCREEN = [