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 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
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
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