本文整理汇总了Python中qtpy.QtCore.QProcess.setReadChannel方法的典型用法代码示例。如果您正苦于以下问题:Python QProcess.setReadChannel方法的具体用法?Python QProcess.setReadChannel怎么用?Python QProcess.setReadChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtCore.QProcess
的用法示例。
在下文中一共展示了QProcess.setReadChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PylintWidget
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import setReadChannel [as 别名]
#.........这里部分代码省略.........
self.finished(ec, es))
self.stop_button.clicked.connect(self.process.kill)
self.output = ''
self.error_output = ''
plver = PYLINT_VER
if plver is not None:
p_args = ['-m', 'pylint', '--output-format=text']
if plver.split('.')[0] == '0':
p_args += ['-i', 'yes']
else:
# Option '-i' (alias for '--include-ids') was removed in pylint
# 1.0
p_args += ["--msg-template='{msg_id}:{line:3d},"\
"{column}: {obj}: {msg}"]
p_args += [osp.basename(filename)]
else:
p_args = [osp.basename(filename)]
self.process.start(sys.executable, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
def set_running_state(self, state=True):
self.start_button.setEnabled(not state)
self.stop_button.setEnabled(state)
def read_output(self, error=False):
if error:
self.process.setReadChannel(QProcess.StandardError)
else:
self.process.setReadChannel(QProcess.StandardOutput)
qba = QByteArray()
while self.process.bytesAvailable():
if error:
qba += self.process.readAllStandardError()
else:
qba += self.process.readAllStandardOutput()
text = to_text_string( locale_codec.toUnicode(qba.data()) )
if error:
self.error_output += text
else:
self.output += text
def finished(self, exit_code, exit_status):
self.set_running_state(False)
if not self.output:
if self.error_output:
QMessageBox.critical(self, _("Error"), self.error_output)
print("pylint error:\n\n" + self.error_output, file=sys.stderr)
return
# Convention, Refactor, Warning, Error
results = {'C:': [], 'R:': [], 'W:': [], 'E:': []}
txt_module = '************* Module '
module = '' # Should not be needed - just in case something goes wrong
for line in self.output.splitlines():
if line.startswith(txt_module):
# New module
module = line[len(txt_module):]
continue
示例2: ProfilerWidget
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import setReadChannel [as 别名]
#.........这里部分代码省略.........
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.process.setWorkingDirectory(wdir)
self.process.readyReadStandardOutput.connect(self.read_output)
self.process.readyReadStandardError.connect(
lambda: self.read_output(error=True))
self.process.finished.connect(lambda ec, es=QProcess.ExitStatus:
self.finished(ec, es))
self.stop_button.clicked.connect(self.process.kill)
if pythonpath is not None:
env = [to_text_string(_pth)
for _pth in self.process.systemEnvironment()]
baseshell.add_pathlist_to_PYTHONPATH(env, pythonpath)
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
self.output = ''
self.error_output = ''
p_args = ['-m', 'cProfile', '-o', self.DATAPATH]
if os.name == 'nt':
# On Windows, one has to replace backslashes by slashes to avoid
# confusion with escape characters (otherwise, for example, '\t'
# will be interpreted as a tabulation):
p_args.append(osp.normpath(filename).replace(os.sep, '/'))
else:
p_args.append(filename)
if args:
p_args.extend(shell_split(args))
executable = sys.executable
if executable.endswith("spyder.exe"):
# py2exe distribution
executable = "python.exe"
self.process.start(executable, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
def set_running_state(self, state=True):
self.start_button.setEnabled(not state)
self.stop_button.setEnabled(state)
def read_output(self, error=False):
if error:
self.process.setReadChannel(QProcess.StandardError)
else:
self.process.setReadChannel(QProcess.StandardOutput)
qba = QByteArray()
while self.process.bytesAvailable():
if error:
qba += self.process.readAllStandardError()
else:
qba += self.process.readAllStandardOutput()
text = to_text_string( locale_codec.toUnicode(qba.data()) )
if error:
self.error_output += text
else:
self.output += text
def finished(self, exit_code, exit_status):
self.set_running_state(False)
self.show_errorlog() # If errors occurred, show them.
self.output = self.error_output + self.output
# FIXME: figure out if show_data should be called here or
# as a signal from the combobox
self.show_data(justanalyzed=True)
def kill_if_running(self):
if self.process is not None:
if self.process.state() == QProcess.Running:
self.process.kill()
self.process.waitForFinished()
def show_data(self, justanalyzed=False):
if not justanalyzed:
self.output = None
self.log_button.setEnabled(self.output is not None \
and len(self.output) > 0)
self.kill_if_running()
filename = to_text_string(self.filecombo.currentText())
if not filename:
return
self.datelabel.setText(_('Sorting data, please wait...'))
QApplication.processEvents()
self.datatree.load_data(self.DATAPATH)
self.datatree.show_tree()
text_style = "<span style=\'color: #444444\'><b>%s </b></span>"
date_text = text_style % time.strftime("%d %b %Y %H:%M",
time.localtime())
self.datelabel.setText(date_text)
示例3: LineProfilerWidget
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import setReadChannel [as 别名]
#.........这里部分代码省略.........
self.process.setWorkingDirectory(wdir)
self.process.readyReadStandardOutput.connect(self.read_output)
self.process.readyReadStandardError.connect(
lambda: self.read_output(error=True))
self.process.finished.connect(self.finished)
self.stop_button.clicked.connect(self.process.kill)
if pythonpath is not None:
env = [to_text_string(_pth)
for _pth in self.process.systemEnvironment()]
add_pathlist_to_PYTHONPATH(env, pythonpath)
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
self.output = ''
self.error_output = ''
if os.name == 'nt':
# On Windows, one has to replace backslashes by slashes to avoid
# confusion with escape characters (otherwise, for example, '\t'
# will be interpreted as a tabulation):
filename = osp.normpath(filename).replace(os.sep, '/')
p_args = ['-lvb', '-o', '"' + self.DATAPATH + '"',
'"' + filename + '"']
if args:
p_args.extend(programs.shell_split(args))
executable = '"' + programs.find_program('kernprof') + '"'
executable += ' ' + ' '.join(p_args)
executable = executable.replace(os.sep, '/')
self.process.start(executable)
else:
p_args = ['-lvb', '-o', self.DATAPATH, filename]
if args:
p_args.extend(programs.shell_split(args))
executable = 'kernprof'
self.process.start(executable, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
def set_running_state(self, state=True):
self.start_button.setEnabled(not state)
self.stop_button.setEnabled(state)
def read_output(self, error=False):
if error:
self.process.setReadChannel(QProcess.StandardError)
else:
self.process.setReadChannel(QProcess.StandardOutput)
qba = QByteArray()
while self.process.bytesAvailable():
if error:
qba += self.process.readAllStandardError()
else:
qba += self.process.readAllStandardOutput()
text = to_text_string(locale_codec.toUnicode(qba.data()))
if error:
self.error_output += text
else:
self.output += text
def finished(self):
self.set_running_state(False)
self.show_errorlog() # If errors occurred, show them.
self.output = self.error_output + self.output
# FIXME: figure out if show_data should be called here or
# as a signal from the combobox
self.show_data(justanalyzed=True)
def kill_if_running(self):
if self.process is not None:
if self.process.state() == QProcess.Running:
self.process.kill()
self.process.waitForFinished()
def show_data(self, justanalyzed=False):
if not justanalyzed:
self.output = None
self.log_button.setEnabled(
self.output is not None and len(self.output) > 0)
self.kill_if_running()
filename = to_text_string(self.filecombo.currentText())
if not filename:
return
self.datatree.load_data(self.DATAPATH)
self.datelabel.setText(_('Sorting data, please wait...'))
QApplication.processEvents()
self.datatree.show_tree()
text_style = "<span style=\'color: #444444\'><b>%s </b></span>"
date_text = text_style % time.strftime("%d %b %Y %H:%M",
time.localtime())
self.datelabel.setText(date_text)
示例4: ExternalPythonShell
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import setReadChannel [as 别名]
#.........这里部分代码省略.........
self.process.start(self.pythonexecutable, p_args)
#-------------------------Python specific------------------------------
running = self.process.waitForStarted(3000)
self.set_running_state(running)
if not running:
if self.is_ipykernel:
self.ipython_kernel_start_error.emit(
_("The kernel failed to start!! That's all we know... "
"Please close this console and open a new one."))
else:
QMessageBox.critical(self, _("Error"),
_("A Python console failed to start!"))
else:
self.shell.setFocus()
self.started.emit()
return self.process
def finished(self, exit_code, exit_status):
"""Reimplement ExternalShellBase method"""
if self.is_ipykernel and exit_code == 1:
self.ipython_kernel_start_error.emit(self.shell.get_text_with_eol())
ExternalShellBase.finished(self, exit_code, exit_status)
self.introspection_socket = None
#==============================================================================
# Input/Output
#==============================================================================
def write_error(self):
if os.name == 'nt':
#---This is apparently necessary only on Windows (not sure though):
# emptying standard output buffer before writing error output
self.process.setReadChannel(QProcess.StandardOutput)
if self.process.waitForReadyRead(1):
self.write_output()
self.shell.write_error(self.get_stderr())
QApplication.processEvents()
def send_to_process(self, text):
if not self.is_running():
return
if not is_text_string(text):
text = to_text_string(text)
if self.mpl_backend == 0 and os.name == 'nt' and \
self.introspection_socket is not None:
communicate(self.introspection_socket, "toggle_inputhook_flag(True)")
# # Socket-based alternative (see input hook in sitecustomize.py):
# while self.local_server.hasPendingConnections():
# self.local_server.nextPendingConnection().write('go!')
if any([text == cmd for cmd in ['%ls', '%pwd', '%scientific']]) or \
any([text.startswith(cmd) for cmd in ['%cd ', '%clear ']]):
text = 'evalsc(r"%s")\n' % text
if not text.endswith('\n'):
text += '\n'
self.process.write(to_binary_string(text, 'utf8'))
self.process.waitForBytesWritten(-1)
# Eventually write prompt faster (when hitting Enter continuously)
# -- necessary/working on Windows only:
if os.name == 'nt':
self.write_error()
def keyboard_interrupt(self):
if self.introspection_socket is not None:
communicate(self.introspection_socket, "thread.interrupt_main()")