graphics_view.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Open Source Robotics Foundation, Inc.
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 Open Source Robotics Foundation, Inc. nor
00017 #    the names of its contributors may be used to endorse or promote
00018 #    products derived from this software without specific prior
00019 #    written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 # Author: William Woodall <william@osrfoundation.org>
00035 
00036 """Extends the InteractiveGraphicsView from rqt_graph to handle special actions
00037 """
00038 
00039 import rospy
00040 
00041 from PySide.QtCore import Qt
00042 from PySide.QtCore import QPoint
00043 
00044 from PySide.QtGui import QMenu
00045 
00046 from rqt_graph.interactive_graphics_view import InteractiveGraphicsView
00047 
00048 from qt_dotgraph.node_item import NodeItem
00049 
00050 from capabilities.srv import StartCapability
00051 from capabilities.srv import StopCapability
00052 
00053 
00054 class CapabilitiesInteractiveGraphicsView(InteractiveGraphicsView):
00055     """Extends the InteractiveGraphicsView from rqt_graph"""
00056     def __init__(self, parent=None):
00057         super(InteractiveGraphicsView, self).__init__(parent)
00058         self._last_pan_point = None
00059         self._last_scene_center = None
00060         self._running_providers = []
00061         self._spec_index = None
00062 
00063     def mousePressEvent(self, mouse_event):
00064         if mouse_event.button() == Qt.RightButton:
00065             if self._spec_index is None:
00066                 print("spec_index is None")
00067                 print(self)
00068                 print(self._running_providers)
00069                 return
00070             pos = mouse_event.pos()
00071             items = [item for item in self.items(pos) if isinstance(item, NodeItem) and item._label.text()]
00072             if len(items) != 1:
00073                 print("wrong number of things", [x._label.text() for x in items])
00074                 return
00075 
00076             name = items[0]._label.text().rstrip('(default)').strip()
00077             if name not in self._spec_index.provider_names:
00078                 print(name, "Not in list of providers")
00079                 return
00080             provider = self._spec_index.providers[name]
00081 
00082             def start_trigger():
00083                 # TODO: replace 'capability_server' with user provided server name
00084                 service_name = '/{0}/start_capability'.format('capability_server')
00085                 rospy.wait_for_service(service_name)
00086                 start_capability = rospy.ServiceProxy(service_name, StartCapability)
00087                 start_capability(provider.implements, name)
00088 
00089             def stop_trigger():
00090                 # TODO: replace 'capability_server' with user provided server name
00091                 service_name = '/{0}/stop_capability'.format('capability_server')
00092                 rospy.wait_for_service(service_name)
00093                 stop_capability = rospy.ServiceProxy(service_name, StopCapability)
00094                 stop_capability(provider.implements)
00095 
00096             if name not in self._running_providers:
00097                 trigger = start_trigger
00098                 msg = "start => "
00099             else:
00100                 trigger = stop_trigger
00101                 msg = "stop => "
00102 
00103             menu = QMenu()
00104             action = menu.addAction(msg + name)
00105             action.triggered.connect(trigger)
00106             pos = mouse_event.globalPos()
00107             pos = QPoint(pos.x(), pos.y())
00108             menu.exec_(pos)
00109         else:
00110             InteractiveGraphicsView.mousePressEvent(self, mouse_event)


rqt_capabilities
Author(s): William Woodall
autogenerated on Sat Jun 8 2019 18:40:50