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


rqt_shell
Author(s): Dorian Scholz
autogenerated on Mon Oct 6 2014 07:15:38