33 from python_qt_binding.QtGui
import QFont, QIcon
34 from python_qt_binding.QtCore
import QProcess, SIGNAL, QTextCodec, Signal
36 from spyderlib.widgets.externalshell.baseshell
import ExternalShellBase
37 from spyderlib.widgets.shell
import TerminalWidget
43 """Check if the argument is a string which works for both Python 2 and 3."""
45 return isinstance(s, basestring)
47 return isinstance(s, str)
51 """Spyder Shell Widget: execute a shell in a separate process using spyderlib's ExternalShellBase"""
52 SHELL_CLASS = TerminalWidget
53 close_signal = Signal()
55 def __init__(self, parent=None, script_path=None):
56 ExternalShellBase.__init__(self, parent=parent, fname=
None, wdir=
'.',
57 history_filename=
'.history',
58 light_background=
True,
60 show_buttons_inside=
False,
61 show_elapsed_time=
False)
63 self.setObjectName(
'SpyderShellWidget')
68 self.shell.set_pythonshell_font(QFont(
'Mono'))
86 self.
process.setProcessChannelMode(QProcess.MergedChannels)
89 for key_val_pair
in self.
process.systemEnvironment():
91 value = unicode(key_val_pair)
93 value = str(key_val_pair)
95 env.append(
'TERM=xterm')
96 env.append(
'COLORTERM=gnome-terminal')
97 self.
process.setEnvironment(env)
100 if self.wdir
is not None:
101 self.
process.setWorkingDirectory(self.wdir)
103 self.
process.readyReadStandardOutput.connect(self.write_output)
104 self.
process.finished.connect(self.finished)
109 "-c 'source %s; /bin/bash -i'" % os.path.abspath(script_path)]
112 self.
process.start(
'/bin/bash', options)
114 running = self.
process.waitForStarted()
115 self.set_running_state(running)
117 self.shell.addPlainText(
"Process failed to start")
119 self.shell.setFocus()
120 self.emit(SIGNAL(
'started()'))
130 self.
process.waitForBytesWritten(-1)
139 if not text.endswith(
'\n'):
141 self.
process.write(QTextCodec.codecForLocale().fromUnicode(text))
142 self.
process.waitForBytesWritten(-1)
145 self.send_ctrl_to_process(
'c')