Commit bee07859 authored by Thomas Moulard's avatar Thomas Moulard
Browse files

Initial work (fork from rqt_py_console)

parents
cmake_minimum_required(VERSION 2.8.3)
project(rqt_dynamic_graph)
# Load catkin and all dependencies required for this package
find_package(catkin REQUIRED)
catkin_package()
catkin_python_setup()
install(FILES plugin.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(DIRECTORY resource
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(PROGRAMS scripts/rqt_dynamic_graph
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
<package>
<name>rqt_dynamic_graph</name>
<version>0.3.0</version>
<description>rqt_dynamic_graph
is a Python GUI plugin providing an interactive Python console.</description>
<maintainer email="scholz@sim.tu-darmstadt.de">Dorian Scholz</maintainer>
<maintainer email="isao.saito@mavs.uta.edu">Isaac Saito</maintainer>
<license>BSD</license>
<url type="website">http://ros.org/wiki/rqt_dynamic_graph</url>
<author>Dorian Scholz</author>
<buildtool_depend>catkin</buildtool_depend>
<run_depend>python-rospkg</run_depend>
<run_depend>qt_gui</run_depend>
<run_depend>qt_gui_py_common</run_depend>
<run_depend>rospy</run_depend>
<run_depend>rqt_gui</run_depend>
<run_depend>rqt_gui_py</run_depend>
<run_depend>rospy</run_depend>
<run_depend>dynamic_graph_bridge</run_depend>
<export>
<qt_gui plugin="${prefix}/plugin.xml"/>
</export>
</package>
<library path="src">
<class name="PyConsole"
type="rqt_dynamic_graph.py_console.PyConsole"
base_class_type="qt_gui_py::Plugin">
<description>
A Python GUI plugin providing an interactive Python console.
</description>
<qtgui>
<label>Dynamic Graph Console</label>
<icon type="theme">applications-python</icon>
<statustip>Open a Python interpreter connected to the Stack of
Tasks.</statustip>
</qtgui>
</class>
</library>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RunCommand</class>
<widget class="QWidget" name="RunCommand">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>212</height>
</rect>
</property>
<property name="windowTitle">
<string>RunCommand</string>
</property>
<layout class="QVBoxLayout" name="_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="header_layout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="PyConsoleTextEdit" name="py_console"/>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PyConsoleTextEdit</class>
<extends>QTextEdit</extends>
<header>rqt_dynamic_graph.py_console_text_edit</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
#!/usr/bin/env python
import sys
from rqt_gui.main import Main
main = Main()
sys.exit(main.main(sys.argv, standalone='rqt_dynamic_graph'))
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['rqt_dynamic_graph'],
package_dir={'': 'src'}
)
setup(**d)
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Dorian Scholz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from python_qt_binding.QtGui import QVBoxLayout, QWidget
from qt_gui.plugin import Plugin
from qt_gui_py_common.simple_settings_dialog import SimpleSettingsDialog
from rqt_dynamic_graph.py_console_widget import PyConsoleWidget
try:
from spyder_console_widget import SpyderConsoleWidget
_has_spyderlib = True
except ImportError:
_has_spyderlib = False
class PyConsole(Plugin):
"""
Plugin providing an interactive Python console
"""
def __init__(self, context):
super(PyConsole, self).__init__(context)
self.setObjectName('PyConsole')
self._context = context
self._use_spyderlib = _has_spyderlib
self._console_widget = None
self._widget = QWidget()
self._widget.setLayout(QVBoxLayout())
self._widget.layout().setContentsMargins(0, 0, 0, 0)
if context.serial_number() > 1:
self._widget.setWindowTitle(self._widget.windowTitle() + \
(' (%d)' % context.serial_number()))
self._context.add_widget(self._widget)
def _switch_console_widget(self):
self._widget.layout().removeWidget(self._console_widget)
self.shutdown_console_widget()
if _has_spyderlib and self._use_spyderlib:
self._console_widget = SpyderConsoleWidget(self._context)
self._widget.setWindowTitle('SpyderConsole')
else:
self._console_widget = PyConsoleWidget(self._context)
self._widget.setWindowTitle('PyConsole')
if self._context.serial_number() > 1:
self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % self._context.serial_number()))
self._widget.layout().addWidget(self._console_widget)
def save_settings(self, plugin_settings, instance_settings):
instance_settings.set_value('use_spyderlib', self._use_spyderlib)
def restore_settings(self, plugin_settings, instance_settings):
self._use_spyderlib = _has_spyderlib and (instance_settings.value('use_spyderlib', True) in [True, 'true'])
self._switch_console_widget()
def trigger_configuration(self):
options = [
{'title': 'SpyderConsole', 'description': 'Advanced Python console with tab-completion (needs spyderlib to be installed).', 'enabled': _has_spyderlib},
{'title': 'PyConsole', 'description': 'Simple Python console.'},
]
dialog = SimpleSettingsDialog(title='PyConsole Options')
dialog.add_exclusive_option_group(title='Console Type', options=options, selected_index=int(not self._use_spyderlib))
console_type = dialog.get_settings()[0]
new_use_spyderlib = {0: True, 1: False}.get(console_type['selected_index'], self._use_spyderlib)
if self._use_spyderlib != new_use_spyderlib:
self._use_spyderlib = new_use_spyderlib
self._switch_console_widget()
def shutdown_console_widget(self):
if self._console_widget is not None and hasattr(self._console_widget, 'shutdown'):
self._console_widget.shutdown()
def shutdown_plugin(self):
self.shutdown_console_widget()
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Dorian Scholz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import sys
from code import InteractiveInterpreter
from exceptions import SystemExit
from python_qt_binding import QT_BINDING, QT_BINDING_VERSION
from python_qt_binding.QtCore import Qt, Signal
from qt_gui_py_common.console_text_edit import ConsoleTextEdit
import roslib; roslib.load_manifest('rqt_dynamic_graph')
import rospy
import dynamic_graph_bridge.srv
class PyConsoleTextEdit(ConsoleTextEdit):
_color_stdin = Qt.darkGreen
_multi_line_char = ':'
_multi_line_indent = ' '
_prompt = ('>>> ', '... ') # prompt for single and multi line
exit = Signal()
def __init__(self, parent=None):
super(PyConsoleTextEdit, self).__init__(parent)
self.cache = ""
self._client = rospy.ServiceProxy(
'run_command', dynamic_graph_bridge.srv.RunCommand, True)
self._comment_writer.write('Python %s on %s\n' % (sys.version.replace('\n', ''), sys.platform))
self._comment_writer.write('Qt bindings: %s version %s\n' % (QT_BINDING, QT_BINDING_VERSION))
self._add_prompt()
def update_interpreter_locals(self, newLocals):
pass
def _exec_code(self, code):
try:
self._runcode(code)
except SystemExit: # catch sys.exit() calls, so they don't close the whole gui
self.exit.emit()
def _runcode(self, code, retry = True):
self.cache += code + "\n"
source = self.cache[:-1]
self.cache = ""
if source != "":
try:
if not self._client:
if not retry:
print("Connection to remote server lost. Reconnecting...")
self._client = rospy.ServiceProxy(
'run_command', dynamic_graph_bridge.srv.RunCommand, True)
response = self._client(str(source))
if response.stdout != "":
print(response.stdout[:-1])
if response.stderr != "":
print(response.stderr[:-1])
elif response.result != "None":
print(response.result)
except rospy.ServiceException, e:
print("Connection to remote server lost. Reconnecting...")
self._client = rospy.ServiceProxy(
'run_command', dynamic_graph_bridge.srv.RunCommand, True)
if retry:
self.cache = source
self._runcode(code, False)
else:
print("Failed to connect. Is Stack of Tasks running?")
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Dorian Scholz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import rospkg
from python_qt_binding import loadUi
from python_qt_binding.QtGui import QWidget
import rqt_dynamic_graph.py_console_text_edit
class PyConsoleWidget(QWidget):
def __init__(self, context=None):
super(PyConsoleWidget, self).__init__()
rp = rospkg.RosPack()
ui_file = os.path.join(rp.get_path('rqt_dynamic_graph'),
'resource', 'run_command_widget.ui')
loadUi(ui_file, self,
{'PyConsoleTextEdit':
rqt_dynamic_graph.py_console_text_edit.PyConsoleTextEdit})
self.setObjectName('PyConsoleWidget')
my_locals = {
'context': context
}
self.py_console.update_interpreter_locals(my_locals)
self.py_console.print_message('The variable "context" is set to the PluginContext of this plugin.')
self.py_console.exit.connect(context.close_plugin)
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Dorian Scholz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from python_qt_binding.QtGui import QFont
from spyderlib.widgets.internalshell import InternalShell
from spyderlib.utils.module_completion import moduleCompletion
import roslib; roslib.load_manifest('rqt_dynamic_graph')
import rospy
import dynamic_graph_bridge.srv
class SpyderConsoleWidget(InternalShell):
def __init__(self, context=None):
my_locals = {
'context': context
}
super(SpyderConsoleWidget, self).__init__(namespace=my_locals)
self.cache = ""
self._client = rospy.ServiceProxy(
'run_command', dynamic_graph_bridge.srv.RunCommand, True)
self.setObjectName('SpyderConsoleWidget')
self.set_pythonshell_font(QFont('Mono'))
self.interpreter.restore_stds()
def get_module_completion(self, objtxt):
"""Return module completion list associated to object name"""
return moduleCompletion(objtxt)
def run_command(self, code):
self.interpreter.redirect_stds()
super(SpyderConsoleWidget, self).run_command("")
self._runcode(code)
self.flush()
self.interpreter.restore_stds()
def _runcode(self, code, retry = True):
self.cache += code + "\n"
source = self.cache[:-1]
self.cache = ""
if source != "":
try:
if not self._client:
if not retry:
print("Connection to remote server lost. Reconnecting...")
self._client = rospy.ServiceProxy(
'run_command', dynamic_graph_bridge.srv.RunCommand, True)
response = self._client(str(source))
if response.stdout != "":
print(response.stdout[:-1])
if response.stderr != "":
print(response.stderr[:-1])
elif response.result != "None":
print(response.result)
print("\n")
except rospy.ServiceException, e:
print("Connection to remote server lost. Reconnecting...")
self._client = rospy.ServiceProxy(
'run_command', dynamic_graph_bridge.srv.RunCommand, True)
if retry:
self.cache = source
self._runcode(code, False)
else:
print("Failed to connect. Is Stack of Tasks running?")
def shutdown(self):
self.exit_interpreter()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment