本文整理汇总了Python中qtpy.QtCore.QProcess.systemEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Python QProcess.systemEnvironment方法的具体用法?Python QProcess.systemEnvironment怎么用?Python QProcess.systemEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtCore.QProcess
的用法示例。
在下文中一共展示了QProcess.systemEnvironment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _prepare_process
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import systemEnvironment [as 别名]
def _prepare_process(self, config, pythonpath):
"""
Prepare and return process for running the unit test suite.
This sets the working directory and environment.
"""
process = QProcess(self)
process.setProcessChannelMode(QProcess.MergedChannels)
process.setWorkingDirectory(config.wdir)
process.finished.connect(self.finished)
if pythonpath is not None:
env = [
to_text_string(_pth)
for _pth in process.systemEnvironment()
]
add_pathlist_to_PYTHONPATH(env, pythonpath)
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
process.setProcessEnvironment(processEnvironment)
return process
示例2: LineProfilerWidget
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import systemEnvironment [as 别名]
#.........这里部分代码省略.........
if self.error_output:
TextEditor(self.error_output, title=_("Line profiler output"),
readonly=True, size=(700, 500)).exec_()
def start(self, wdir=None, args=None, pythonpath=None):
filename = to_text_string(self.filecombo.currentText())
if wdir is None:
wdir = self._last_wdir
if wdir is None:
wdir = osp.basename(filename)
if args is None:
args = self._last_args
if args is None:
args = []
if pythonpath is None:
pythonpath = self._last_pythonpath
self._last_wdir = wdir
self._last_args = args
self._last_pythonpath = pythonpath
self.datelabel.setText(_('Profiling, please wait...'))
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(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)
示例3: ProfilerWidget
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import systemEnvironment [as 别名]
#.........这里部分代码省略.........
TextEditor(self.error_output, title=_("Profiler output"),
readonly=True, size=(700, 500)).exec_()
def start(self, wdir=None, args=None, pythonpath=None):
filename = to_text_string(self.filecombo.currentText())
if wdir is None:
wdir = self._last_wdir
if wdir is None:
wdir = osp.basename(filename)
if args is None:
args = self._last_args
if args is None:
args = []
if pythonpath is None:
pythonpath = self._last_pythonpath
self._last_wdir = wdir
self._last_args = args
self._last_pythonpath = pythonpath
self.datelabel.setText(_('Profiling, please wait...'))
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"))
示例4: ExternalSystemShell
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import systemEnvironment [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 finish_process(self):
while not self.process.waitForFinished(100):
self.process.kill();
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):
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
#.........这里部分代码省略.........
示例5: AsyncClient
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import systemEnvironment [as 别名]
class AsyncClient(QObject):
"""
A class which handles a connection to a client through a QProcess.
"""
# Emitted when the client has initialized.
initialized = Signal()
# Emitted when the client errors.
errored = Signal()
# Emitted when a request response is received.
received = Signal(object)
def __init__(self, target, executable=None, name=None,
extra_args=None, libs=None, cwd=None, env=None):
super(AsyncClient, self).__init__()
self.executable = executable or sys.executable
self.extra_args = extra_args
self.target = target
self.name = name or self
self.libs = libs
self.cwd = cwd
self.env = env
self.is_initialized = False
self.closing = False
self.context = zmq.Context()
QApplication.instance().aboutToQuit.connect(self.close)
# Set up the heartbeat timer.
self.timer = QTimer(self)
self.timer.timeout.connect(self._heartbeat)
def run(self):
"""Handle the connection with the server.
"""
# Set up the zmq port.
self.socket = self.context.socket(zmq.PAIR)
self.port = self.socket.bind_to_random_port('tcp://*')
# Set up the process.
self.process = QProcess(self)
if self.cwd:
self.process.setWorkingDirectory(self.cwd)
p_args = ['-u', self.target, str(self.port)]
if self.extra_args is not None:
p_args += self.extra_args
# Set up environment variables.
processEnvironment = QProcessEnvironment()
env = self.process.systemEnvironment()
if (self.env and 'PYTHONPATH' not in self.env) or DEV:
python_path = osp.dirname(get_module_path('spyderlib'))
# Add the libs to the python path.
for lib in self.libs:
try:
path = osp.dirname(imp.find_module(lib)[1])
python_path = osp.pathsep.join([python_path, path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
if self.env:
env.update(self.env)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
# Start the process and wait for started.
self.process.start(self.executable, p_args)
self.process.finished.connect(self._on_finished)
running = self.process.waitForStarted()
if not running:
raise IOError('Could not start %s' % self)
# Set up the socket notifer.
fid = self.socket.getsockopt(zmq.FD)
self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
self.notifier.activated.connect(self._on_msg_received)
def request(self, func_name, *args, **kwargs):
"""Send a request to the server.
The response will be a dictionary the 'request_id' and the
'func_name' as well as a 'result' field with the object returned by
the function call or or an 'error' field with a traceback.
"""
if not self.is_initialized:
return
request_id = uuid.uuid4().hex
request = dict(func_name=func_name,
args=args,
kwargs=kwargs,
request_id=request_id)
self._send(request)
return request_id
def close(self):
"""Cleanly close the connection to the server.
#.........这里部分代码省略.........
示例6: ExternalPythonShell
# 需要导入模块: from qtpy.QtCore import QProcess [as 别名]
# 或者: from qtpy.QtCore.QProcess import systemEnvironment [as 别名]
#.........这里部分代码省略.........
if self.notification_thread is not None:
self.notification_thread.refresh_namespace_browser.connect(
self.namespacebrowser.refresh_table)
signal = self.notification_thread.sig_process_remote_view
signal.connect(lambda data:
self.namespacebrowser.process_remote_view(data))
def create_process(self):
self.shell.clear()
self.process = QProcess(self)
if self.merge_output_channels:
self.process.setProcessChannelMode(QProcess.MergedChannels)
else:
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.shell.wait_for_ready_read.connect(
lambda: self.process.waitForReadyRead(250))
# Working directory
if self.wdir is not None:
self.process.setWorkingDirectory(self.wdir)
#-------------------------Python specific------------------------------
# Python arguments
p_args = ['-u']
if DEBUG >= 3:
p_args += ['-v']
p_args += get_python_args(self.fname, self.python_args,
self.interact_action.isChecked(),
self.debug_action.isChecked(),
self.arguments)
env = [to_text_string(_path)
for _path in self.process.systemEnvironment()]
if self.pythonstartup:
env.append('PYTHONSTARTUP=%s' % self.pythonstartup)
#-------------------------Python specific-------------------------------
# Post mortem debugging
if self.post_mortem_action.isChecked():
env.append('SPYDER_EXCEPTHOOK=True')
# Set standard input/output encoding for Python consoles
# (IPython handles it on its own)
# See http://stackoverflow.com/q/26312400/438386, specifically
# the comments of Martijn Pieters
if not self.is_ipykernel:
env.append('PYTHONIOENCODING=UTF-8')
# Monitor
if self.monitor_enabled:
env.append('SPYDER_SHELL_ID=%s' % id(self))
env.append('SPYDER_AR_TIMEOUT=%d' % self.autorefresh_timeout)
env.append('SPYDER_AR_STATE=%r' % self.autorefresh_state)
from spyderlib.widgets.externalshell import introspection
introspection_server = introspection.start_introspection_server()
introspection_server.register(self)
notification_server = introspection.start_notification_server()
self.notification_thread = notification_server.register(self)
self.notification_thread.sig_pdb.connect(
lambda fname, lineno:
self.sig_pdb.emit(fname, lineno))
self.notification_thread.new_ipython_kernel.connect(
lambda args:
self.create_ipython_client.emit(args))
self.notification_thread.open_file.connect(