def embed(self, command, *args): proc = QtCore.QProcess() proc.setProgram(command) proc.setArguments(args) started, procId = proc.startDetached() if not started: QtWidgets.QMessageBox.critical(self, 'Command "{}" not started!') return attempts = 0 while attempts < 10: screen = Wnck.Screen.get_default() screen.force_update() # this is required to ensure that newly mapped window get listed. while Gdk.events_pending(): Gdk.event_get() for w in screen.get_windows(): if w.get_pid() == procId: window = QtGui.QWindow.fromWinId(w.get_xid()) container = QtWidgets.QWidget.createWindowContainer( window, self) self.addTab(container, command) return attempts += 1 QtWidgets.QMessageBox.critical(self, 'Window not found', 'Process started but window not found')
def initialize_window(self): """Method that initializes all the components of the main window. Parameters: - self: current instance of the class. """ self.current_network = network_core.create_network() self.current_network_name = "" self.current_network_path = "" self.current_network_deployed = 0 self.resize(1024, 768) self.center() self.setWindowTitle("Virtual Network automated deployment via Vagrant") self.main_toolbar() self.statusbar() self.setWindowIcon(QtGui.QIcon("./Images/network.png")) self.main_frame = QtWidgets.QWidget() self.main_frame_layout = QtWidgets.QVBoxLayout(self.main_frame) self.setCentralWidget(self.main_frame) self.canvas_html() self.debug_console() self.network_wizard = new_network_wizard(self) self.editor_window = editor_components(self) self.dashboard_window = dashboard_vms(self) self.edge_window = edge_editors(self) self.vagrant_process = QtCore.QProcess(self) self.vagrant_process.readyReadStandardOutput.connect( self.onReadyReadStandardOutput) self.vagrant_process.readyReadStandardError.connect( self.onReadyReadStandardError)
def begin_process(self): process_name = 'InvertedPendulum.py' print('Connecting Process') self.process = QTC.QProcess(self.qmainwindow) #Signals to trigger events self.process.readyRead.connect(lambda: self.stdoutReady()) #triggers when something is flushed to prompt #self.process.readyReadStandardOutput(lambda: self.stdoutReady()) #self.process.readyReadStandardError.connect(lambda: self.stderrReady()) #signals to signal begin and end self.process.started.connect(lambda: print('Started!', flush= True)) self.process.finished.connect(lambda: print('Finished!', flush= True)) print('Starting process', flush = True) self.process.start('python', [process_name]) #starting the process #updating the image self.img = Image_plot() self.th = Th(self.img) self.th.start() self.process.finished.connect(self.th.raise_exception) #terminate the Thread that uploads image
def launch(self, annotation_data, org_file, anno_type): self.cspr_file = org_file self.db_file = org_file[:org_file.find('.')] + '_repeats.db' self.anno_data = annotation_data self.kegg_nonKegg = anno_type self.process = QtCore.QProcess() self.parser.fileName = org_file # setting the path and file name fields index1 = self.cspr_file.find('.') if platform.system() == "Windows": index2 = self.cspr_file.rfind('\\') else: index2 = self.cspr_file.rfind('/') self.filename_input.setText(self.cspr_file[index2 + 1:index1] + '_lib') if platform.system() == "Windows": self.output_path.setText(GlobalSettings.CSPR_DB + "\\") else: self.output_path.setText(GlobalSettings.CSPR_DB + "/") # depending on the type of file, build the dictionary accordingly self.build_dict_non_kegg() # get the gRNA data from the cspr file self.cspr_data = self.parser.gen_lib_parser(self.gen_lib_dict, GlobalSettings.mainWindow.endoChoice.currentText()) self.get_endo_data() self.show()
def __init__(self, parent=None): super(ScrapyWorker, self).__init__(parent) self._process = QtCore.QProcess(self) self._process.setProcessChannelMode(QtCore.QProcess.MergedChannels) self._process.readyReadStandardOutput.connect(self.on_readyReadStandardOutput) self._process.started.connect(self.started) self._process.finished.connect(self.finished)
def make_verilator(self): self.cur_dir = os.getcwd() print("Make Verilator.............") os.chdir(self.modelpath) if os.path.exists(self.modelpath + "../verilated.o"): os.remove(self.modelpath + "../verilated.o") if os.name == 'nt': # path to msys home directory self.msys_home = self.parser.get('COMPILER', 'MSYS_HOME') self.cmd = self.msys_home + "/mingw64/bin/mingw32-make.exe" else: self.cmd = "make" self.cmd = self.cmd + " -f V" + self.fname.split('.')[0]\ + ".mk V" + self.fname.split( '.')[0] + "__ALL.a sim_main_" \ + self.fname.split('.')[0] + ".o ../verilated.o" self.process = QtCore.QProcess(self) self.process.readyReadStandardOutput.connect(self.readAllStandard) self.process.start('sh', ['-c', self.cmd]) self.termtitle("MAKE VERILATOR") self.termtext("Current Directory: " + self.modelpath) self.termtext("Command: " + self.cmd) self.process \ .readyReadStandardOutput.connect(self.readAllStandard) self.process \ .readyReadStandardError.connect(self.readAllStandard) self.process.waitForFinished(50000) print("Make Verilator Executed") os.chdir(self.cur_dir)
def info_play(self): proc = QtCore.QProcess() proc.started.connect(self.started) proc.readyReadStandardOutput.connect(partial(self.data_ready, proc)) proc.finished.connect(self.finished) QtCore.QTimer.singleShot(100, partial(proc.start, " ".join(self.command)))
def launch_merge_tool(self): items = self.conflicts_list.selectedItems() enabled, error_msg = self.is_merge_tool_launchable() if not enabled: return config = GlobalConfig() cmdline = config.find_merge_tool( str(self.merge_tools_combo.currentText())) file_id = items[0].data(0, QtCore.Qt.UserRole) if not file_id: # bug https://bugs.launchpad.net/qbrz/+bug/655451 return file_name = self.wt.abspath(self.wt.id2path(file_id)) process = QtCore.QProcess(self) def qprocess_invoker(executable, args, cleanup): def qprocess_error(error): self.show_merge_tool_error(error) cleanup(process.exitCode()) def qprocess_finished(exit_code, exit_status): cleanup(exit_code) process.error[QProcess.ProcessError].connect(qprocess_error) process.finished[int, QProcess.ExitStatus].connect(qprocess_finished) process.start(executable, args) mergetools.invoke(cmdline, file_name, qprocess_invoker)
def __clickHtml(self) -> None: """ Emit 'htmlClicked' SIGNAL. """ process = QtCore.QProcess(self) process.start('xdg-open', [self._vulnerability.generateHtml()]) self.htmlClicked.emit()
def __init__(self,parent=None): super().__init__(parent=None) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.tabs = self.ui.tabWidget self.setWindowTitle('主窗口') self.setWindowIcon(QIcon(':/ico/trex.png')) self.settings = QtCore.QSettings("miner_config.ini", QtCore.QSettings.IniFormat) # self.ui.coinkind_comboBox.setCurrentIndex(7) #设置以太币为默认值 self.ui.startmine_pushButton.setEnabled(False) self.ui.findprogram_pushButton.clicked.connect(self.findProgram) self.ui.startmine_pushButton.clicked.connect(self.startRun) self.ui.coinkind_comboBox.currentTextChanged.connect(self.getCoin) self.ui.link_comboBox.currentTextChanged.connect(self.getLink) self.ui.server_lineEdit.textEdited.connect(self.getServerIp) self.ui.port_lineEdit.textEdited.connect(self.getPort) self.ui.wallet_lineEdit.textChanged.connect(self.getWallet) self.refill() #还原记录的数据到GUI界面 self.process = QtCore.QProcess() self.process.readyReadStandardOutput.connect(self.addStdOut)
def __clickFolder(self) -> None: """ Emit 'folderClicked' SIGNAL. """ process = QtCore.QProcess(self) process.start('xdg-open', [self._vulnerability.absolutePath()]) self.folderClicked.emit()
def show_help(self, help_topic=None): # open qt assistant for help if HelpHandler.help_process: if HelpHandler.help_process.state( ) == HelpHandler.help_process.NotRunning: HelpHandler.help_process.close() HelpHandler.help_process = None if not HelpHandler.help_process: HelpHandler.help_process = QtCore.QProcess() HelpHandler.help_process.start( HelpHandler.help_assistant_executable, HelpHandler.help_assistant_arguments) # If there is a help_topic specified as an argument, use it. # Otherwise if self.listen_here_for_help_key.help_topic is specified, use that topic. if not help_topic and hasattr(self.listen_here_for_help_key, "help_topic"): help_topic = self.listen_here_for_help_key.help_topic # If we found a topic, open it, otherwise help is already open from above, just leave it open. if help_topic: # Trim leading slashes and backslashes while help_topic.startswith('/') or help_topic.startswith('\\'): help_topic = help_topic[1:] # set to the right page help_command = QtCore.QByteArray() help_command.append("setSource qthelp://" + help_topic + '\n') HelpHandler.help_process.write(help_command)
def setSsh(self): self.timer.stop() print("setSsh") action = "stop" if self.ssh_cb.isChecked() is True: # Note: we get called before the checkbox has been toggled, hence this is correct action = "start" proc = QtCore.QProcess() # First, enable/disable command = 'sysrc' if action == "start": yn = "YES" else: yn = "NO" args = ["sshd_enable=" + yn] proc.start(command, args) proc.waitForFinished() # Second, start/stop command = 'service' args = ["sshd", action] try: proc.start(command, args) proc.waitForFinished() print(str(proc.readAllStandardOutput(), 'utf-8')).strip() print(str(proc.readAllStandardError(), 'utf-8')).strip() except: # FIXME: do not use bare 'except' pass self.onTimer() # Make sure the new state is immediately reflected self.timer.start()
def initProcess(self): self.process = QtCore.QProcess(self) self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels) self.process.readyRead.connect(self.dataReady) self.process.started.connect(self.disableButtons) self.process.finished.connect(self.enableButtons)
def download(self): print("Download started") self.pushButton.setVisible(False) import glob partitions = glob.glob(self.save_loc + "*") print("Trying to unmount %s*" % partitions) # Unmount all partitions on the target disk proc = QtCore.QProcess() command = '/sbin/umount' args = partitions print(command, args) try: proc.startDetached(command, args) except: wizard.showErrorPage("Could not unmount parititons.") proc.waitForFinished() # Download and write directly to the device try: urllib.request.urlretrieve(wizard.selected_iso_url, self.save_loc, self.handleProgress) except: wizard.showErrorPage("An error occured while trying to write the image. Were all partitions unmounted? Do you have write permissions there?") wizard.next()
def __init__(self): super(OffTarget, self).__init__() uic.loadUi(GlobalSettings.appdir + '\OffTargetAnalysis.ui', self) self.setWindowTitle("Off-Target Analysis") self.show() self.progressBar.setMinimum(0) self.progressBar.setMaximum(100) self.progressBar.reset() self.Run.clicked.connect(self.run_analysis) self.tolerancehorizontalSlider.valueChanged.connect(self.tol_change) self.tolerancehorizontalSlider.setMaximum(100) self.tolerancehorizontalSlider.setMinimum(0) self.tolerance = 0.0 self.tolerancelineEdit.setText("0") self.pushButton.clicked.connect(self.tol_change) self.cancelButton.clicked.connect(self.exit) self.fill_data_dropdown() self.perc = False self.bool_temp = False self.running = False self.process = QtCore.QProcess() # make sure to intialize the class variable in init. That way elsewhere and other classes can access it self.output_path = ''
def init_t_ct(self): self.t_ct_log_dir_line.setText(os.path.join(os.getcwd(), 'runs')) self.t_ct_open_path_button.clicked.connect( lambda: self.file_dialog2line_text(self.t_ct_log_dir_line, if_folder=False, file_filter='(*.pth)')) self.t_ct_log_dir_line.textChanged.connect( self.t_ct_log_dir_on_text_changed) os.system('tmux kill-session -t continue_session') self.process = QtCore.QProcess(self) self.process.start("xterm", [ "-fa", "Monospace", "-fs", "14", "-into", f"{int(self.t_ct_term_cont.winId())}", '-e', 'tmux', 'new', '-s', 'continue_session', ]) self.t_ct_tr_button.clicked.connect( lambda: os.system(f"tmux send-key -t continue_session " f"\" python cwgan_gp.py --data " f"{self.t_ct_data_combobox.currentText()} " f"--recover " f"--checkpoint-file " f"{self.t_ct_log_dir_line.text()} \" " f"Enter")) self.t_ct_stop_button.clicked.connect( lambda: os.system(f"tmux send-key -t continue_session C-c ")) return
def runMake(self): print("run Make Called") self.release_home = self.parser.get('NGHDL', 'RELEASE') path_icm = os.path.join(self.release_home, "src/xspice/icm") os.chdir(path_icm) try: if os.name == 'nt': # path to msys home directory self.msys_home = self.parser.get('COMPILER', 'MSYS_HOME') self.cmd = self.msys_home + "/mingw64/bin/mingw32-make.exe" else: self.cmd = "make" print("Running Make command in " + path_icm) self.process = QtCore.QProcess(self) self.process.start('sh', ['-c', self.cmd]) print("make command process pid ---------- >", self.process.pid()) self.termtitle("MAKE COMMAND") self.termtext("Current Directory: " + path_icm) self.termtext("Command: " + self.cmd) self.process \ .readyReadStandardOutput.connect(self.readAllStandard) self.process \ .readyReadStandardError.connect(self.readAllStandard) self.process.waitForFinished(50000) os.chdir(self.cur_dir) except BaseException: print("There is error in 'make' ")
def __clickFile(self) -> None: """ Emit 'fileClicked' SIGNAL. """ process = QtCore.QProcess(self) process.start('xdg-open', [self._vulnerability.databasePath()]) self.fileClicked.emit()
def startAssistant(self): if self.proc is None: self.proc = QtCore.QProcess() if self.proc.state() != QtCore.QProcess.Running: app = (QtCore.QLibraryInfo.location( QtCore.QLibraryInfo.BinariesPath) + QtCore.QDir.separator()) if platform.system() != "Darwin": app += "assistant" else: app += "Assistant.app/Contents/MacOS/Assistant" args = [ "-collectionFile", QtCore.QLibraryInfo.location( QtCore.QLibraryInfo.ExamplesPath) + "/assistant/simpletextviewer/documentation/simpletextviewer.qhc", "-enableRemoteControl", ] self.proc.start(app, args) if not self.proc.waitForStarted(): QtWidgets.QMessageBox.critical( None, "Simple Text Viewer", "Unable to launch Qt Assistant (%s)" % (app, ), ) return False return True
def callback(self): """Run the button's callback function Commands are called in a separate thread using QProcess. This way, they can indicate to us when they are finished, or if they ran correctly, using signals. XDG commands in desktop files sometimes have placeholder arguments like '%u' or '%f'. We're going to strip these out, because they have no meaning in the context of a button-push. """ self.error_log.clear() self.output_log.clear() self.command = ' '.join( x for x in self.command.split() if x not in ('%f', '%F', '%u', '%U') ) self.process = qtc.QProcess() # cannot be a kwarg self.process.setWorkingDirectory(qtc.QDir.homePath()) self.process.finished.connect(self.enable) self.process.errorOccurred.connect(self.enable_with_error) # This should log standard error and standard output # Doesn't always catch stuff though. self.process.readyReadStandardError.connect(self.log_error) self.process.readyReadStandardOutput.connect(self.log_output) self.process.start(self.command) if not self.process.state() == qtc.QProcess.NotRunning: # Disable the button to prevent users clicking # 200 times waiting on a slow program. self.setDisabled(True)
def __init__(self, parent): super().__init__(parent) # Start Access Point Button self.startAPButton = widget.QPushButton("Start AP", self) self.startAPButton.setGeometry(core.QRect(10, 10, 60, 28)) self.startAPButton.clicked.connect(self.startAP) self.startAPButton.setStyleSheet("font-size: 11px;") # Stop Access Point Button self.stopAPButton = widget.QPushButton("Stop AP", self) self.stopAPButton.setGeometry(core.QRect(80, 10, 60, 28)) self.stopAPButton.setStyleSheet("font-size: 11px;") self.stopAPButton.clicked.connect(self.stopAP) checkMon = subprocess.getoutput("iwconfig") # Checks if AP is already started and sets buttons correctly if "Mode:Master" in checkMon: self.startAPButton.setStyleSheet( "font-size:11px; border:1px solid green;") self.startAPButton.setDisabled(True) self.stopAPButton.setDisabled(False) else: self.stopAPButton.setStyleSheet( "font-size:11px;border:1px solid red;") self.startAPButton.setDisabled(False) self.stopAPButton.setDisabled(True) # Refresh Connected Clients Button self.reClients = widget.QPushButton("Refresh", self) self.reClients.setGeometry(core.QRect(150, 10, 60, 28)) self.reClients.setStyleSheet("font-size: 11px;") self.reClients.clicked.connect(self.refreshAP) # Exit Button self.exitButton = widget.QPushButton("Exit", self) self.exitButton.setGeometry(core.QRect(210, 10, 60, 28)) self.exitButton.clicked.connect(self.closeWindow) self.exitButton.setStyleSheet("font-size: 11px;") # Connected Clients Table self.getClientsTable = widget.QTableWidget(self) self.getClientsTable.setGeometry(core.QRect(10, 50, 260, 100)) self.getClientsTable.setColumnCount(3) self.rowCount = 1 self.getClientsTable.setRowCount(self.rowCount) self.getClientsTable.setStyleSheet("font-size: 9px") self.getClientsTable.setHorizontalHeaderLabels( ["MAC", "IP", "Hostname"]) self.getClientsTable.resizeColumnsToContents() # AP Process (to call create_ap) self.apProcess = core.QProcess(self) # Resize Window self.resize(300, 200) self.showMaximized()
def __init__(self, parent=MainWindow): super(SequentialManager, self).__init__(parent) self.cancel = "false" self.process = QtCore.QProcess(self) self.process.finished.connect(self.handleFinished) self.process.readyReadStandardOutput.connect( self.onReadyReadStandardOutput) self.parent().killbutton.clicked.connect(self.candownPressed)
def __init__(self, *args): QtWidgets.QWidget.__init__(self, *args) self.process = QtCore.QProcess(self) self.terminal = QtWidgets.QWidget(self) layout = QtWidgets.QVBoxLayout(self) layout.addWidget(self.terminal) self.setFixedSize(555, 425) self.process.start('urxvt', ['-embed', str(int(self.winId()))])
def __run_command(app, cmd, all_args, working_dir): all_args = [str(arg) for arg in all_args] app.log.info('%s %s' % (cmd, ' '.join(all_args))) proc = QtCore.QProcess() proc.setStandardInputFile(proc.nullDevice()) proc.setStandardOutputFile(proc.nullDevice()) proc.setStandardErrorFile(proc.nullDevice()) proc.startDetached(cmd, all_args, str(working_dir))
def invoke(self, cmd, background=False, decode=True): """ :param cmd: 命令行 :param background: 如果是常驻进程则为 True :return: """ # if not self.stop_refresh(): return # self.comboBoxAdd() if not self.device_list: self.Terminal.appendPlainText('命令执行失败,当前没有连接设备,请点击右侧"获取设备"按钮,尝试获取设备。') return False try: if not self.stop_refresh(): return cmd_str = ' '.join(cmd) if isinstance(cmd, list) else cmd self.groupCenter.setTitle("执行命令:{}".format(cmd_str)) self.Terminal.appendPlainText('正在执行命令: {}'.format(cmd_str)) if background: self.process = QtCore.QProcess() self.process.start(cmd[0], cmd[1:]) self.process.readyRead.connect(self.data_ready_process) self.process.finished.connect(self.process_finished) else: my_process = QtCore.QProcess() my_process.start(cmd[0], cmd[1:]) my_process.waitForFinished() errors = my_process.readAllStandardError() output = my_process.readAllStandardOutput() if errors: errors = str(errors, encoding='utf-8') self.Terminal.appendPlainText('命令执行执行失败:{0}'.format(errors)) return False if output: if decode: output = str(output, encoding='utf-8') self.Terminal.appendPlainText('执行结果:') self.Terminal.appendPlainText(output) self.Terminal.moveCursor(QTextCursor.End) else: output = bytes(output) return output my_process.close() return True except Exception as E: self.Terminal.appendPlainText('命令执行出错:{0}'.format(E)) return False
def __init__(self, parent=None): super(MyApp, self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.process = QtCore.QProcess(self) self.ui.pushButton.clicked.connect(self.start_process) self.ui.pushButton_2.clicked.connect(self.stop_process) self._pid = -1
def __init__(self, command, projPath): """ - Creates constructor for NgspiceWidget class. - Checks whether OS is Linux or Windows and creates Ngspice window accordingly. """ QtWidgets.QWidget.__init__(self) self.obj_appconfig = Appconfig() self.process = QtCore.QProcess(self) self.terminal = QtWidgets.QWidget(self) self.layout = QtWidgets.QVBoxLayout(self) self.layout.addWidget(self.terminal) print("Argument to ngspice command : ", command) if os.name == 'nt': # For Windows OS parser_nghdl = ConfigParser() parser_nghdl.read( os.path.join('library', 'config', '.nghdl', 'config.ini')) msys_home = parser_nghdl.get('COMPILER', 'MSYS_HOME') tempdir = os.getcwd() projPath = self.obj_appconfig.current_project["ProjectName"] os.chdir(projPath) self.command = 'cmd /c '+'"start /min ' + \ msys_home + "/usr/bin/mintty.exe ngspice -p " + command + '"' self.process.start(self.command) os.chdir(tempdir) else: # For Linux OS self.command = "cd " + projPath + \ ";ngspice -r " + command.replace(".cir.out", ".raw") + \ " " + command # Creating argument for process self.args = ['-hold', '-e', self.command] self.process.start('xterm', self.args) self.obj_appconfig.process_obj.append(self.process) print(self.obj_appconfig.proc_dict) (self.obj_appconfig.proc_dict[ self.obj_appconfig.current_project['ProjectName']].append( self.process.pid())) self.process = QtCore.QProcess(self) self.command = "gaw " + command.replace(".cir.out", ".raw") self.process.start('sh', ['-c', self.command]) print(self.command)
def reveal(path): proc = QtCore.QProcess() if sys.platform.startswith('darwin'): proc.startDetached('open', ['--', path]) elif sys.platform.startswith('linux'): proc.startDetached('xdg-open', ['--', path]) elif sys.platform.startswith('win32'): proc.startDetached('explorer', [path.replace('/', '\\')])
def _remind_now(self): process = QtCore.QProcess() process.start("gcalcli", ["remind", "10", "echo %s"]) process.waitForFinished() remind_text = process.readAllStandardOutput().data().decode('utf8') if remind_text: self._show_notification(remind_text) self._update_agenda()