spyder_shell_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Dorian Scholz
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
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         # capture tab key
00059         #self.shell._key_tab = self._key_tab
00060 
00061         self.shell.set_pythonshell_font(QFont('Mono'))
00062 
00063         # Additional python path list
00064         self.path = []
00065 
00066         # For compatibility with the other shells that can live in the external console
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         # Working directory
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')


rqt_shell
Author(s): Dorian Scholz
autogenerated on Fri Jan 3 2014 11:55:41