def onLogin(self, host, username, passwd, ssl): """ Slot. Triggers a log in request to the server. :param host: Indicates the hostname of the FTP server :param username: Username to log in into the FTP server :param passwd: Password to log in into the FTP server :param ssl: Indicates whether the FTP needs SSL support """ self.sync = Sync(host, ssl) self.syncStarted.connect(self.sync.initQueue) self.sync.server.downloadProgress.connect(self.onDownloadProgress) self.sync.server.uploadProgress.connect(self.onUploadProgress) self.sync.server.fileEvent.connect(self.onFileEvent) self.sync.server.badFilenameFound.connect(self.badNameWarning) self.sync.server.loginCompleted.connect(self.onLoginCompleted) self.sync.server.fileEventCompleted.connect(self.onFileEventCompleted) self.sync.server.ioError.connect(self.onIOError) # Added by Si self.sync.server.textStatus.connect(self.setStatus) self.sync.statusChanged.connect(self.setStatus) self.loginRequested.connect(self.sync.server.onLogin) self.syncThread = QThread() self.sync.moveToThread(self.syncThread) self.syncThread.start() QApplication.instance().lastWindowClosed.connect(self.syncThread.quit) self.loginRequested.emit(username, passwd)
def start_q_watcher(app, emu_window, proc_comms_q_to_em, proc_comms_q_from_em): # need to spawn a worker thread that watches the proc_comms_q # need to seperate queue function from queue thread # http://stackoverflow.com/questions/4323678/threading-and-signals-problem # -in-pyqt q_watcher = QueueWatcher(app, emu_window, proc_comms_q_to_em, proc_comms_q_from_em) q_watcher_thread = QThread() q_watcher.moveToThread(q_watcher_thread) q_watcher_thread.started.connect(q_watcher.check_queue) # now that we've set up the thread, let's set up rest of signals/slots q_watcher.set_out_enable.connect(emu_window.set_output_enable) q_watcher.set_out_disable.connect(emu_window.set_output_disable) q_watcher.get_in.connect(emu_window.get_input) q_watcher.get_out.connect(emu_window.get_output) emu_window.send_output.connect(q_watcher.send_get_out_pin_result) emu_window.send_input.connect(q_watcher.send_get_in_pin_result) emu_window.interrupt_flagger.connect(q_watcher.handle_interrupt) # not sure why this doesn't work by connecting to q_watcher_thread.quit def about_to_quit(): q_watcher_thread.quit() app.aboutToQuit.connect(about_to_quit) q_watcher_thread.start()
def testQThreadReceiversExtern(self): #QThread.receivers() - Inherited protected method obj = QThread() self.assertEqual(obj.receivers(SIGNAL('destroyed()')), 0) QObject.connect(obj, SIGNAL("destroyed()"), self.cb) self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 1)
def Record(self): if self.action_Record.isChecked(): if not self.acquiring: self.workerThread = QThread(self) self.workerThread.start() self.worker = Worker(self) self.worker.moveToThread(self.workerThread) try: self.start_rec.disconnect() except: pass while 1: try: self.sock.send('StartAcquisition') self.sock.recv() except: continue break while 1: try: self.sock.send('StartRecord') self.sock.recv() except: continue break self.vidbuffer = [] self.start_rec.connect(self.worker.acquire) self.recording = True self.start_rec.emit('start!') else: while 1: try: self.sock.send('StartRecord') self.sock.recv() except: continue break self.vidbuffer = [] self.recording = True record_icon = self.style().standardIcon(QStyle.SP_DialogNoButton) #set the icon for the action self.action_Record.setIcon(record_icon) self.action_Record.setEnabled(False) self.action_Acq.setChecked(False) self.action_Acq.setEnabled(True)
def __init__(self, cmd, img): """Initialize executor. Args: cmd -- command to execute (str) img -- path to resulting image (the renderer output) (str) """ super().__init__(QCoreApplication.instance()) self.thread = QThread() self.worker = Worker(cmd, img) self.thread.setObjectName("fcd-renderexec")
def Acquire(self): if self.action_Acq.isChecked(): self.vidbuffer = [] if self.recording: while 1: try: self.sock.send('StopRecord') self.sock.recv() except: continue break self.recording = False else: #create and start a thread to transport a worker to later self.workerThread = QThread(self) self.workerThread.start() #create a worker object based on Worker class and move it to our #worker thread self.worker = Worker(self) self.worker.moveToThread(self.workerThread) try: self.start_acq.disconnect() except: pass while 1: try: self.sock.send('StartAcquisition') self.sock.recv() except: continue break self.acquiring = True self.start_acq.connect(self.worker.acquire) self.start_acq.emit('start!') self.action_Acq.setEnabled(False) self.action_Record.setChecked(False) self.action_Record.setEnabled(True) record_icon = self.style().standardIcon(QStyle.SP_DialogYesButton) #set the icon for the action self.action_Record.setIcon(record_icon)
def start_input_watcher(app, emu_window): input_watcher = InputWatcher(emu_window) input_watcher_thread = QThread() input_watcher.moveToThread(input_watcher_thread) input_watcher_thread.started.connect(input_watcher.check_inputs) # signal / slots input_watcher.set_in_enable.connect(emu_window.set_input_enable) input_watcher.set_in_disable.connect(emu_window.set_input_disable) # quit setup def about_to_quit(): input_watcher.stop_checking_inputs() input_watcher_thread.quit() app.aboutToQuit.connect(about_to_quit) input_watcher_thread.start()
def unlockFile(self): if EncryptedFile.isValidFile(self.fileName): eFile = EncryptedFile(self.fileName) unhashedPassword = self.passwordLineEdit.text() password = EncryptionHelper.generateKeyHash(unhashedPassword) self.thread = QThread() self.worker = Worker(eFile, password, self.signal, self.sameLocation) self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.worker.signal.connect(self.thread.quit) self.worker.signal.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.thread.start() else: QMessageBox.information(self, __appname__, "Invalid .exelocker file.") self.passwordLineEdit.setText("")
# @Slot() def receive(self): report("receive: DERIVED") USE_DERIVED = True if __name__ == '__main__': logging.basicConfig() logger.setLevel(logging.DEBUG) # Objects app = QCoreApplication(sys.argv) tx_thread = QThread() debug_thread("tx_thread", tx_thread) transmitter = Transmitter() debug_object(transmitter) transmitter.moveToThread(tx_thread) debug_object(transmitter) rx_thread = QThread() debug_thread("rx_thread", rx_thread) if USE_DERIVED: # receiver = Derived() # receiver = DerivedTwo() # receiver = DerivedThree() # receiver = RelayDerived() receiver = DerivedFromNoSlot() else:
def __init__(self, parent=None): ''' sets up the whole main window ''' #standard init super(MainWindow, self).__init__(parent) #set the window title self.setWindowTitle('Open Ephys Control GUI') self.window_height = 700 self.window_width = 1100 self.screen2 = QDesktopWidget().screenGeometry(0) self.move( self.screen2.left() + (self.screen2.width() - self.window_width) / 2., self.screen2.top() + (self.screen2.height() - self.window_height) / 2.) self.get_info() self.noinfo = True while self.noinfo: loop = QEventLoop() QTimer.singleShot(500., loop.quit) loop.exec_() subprocess.Popen('start %s' % open_ephys_path, shell=True) self.collect_frame.connect(self.update_frame) self.collect_threshed.connect(self.update_threshed) self.acquiring = False self.recording = False self.video_height = self.window_height * .52 self.video_width = self.window_width * .48 self.resize(self.window_width, self.window_height) #create QTextEdit window 'terminal' for receiving stdout and stderr self.terminal = QTextEdit(self) #set the geometry self.terminal.setGeometry( QRect(self.window_width * .02, self.window_height * .15 + self.video_height, self.video_width * .96, 150)) #make widgets self.setup_video_frames() self.setup_thresh_buttons() self.overlay = True #create thread and worker for video processing self.videoThread = QThread(self) self.videoThread.start() self.videoproc_worker = VideoWorker(self) self.videoproc_worker.moveToThread(self.videoThread) self.vt_file = None """""" """""" """""" """""" """""" """""" """""" """ set up menus """ """""" """""" """""" """""" """""" """""" """""" #create a QMenuBar and set geometry self.menubar = QMenuBar(self) self.menubar.setGeometry( QRect(0, 0, self.window_width * .5, self.window_height * .03)) #set the QMenuBar as menu bar for main window self.setMenuBar(self.menubar) #create a QStatusBar statusbar = QStatusBar(self) #set it as status bar for main window self.setStatusBar(statusbar) #create icon toolbar with default image iconToolBar = self.addToolBar("iconBar.png") #create a QAction for the acquire button self.action_Acq = QAction(self) #make it checkable self.action_Acq.setCheckable(True) #grab an icon for the button acq_icon = self.style().standardIcon(QStyle.SP_MediaPlay) #set the icon for the action self.action_Acq.setIcon(acq_icon) #when the button is pressed, call the Acquire function self.action_Acq.triggered.connect(self.Acquire) #create a QAction for the record button self.action_Record = QAction(self) #make it checkable self.action_Record.setCheckable(True) #grab an icon for the button record_icon = self.style().standardIcon(QStyle.SP_DialogYesButton) #set the icon for the action self.action_Record.setIcon(record_icon) #when the button is pressed, call advanced_settings function self.action_Record.triggered.connect(self.Record) #create QAction for stop button action_Stop = QAction(self) #grab close icon stop_icon = self.style().standardIcon(QStyle.SP_MediaStop) #set icon for action action_Stop.setIcon(stop_icon) #when button pressed, close window action_Stop.triggered.connect(self.Stop) #show tips for each action in the status bar self.action_Acq.setStatusTip("Start acquiring") self.action_Record.setStatusTip("Start recording") action_Stop.setStatusTip("Stop acquiring/recording") #add actions to icon toolbar iconToolBar.addAction(self.action_Acq) iconToolBar.addAction(self.action_Record) iconToolBar.addAction(action_Stop) # self.sort_button = QPushButton('Sort Now',self) # self.sort_button.setGeometry(QRect(self.window_width*.85,0,self.window_width*.15,self.window_height*.05)) # self.sort_button.clicked.connect(self.sort_now) #show the window if minimized by windows self.showMinimized() self.showNormal() """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" "" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" ""