Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 from python_qt_binding.QtGui import QFont, QIcon
00034 from python_qt_binding.QtCore import QProcess, SIGNAL, QTextCodec, Signal
00035
00036 from spyderlib.widgets.externalshell.baseshell import ExternalShellBase
00037 from spyderlib.widgets.shell import TerminalWidget
00038
00039
00040 class SpyderShellWidget(ExternalShellBase):
00041 """Spyder Shell Widget: execute a shell in a separate process using spyderlib's ExternalShellBase"""
00042 SHELL_CLASS = TerminalWidget
00043 close_signal = Signal()
00044
00045 def __init__(self, parent=None):
00046 ExternalShellBase.__init__(self, parent=parent, fname=None, wdir='.',
00047 history_filename='.history',
00048 light_background=True,
00049 menu_actions=None,
00050 show_buttons_inside=False,
00051 show_elapsed_time=False)
00052
00053 self.setObjectName('SpyderShellWidget')
00054
00055
00056
00057
00058 self.shell.set_pythonshell_font(QFont('Mono'))
00059
00060
00061 self.path = []
00062
00063
00064 self.is_ipython_kernel = False
00065 self.connection_file = None
00066
00067 self.create_process()
00068
00069 def get_icon(self):
00070 return QIcon()
00071
00072 def create_process(self):
00073 self.shell.clear()
00074
00075 self.process = QProcess(self)
00076 self.process.setProcessChannelMode(QProcess.MergedChannels)
00077
00078 env = [unicode(key_val_pair) for key_val_pair in self.process.systemEnvironment()]
00079 env.append('TERM=xterm')
00080 env.append('COLORTERM=gnome-terminal')
00081 self.process.setEnvironment(env)
00082
00083
00084 if self.wdir is not None:
00085 self.process.setWorkingDirectory(self.wdir)
00086
00087 self.process.readyReadStandardOutput.connect(self.write_output)
00088 self.process.finished.connect(self.finished)
00089 self.process.finished.connect(self.close_signal)
00090
00091 self.process.start('/bin/bash', ['-i'])
00092
00093 running = self.process.waitForStarted()
00094 self.set_running_state(running)
00095 if not running:
00096 self.shell.addPlainText("Process failed to start")
00097 else:
00098 self.shell.setFocus()
00099 self.emit(SIGNAL('started()'))
00100
00101 return self.process
00102
00103 def shutdown(self):
00104 self.process.kill()
00105 self.process.waitForFinished()
00106
00107 def _key_tab(self):
00108 self.process.write('\t')
00109 self.process.waitForBytesWritten(-1)
00110 self.write_output()
00111
00112 def send_to_process(self, text):
00113 if not isinstance(text, basestring):
00114 text = unicode(text)
00115 if not text.endswith('\n'):
00116 text += '\n'
00117 self.process.write(QTextCodec.codecForLocale().fromUnicode(text))
00118 self.process.waitForBytesWritten(-1)
00119
00120 def keyboard_interrupt(self):
00121 self.send_ctrl_to_process('c')