本文整理汇总了Python中spyderlib.qt.QtCore.QProcess.write方法的典型用法代码示例。如果您正苦于以下问题:Python QProcess.write方法的具体用法?Python QProcess.write怎么用?Python QProcess.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtCore.QProcess
的用法示例。
在下文中一共展示了QProcess.write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExternalPythonShell
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import write [as 别名]
#.........这里部分代码省略.........
if self.pyqt_api:
env.append('PYQT_API=%d' % self.pyqt_api)
env.append('IGNORE_SIP_SETAPI_ERRORS=%s'
% self.ignore_sip_setapi_errors)
# User Module Deleter
if self.is_interpreter:
env.append('UMR_ENABLED=%r' % self.umr_enabled)
env.append('UMR_NAMELIST=%s' % ','.join(self.umr_namelist))
env.append('UMR_VERBOSE=%r' % self.umr_verbose)
env.append('MATPLOTLIB_ION=True')
else:
if self.interact:
env.append('MATPLOTLIB_ION=True')
else:
env.append('MATPLOTLIB_ION=False')
# IPython kernel
env.append('IPYTHON_KERNEL=%r' % self.is_ipykernel)
# Add sitecustomize path to path list
pathlist = []
scpath = osp.dirname(osp.abspath(__file__))
pathlist.append(scpath)
# Adding Spyder path
pathlist += self.path
# Adding path list to PYTHONPATH environment variable
add_pathlist_to_PYTHONPATH(env, pathlist)
#-------------------------Python specific------------------------------
self.process.readyReadStandardOutput.connect(self.write_output)
self.process.readyReadStandardError.connect(self.write_error)
self.process.finished.connect(lambda ec, es=QProcess.ExitStatus:
self.finished(ec, es))
self.sig_finished.connect(self.dialog_manager.close_all)
self.terminate_button.clicked.connect(self.process.terminate)
self.kill_button.clicked.connect(self.process.kill)
#-------------------------Python specific------------------------------
# Fixes for our Mac app:
# 1. PYTHONPATH and PYTHONHOME are set while bootstrapping the app,
# but their values are messing sys.path for external interpreters
# (e.g. EPD) so we need to remove them from the environment.
# 2. Set PYTHONPATH again but without grabbing entries defined in the
# environment (Fixes Issue 1321)
# 3. Remove PYTHONOPTIMIZE from env so that we can have assert
# statements working with our interpreters (See Issue 1281)
if running_in_mac_app():
env.append('SPYDER_INTERPRETER=%s' % self.pythonexecutable)
if MAC_APP_NAME not in self.pythonexecutable:
env = [p for p in env if not (p.startswith('PYTHONPATH') or \
p.startswith('PYTHONHOME'))] # 1.
add_pathlist_to_PYTHONPATH(env, pathlist, drop_env=True) # 2.
env = [p for p in env if not p.startswith('PYTHONOPTIMIZE')] # 3.
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
self.process.start(self.pythonexecutable, p_args)
#-------------------------Python specific------------------------------
示例2: ExternalSystemShell
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import write [as 别名]
class ExternalSystemShell(ExternalShellBase):
"""External Shell widget: execute Python script in a separate process"""
SHELL_CLASS = TerminalWidget
def __init__(self, parent=None, wdir=None, path=[], light_background=True,
menu_actions=None, show_buttons_inside=True,
show_elapsed_time=True):
ExternalShellBase.__init__(self, parent=parent, fname=None, wdir=wdir,
history_filename='.history',
light_background=light_background,
menu_actions=menu_actions,
show_buttons_inside=show_buttons_inside,
show_elapsed_time=show_elapsed_time)
# Additional python path list
self.path = path
# For compatibility with the other shells that can live in the external
# console
self.is_ipykernel = False
self.connection_file = None
def get_icon(self):
return get_icon('cmdprompt.png')
def create_process(self):
self.shell.clear()
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.MergedChannels)
# PYTHONPATH (in case we use Python in this terminal, e.g. py2exe)
env = [to_text_string(_path)
for _path in self.process.systemEnvironment()]
add_pathlist_to_PYTHONPATH(env, self.path)
self.process.setEnvironment(env)
# Working directory
if self.wdir is not None:
self.process.setWorkingDirectory(self.wdir)
# Shell arguments
if os.name == 'nt':
p_args = ['/Q']
else:
p_args = ['-i']
if self.arguments:
p_args.extend( shell_split(self.arguments) )
self.connect(self.process, SIGNAL("readyReadStandardOutput()"),
self.write_output)
self.connect(self.process, SIGNAL("finished(int,QProcess::ExitStatus)"),
self.finished)
self.connect(self.kill_button, SIGNAL("clicked()"),
self.process.kill)
if os.name == 'nt':
self.process.start('cmd.exe', p_args)
else:
# Using bash:
self.process.start('bash', p_args)
self.send_to_process('PS1="\\[email protected]\\h:\\w> "\n')
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
else:
self.shell.setFocus()
self.emit(SIGNAL('started()'))
return self.process
#===============================================================================
# Input/Output
#===============================================================================
def transcode(self, qba):
if os.name == 'nt':
return to_text_string( CP850_CODEC.toUnicode(qba.data()) )
else:
return ExternalShellBase.transcode(self, qba)
def send_to_process(self, text):
if not is_text_string(text):
text = to_text_string(text)
if text[:-1] in ["clear", "cls", "CLS"]:
self.shell.clear()
self.send_to_process(os.linesep)
return
if not text.endswith('\n'):
text += '\n'
if os.name == 'nt':
self.process.write(text.encode('cp850'))
else:
self.process.write(LOCALE_CODEC.fromUnicode(text))
self.process.waitForBytesWritten(-1)
def keyboard_interrupt(self):
#.........这里部分代码省略.........
示例3: ExternalSystemShell
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import write [as 别名]
class ExternalSystemShell(ExternalShellBase):
"""External Shell widget: execute Python script in a separate process"""
SHELL_CLASS = TerminalWidget
started = Signal()
def __init__(
self,
parent=None,
wdir=None,
path=[],
light_background=True,
menu_actions=None,
show_buttons_inside=True,
show_elapsed_time=True,
):
ExternalShellBase.__init__(
self,
parent=parent,
fname=None,
wdir=wdir,
history_filename=".history",
light_background=light_background,
menu_actions=menu_actions,
show_buttons_inside=show_buttons_inside,
show_elapsed_time=show_elapsed_time,
)
# Additional python path list
self.path = path
# For compatibility with the other shells that can live in the external
# console
self.is_ipykernel = False
self.connection_file = None
def get_icon(self):
return ima.icon("cmdprompt")
def create_process(self):
self.shell.clear()
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.MergedChannels)
# PYTHONPATH (in case we use Python in this terminal, e.g. py2exe)
env = [to_text_string(_path) for _path in self.process.systemEnvironment()]
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition("=")
processEnvironment.insert(envName, envValue)
add_pathlist_to_PYTHONPATH(env, self.path)
self.process.setProcessEnvironment(processEnvironment)
# Working directory
if self.wdir is not None:
self.process.setWorkingDirectory(self.wdir)
# Shell arguments
if os.name == "nt":
p_args = ["/Q"]
else:
p_args = ["-i"]
if self.arguments:
p_args.extend(shell_split(self.arguments))
self.process.readyReadStandardOutput.connect(self.write_output)
self.process.finished.connect(self.finished)
self.kill_button.clicked.connect(self.process.kill)
if os.name == "nt":
self.process.start("cmd.exe", p_args)
else:
# Using bash:
self.process.start("bash", p_args)
self.send_to_process('PS1="\\[email protected]\\h:\\w> "\n')
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"), _("Process failed to start"))
else:
self.shell.setFocus()
self.started.emit()
return self.process
# ===============================================================================
# Input/Output
# ===============================================================================
def transcode(self, qba):
if os.name == "nt":
return to_text_string(CP850_CODEC.toUnicode(qba.data()))
else:
return ExternalShellBase.transcode(self, qba)
def send_to_process(self, text):
#.........这里部分代码省略.........
示例4: ExternalPythonShell
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import write [as 别名]
#.........这里部分代码省略.........
env.append('IGNORE_SIP_SETAPI_ERRORS=%s'
% self.ignore_sip_setapi_errors)
# User Module Deleter
if self.is_interpreter:
env.append('UMD_ENABLED=%r' % self.umd_enabled)
env.append('UMD_NAMELIST=%s' % ','.join(self.umd_namelist))
env.append('UMD_VERBOSE=%r' % self.umd_verbose)
# IPython related configuration
if self.is_ipython_shell:
env.append('IPYTHON=True')
# Do not call msvcrt.getch in IPython.genutils.page_more:
env.append('TERM=emacs')
elif self.is_ipython_kernel:
env.append('IPYTHON_KERNEL=True')
pathlist = []
# Fix encoding with custom "sitecustomize.py"
scpath = osp.dirname(osp.abspath(__file__))
pathlist.append(scpath)
# Adding Spyder path
pathlist += self.path
# Adding path list to PYTHONPATH environment variable
add_pathlist_to_PYTHONPATH(env, pathlist)
self.process.setEnvironment(env)
#-------------------------Python specific-------------------------------
self.connect(self.process, SIGNAL("readyReadStandardOutput()"),
self.write_output)
self.connect(self.process, SIGNAL("readyReadStandardError()"),
self.write_error)
self.connect(self.process, SIGNAL("finished(int,QProcess::ExitStatus)"),
self.finished)
self.connect(self, SIGNAL('finished()'), self.dialog_manager.close_all)
self.connect(self.terminate_button, SIGNAL("clicked()"),
self.process.terminate)
self.connect(self.kill_button, SIGNAL("clicked()"),
self.process.kill)
#-------------------------Python specific-------------------------------
executable = self.pythonexecutable
if executable is None:
executable = get_python_executable()
self.process.start(executable, p_args)
#-------------------------Python specific-------------------------------
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
else:
self.shell.setFocus()
self.emit(SIGNAL('started()'))
return self.process
#===============================================================================
# Input/Output