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