py_console.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Dorian Scholz
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 from python_qt_binding.QtWidgets import QVBoxLayout, QWidget
34 from qt_gui.plugin import Plugin
35 from qt_gui_py_common.simple_settings_dialog import SimpleSettingsDialog
36 from rqt_py_console.py_console_widget import PyConsoleWidget
37 
38 try:
39  from spyder_console_widget import SpyderConsoleWidget
40  _has_spyderlib = True
41 except ImportError:
42  _has_spyderlib = False
43 
44 
46 
47  """
48  Plugin providing an interactive Python console
49  """
50 
51  def __init__(self, context):
52  super(PyConsole, self).__init__(context)
53  self.setObjectName('PyConsole')
54 
55  self._context = context
56  self._use_spyderlib = _has_spyderlib
57  self._console_widget = None
58  self._widget = QWidget()
59  self._widget.setLayout(QVBoxLayout())
60  self._widget.layout().setContentsMargins(0, 0, 0, 0)
61  if context.serial_number() > 1:
62  self._widget.setWindowTitle(
63  self._widget.windowTitle() + (' (%d)' % context.serial_number()))
64  self._context.add_widget(self._widget)
65 
67  self._widget.layout().removeWidget(self._console_widget)
69 
70  if _has_spyderlib and self._use_spyderlib:
71  self._console_widget = SpyderConsoleWidget(self._context)
72  self._widget.setWindowTitle('SpyderConsole')
73  else:
75  self._widget.setWindowTitle('PyConsole')
76  if self._context.serial_number() > 1:
77  self._widget.setWindowTitle(
78  self._widget.windowTitle() + (' (%d)' % self._context.serial_number()))
79 
80  self._widget.layout().addWidget(self._console_widget)
81 
82  def save_settings(self, plugin_settings, instance_settings):
83  instance_settings.set_value('use_spyderlib', self._use_spyderlib)
84 
85  def restore_settings(self, plugin_settings, instance_settings):
86  self._use_spyderlib = _has_spyderlib and (
87  instance_settings.value('use_spyderlib', True) in [True, 'true'])
89 
91  options = [
92  {'title': 'SpyderConsole',
93  'description': 'Advanced Python console with tab-completion (needs spyderlib to be installed).', 'enabled': _has_spyderlib},
94  {'title': 'PyConsole', 'description': 'Simple Python console.'},
95  ]
96  dialog = SimpleSettingsDialog(title='PyConsole Options')
97  dialog.add_exclusive_option_group(
98  title='Console Type', options=options, selected_index=int(not self._use_spyderlib))
99  console_type = dialog.get_settings()[0]
100  new_use_spyderlib = {0: True, 1: False}.get(
101  console_type['selected_index'], self._use_spyderlib)
102  if self._use_spyderlib != new_use_spyderlib:
103  self._use_spyderlib = new_use_spyderlib
105 
107  if self._console_widget is not None and hasattr(self._console_widget, 'shutdown'):
108  self._console_widget.shutdown()
109 
110  def shutdown_plugin(self):
def save_settings(self, plugin_settings, instance_settings)
Definition: py_console.py:82
def restore_settings(self, plugin_settings, instance_settings)
Definition: py_console.py:85


rqt_py_console
Author(s): Dorian Scholz
autogenerated on Wed Jun 5 2019 19:43:39