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