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