本文整理汇总了Python中spyderlib.qt.QtCore.QProcess类的典型用法代码示例。如果您正苦于以下问题:Python QProcess类的具体用法?Python QProcess怎么用?Python QProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
def start(self):
filename = to_text_string(self.filecombo.currentText())
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.process.setWorkingDirectory(osp.dirname(filename))
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)
self.output = ''
self.error_output = ''
plver = PYLINT_VER
if plver is not None:
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(PYLINT_PATH, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
示例2: start
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.connect(self.process, SIGNAL("readyReadStandardOutput()"),
self.read_output)
self.connect(self.process, SIGNAL("readyReadStandardError()"),
lambda: self.read_output(error=True))
self.connect(self.process,
SIGNAL("finished(int,QProcess::ExitStatus)"),
self.finished)
self.connect(self.stop_button, SIGNAL("clicked()"), 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)
self.process.setEnvironment(env)
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"))
示例3: create_process
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
示例4: create_process
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(r"""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
示例5: run
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)
示例6: start
def start(self):
"""Start a new connection with the plugin.
"""
self._initialized = False
plugin_name = self.plugin_name
self.sock, server_port = connect_to_port()
self.sock.listen(2)
QApplication.instance().aboutToQuit.connect(self.close)
self.process = QProcess(self)
self.process.setWorkingDirectory(os.path.dirname(__file__))
processEnvironment = QProcessEnvironment()
env = self.process.systemEnvironment()
python_path = imp.find_module('spyderlib')[1]
# Use the current version of the plugin provider if possible.
try:
provider_path = imp.find_module(self.plugin_name)[1]
python_path = os.sep.join([python_path, provider_path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
p_args = ['-u', 'plugin_server.py', str(server_port), plugin_name]
self.listener = PluginListener(self.sock)
self.listener.request_handled.connect(self.request_handled.emit)
self.listener.initialized.connect(self._on_initialized)
self.listener.start()
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 plugin %s' % plugin_name)
示例7: ProfilerWidget
#.........这里部分代码省略.........
getcwd(), _("Python scripts")+" (*.py ; *.pyw)")
self.emit(SIGNAL('redirect_stdio(bool)'), False)
if filename:
self.analyze(filename)
def show_log(self):
if self.output:
TextEditor(self.output, title=_("Profiler output"),
readonly=True, size=(700, 500)).exec_()
def show_errorlog(self):
if self.error_output:
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.connect(self.process, SIGNAL("readyReadStandardOutput()"),
self.read_output)
self.connect(self.process, SIGNAL("readyReadStandardError()"),
lambda: self.read_output(error=True))
self.connect(self.process,
SIGNAL("finished(int,QProcess::ExitStatus)"),
self.finished)
self.connect(self.stop_button, SIGNAL("clicked()"), 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)
self.process.setEnvironment(env)
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"):
示例8: PylintWidget
#.........这里部分代码省略.........
def get_filenames(self):
return [filename for filename, _data in self.rdata]
def get_data(self, filename):
filename = osp.abspath(filename)
for index, (fname, data) in enumerate(self.rdata):
if fname == filename:
return index, data
else:
return None, None
def set_data(self, filename, data):
filename = osp.abspath(filename)
index, _data = self.get_data(filename)
if index is not None:
self.rdata.pop(index)
self.rdata.insert(0, (filename, data))
self.save()
def save(self):
while len(self.rdata) > self.max_entries:
self.rdata.pop(-1)
pickle.dump([self.VERSION]+self.rdata, open(self.DATAPATH, 'wb'), 2)
def show_log(self):
if self.output:
TextEditor(self.output, title=_("Pylint output"),
readonly=True, size=(700, 500)).exec_()
def start(self):
filename = to_text_string(self.filecombo.currentText())
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.process.setWorkingDirectory(osp.dirname(filename))
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)
self.output = ''
self.error_output = ''
plver = PYLINT_VER
if plver is not None:
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(PYLINT_PATH, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
示例9: PluginClient
class PluginClient(QObject):
"""
A class which handles a connection to a plugin through a QProcess.
"""
# Emitted when the plugin has initialized.
initialized = Signal()
# Emitted when the plugin has failed to load.
errored = Signal()
# Emitted when a request response is received.
request_handled = Signal(object)
def __init__(self, plugin_name, executable=None):
super(PluginClient, self).__init__()
self.plugin_name = plugin_name
self.executable = executable or sys.executable
self.start()
def start(self):
"""Start a new connection with the plugin.
"""
self._initialized = False
plugin_name = self.plugin_name
self.sock, server_port = connect_to_port()
self.sock.listen(2)
QApplication.instance().aboutToQuit.connect(self.close)
self.process = QProcess(self)
self.process.setWorkingDirectory(os.path.dirname(__file__))
processEnvironment = QProcessEnvironment()
env = self.process.systemEnvironment()
python_path = imp.find_module('spyderlib')[1]
# Use the current version of the plugin provider if possible.
try:
provider_path = imp.find_module(self.plugin_name)[1]
python_path = os.sep.join([python_path, provider_path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
p_args = ['-u', 'plugin_server.py', str(server_port), plugin_name]
self.listener = PluginListener(self.sock)
self.listener.request_handled.connect(self.request_handled.emit)
self.listener.initialized.connect(self._on_initialized)
self.listener.start()
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 plugin %s' % plugin_name)
def send(self, request):
"""Send a request to the plugin.
"""
if not self._initialized:
return
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", self.client_port))
request['plugin_name'] = self.plugin_name
write_packet(sock, request)
sock.close()
def close(self):
self.process.kill()
self.process.waitForFinished(200)
self.sock.close()
def _on_initialized(self, port):
debug_print('Initialized %s' % self.plugin_name)
self._initialized = True
self.client_port = port
self.initialized.emit()
def _on_finished(self):
debug_print('finished %s %s' % (self.plugin_name, self._initialized))
if self._initialized:
self.start()
else:
self._initialized = False
debug_print(self.process.readAllStandardOutput())
debug_print(self.process.readAllStandardError())
self.errored.emit()
示例10: AsyncClient
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)
self.timer.start(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)
try:
self.socket.send_pyobj(request)
except zmq.ZMQError:
pass
#.........这里部分代码省略.........
示例11: ExternalSystemShell
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):
#.........这里部分代码省略.........
示例12: ExternalSystemShell
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):
#.........这里部分代码省略.........
示例13: create_process
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.connect(self.shell, SIGNAL("wait_for_ready_read()"),
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)
# 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.connect(self.notification_thread, SIGNAL('pdb(QString,int)'),
lambda fname, lineno:
self.emit(SIGNAL('pdb(QString,int)'), fname, lineno))
self.connect(self.notification_thread,
SIGNAL('new_ipython_kernel(QString)'),
lambda args:
self.emit(SIGNAL('create_ipython_client(QString)'),
args))
self.connect(self.notification_thread,
SIGNAL('open_file(QString,int)'),
lambda fname, lineno:
self.emit(SIGNAL('open_file(QString,int)'),
fname, lineno))
if self.namespacebrowser is not None:
self.configure_namespacebrowser()
env.append('SPYDER_I_PORT=%d' % introspection_server.port)
env.append('SPYDER_N_PORT=%d' % notification_server.port)
# External modules options
env.append('ETS_TOOLKIT=%s' % self.ets_backend)
if self.mpl_backend:
env.append('MATPLOTLIB_BACKEND=%s' % self.mpl_backend)
if self.qt_api:
env.append('QT_API=%s' % self.qt_api)
env.append('INSTALL_QT_INPUTHOOK=%s' % self.install_qt_inputhook)
env.append('COLORIZE_SYS_STDERR=%s' % self.colorize_sys_stderr)
# # Socket-based alternative (see input hook in sitecustomize.py):
# if self.install_qt_inputhook:
# from PyQt4.QtNetwork import QLocalServer
# self.local_server = QLocalServer()
# self.local_server.listen(str(id(self)))
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('UMD_ENABLED=%r' % self.umd_enabled)
env.append('UMD_NAMELIST=%s' % ','.join(self.umd_namelist))
env.append('UMD_VERBOSE=%r' % self.umd_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)
pathlist = []
# Fix encoding with custom "sitecustomize.py"
scpath = osp.dirname(osp.abspath(__file__))
pathlist.append(scpath)
# Adding Spyder path
pathlist += self.path
#.........这里部分代码省略.........
示例14: create_process
def create_process(self):
self.shell.clear()
self.process = QProcess(self)
if self.merge_output_channels or self.is_ipython_shell:
self.process.setProcessChannelMode(QProcess.MergedChannels)
else:
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.connect(self.shell, SIGNAL("wait_for_ready_read()"),
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'] + get_python_args(self.fname, self.python_args,
self.interact_action.isChecked(),
self.debug_action.isChecked(),
self.arguments)
env = [unicode(_path) for _path in self.process.systemEnvironment()]
if self.pythonstartup:
env.append('PYTHONSTARTUP=%s' % self.pythonstartup)
# 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.connect(self.notification_thread, SIGNAL('pdb(QString,int)'),
lambda fname, lineno:
self.emit(SIGNAL('pdb(QString,int)'), fname, lineno))
self.connect(self.notification_thread,
SIGNAL('new_ipython_kernel(QString)'),
lambda args:
self.emit(SIGNAL('create_ipython_frontend(QString)'),
args))
self.connect(self.notification_thread,
SIGNAL('open_file(QString,int)'),
lambda fname, lineno:
self.emit(SIGNAL('open_file(QString,int)'),
fname, lineno))
if self.namespacebrowser is not None:
self.configure_namespacebrowser()
env.append('SPYDER_I_PORT=%d' % introspection_server.port)
env.append('SPYDER_N_PORT=%d' % notification_server.port)
# External modules options
env.append('ETS_TOOLKIT=%s' % self.ets_backend)
env.append('MATPLOTLIB_PATCH=%r' % self.mpl_patch_enabled)
if self.mpl_backend:
env.append('MATPLOTLIB_BACKEND=%s' % self.mpl_backend)
if self.qt_api:
env.append('QT_API=%s' % self.qt_api)
env.append('INSTALL_QT_INPUTHOOK=%s' % self.install_qt_inputhook)
env.append('COLORIZE_SYS_STDERR=%s' % self.colorize_sys_stderr)
# # Socket-based alternative (see input hook in sitecustomize.py):
# if self.install_qt_inputhook:
# from PyQt4.QtNetwork import QLocalServer
# self.local_server = QLocalServer()
# self.local_server.listen(str(id(self)))
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('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)
#.........这里部分代码省略.........
示例15: ExternalPythonShell
#.........这里部分代码省略.........
else:
argstr = _("No argument")
else:
argstr = _("Arguments...")
self.args_action.setText(argstr)
self.terminate_button.setVisible(not self.is_interpreter and state)
if not state:
self.toggle_globals_explorer(False)
for btn in (self.cwd_button, self.env_button, self.syspath_button):
btn.setEnabled(state and self.monitor_enabled)
if self.namespacebrowser_button is not None:
self.namespacebrowser_button.setEnabled(state)
def set_namespacebrowser(self, namespacebrowser):
"""
Set namespace browser *widget*
Note: this method is not used in stand alone mode
"""
self.namespacebrowser = namespacebrowser
self.configure_namespacebrowser()
def configure_namespacebrowser(self):
"""Connect the namespace browser to the notification thread"""
if self.notification_thread is not None:
self.connect(self.notification_thread,
SIGNAL('refresh_namespace_browser()'),
self.namespacebrowser.refresh_table)
signal = self.notification_thread.sig_process_remote_view
signal.connect(self.namespacebrowser.process_remote_view)
def create_process(self):
self.shell.clear()
self.process = QProcess(self)
if self.merge_output_channels or self.is_ipython_shell:
self.process.setProcessChannelMode(QProcess.MergedChannels)
else:
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.connect(self.shell, SIGNAL("wait_for_ready_read()"),
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'] + get_python_args(self.fname, self.python_args,
self.interact_action.isChecked(),
self.debug_action.isChecked(),
self.arguments)
env = [unicode(_path) for _path in self.process.systemEnvironment()]
if self.pythonstartup:
env.append('PYTHONSTARTUP=%s' % self.pythonstartup)
# 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)