shell.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 qt_gui.plugin import Plugin
00037 from qt_gui_py_common.simple_settings_dialog import SimpleSettingsDialog
00038 
00039 from shell_widget import ShellWidget
00040 
00041 try:
00042     from xterm_widget import XTermWidget, is_xterm_available
00043     _has_xterm = is_xterm_available()
00044 except ImportError:
00045     XTermWidget = None
00046     _has_xterm = False
00047 
00048 try:
00049     from spyder_shell_widget import SpyderShellWidget
00050     _has_spyderlib = True
00051 except ImportError:
00052     SpyderShellWidget = None
00053     _has_spyderlib = False
00054 
00055 
00056 class Shell(Plugin):
00057     """
00058     Plugin providing an interactive shell
00059     """
00060     # shell types in order of priority
00061     shell_types = [
00062         {
00063             'title': 'XTerm',
00064             'widget_class': XTermWidget,
00065             'description': 'Fully functional embedded XTerm (needs xterm and only works on X11).',
00066             'enabled': _has_xterm,
00067         },
00068         {
00069             'title': 'SpyderShell',
00070             'widget_class': SpyderShellWidget,
00071             'description': 'Advanced shell (needs spyderlib).',
00072             'enabled': _has_spyderlib,
00073         },
00074         {
00075             'title': 'SimpleShell',
00076             'widget_class': ShellWidget,
00077             'description': 'Simple shell for executing non-interactive finite commands.',
00078             'enabled': True,
00079         },
00080     ]
00081 
00082     def __init__(self, context):
00083         super(Shell, self).__init__(context)
00084         self._context = context
00085         self.setObjectName('Shell')
00086 
00087         self._widget = None
00088 
00089     def _switch_shell_widget(self):
00090         # check for available shell type
00091         while not self.shell_types[self._shell_type_index]['enabled']:
00092             self._shell_type_index += 1
00093         selected_shell = self.shell_types[self._shell_type_index]
00094 
00095         if self._widget is not None:
00096             if hasattr(self._widget, 'close_signal'):
00097                 self._widget.close_signal.disconnect(self._context.close_plugin)
00098             self._context.remove_widget(self._widget)
00099             self._widget.close()
00100 
00101         self._widget = selected_shell['widget_class']()
00102         self._widget.setWindowTitle(selected_shell['title'])
00103         if self._context.serial_number() > 1:
00104             self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % self._context.serial_number()))
00105         self._context.add_widget(self._widget)
00106         if hasattr(self._widget, 'close_signal'):
00107             self._widget.close_signal.connect(self._context.close_plugin)
00108 
00109     def save_settings(self, plugin_settings, instance_settings):
00110         instance_settings.set_value('shell_type', self._shell_type_index)
00111 
00112     def restore_settings(self, plugin_settings, instance_settings):
00113         self._shell_type_index = int(instance_settings.value('shell_type', 0))
00114         self._switch_shell_widget()
00115 
00116     def trigger_configuration(self):
00117         dialog = SimpleSettingsDialog(title='Shell Options')
00118         dialog.add_exclusive_option_group(title='Shell Type', options=self.shell_types, selected_index=self._shell_type_index)
00119         shell_type = dialog.get_settings()[0]
00120         if shell_type is not None and self._shell_type_index != shell_type['selected_index']:
00121             self._shell_type_index = shell_type['selected_index']
00122             self._context.reload_plugin()
00123 
00124     def shutdown_plugin(self):
00125         if self._widget is not None and hasattr(self._widget, 'shutdown'):
00126             self._widget.shutdown()
00127 


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