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 import sys
00036
00037 import QtGui
00038 from QtGui import QWidget, QPushButton, QComboBox, QScrollArea, QTreeWidget, QTreeWidgetItem
00039 from QtCore import QTimer
00040
00041 import dynamic_reconfigure.client
00042 import rosservice
00043 import rospy
00044
00045 from .editors import *
00046 from .groups import *
00047 from .updater import Updater
00048
00049 class ReconfigureWidget(QWidget):
00050 def __init__(self):
00051 super(ReconfigureWidget, self).__init__()
00052 self.client = None
00053 self.stretch = None
00054
00055 self.hbox = QtGui.QHBoxLayout()
00056 self.selector = ReconfigureSelector(self)
00057 self.hbox.addWidget(self.selector.tree)
00058
00059 self.destroyed.connect(self.close)
00060
00061 self.setLayout(self.hbox)
00062
00063 def show(self, node):
00064 self.close()
00065
00066 reconf = None
00067
00068 try:
00069 reconf = dynamic_reconfigure.client.Client(str(node), timeout=5.0)
00070 except rospy.exceptions.ROSException:
00071 print("Could not connect to %s"%node)
00072 return
00073 finally:
00074 self.close()
00075
00076 self.client = ClientWidget(reconf)
00077
00078 self.scroll = QScrollArea()
00079
00080 self.scroll.setMinimumWidth(self.client.minimumWidth()+20)
00081
00082 self.scroll.setWidget(self.client)
00083 self.scroll.setWidgetResizable(True)
00084
00085 self.hbox.insertWidget(1, self.scroll, 1)
00086 self.hbox.removeItem(self.hbox.itemAt(2))
00087 self.stretch = None
00088
00089 def close(self):
00090 if self.client is not None:
00091
00092 self.client.close()
00093 self.client = None
00094
00095 self.scroll.deleteLater()
00096
00097 def clear(self):
00098 if not self.stretch:
00099 self.stretch = self.hbox.addStretch(1)
00100
00101 class ReconfigureSelector(QWidget):
00102 def __init__(self, parent):
00103 super(ReconfigureSelector, self).__init__()
00104
00105 self.parent = parent
00106 self.last_nodes = None
00107 self.current_node = ''
00108
00109 self.tree = QTreeWidget()
00110 self.update_tree()
00111
00112 self.tree.itemClicked.connect(self.selected)
00113 self.tree.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
00114
00115 self.tree.setHeaderLabel("Available Nodes")
00116
00117 self.timer = QTimer()
00118 self.timer.timeout.connect(self.update_tree)
00119 self.timer.start(100)
00120
00121 def update_tree(self):
00122 try:
00123 nodes = dynamic_reconfigure.find_reconfigure_services()
00124 except rosservice.ROSServiceIOException:
00125 print("Reconfigure GUI cannot connect to master.")
00126 else:
00127 if not nodes == self.last_nodes:
00128 self.tree.clear()
00129 for n in nodes:
00130 item = QTreeWidgetItem()
00131 item.setText(0, n)
00132 self.tree.addTopLevelItem(item)
00133 elif len(nodes) == 0:
00134 self.tree.clear()
00135 self.parent.close()
00136 self.parent.clear()
00137
00138 self.last_nodes = nodes
00139
00140 def selected(self, node, col):
00141 print("Selected %s"%node.text(0))
00142 if not node.text(0) == self.current_node:
00143 self.parent.show(node.text(0))
00144 self.current_node = node.text(0)
00145
00146 class ClientWidget(Group):
00147 def __init__(self, reconf):
00148 super(ClientWidget, self).__init__(Updater(reconf), reconf.get_group_descriptions())
00149
00150 self.setMinimumWidth(550)
00151
00152 self.reconf = reconf
00153
00154 self.updater.start()
00155 self.reconf.config_callback = self.config_callback
00156
00157 def config_callback(self, config):
00158 if config is not None:
00159
00160 names = [name for name, v in config.items()]
00161
00162 for widget in self.widgets:
00163 if isinstance(widget, Editor):
00164 if widget.name in names:
00165 widget.update_value(config[widget.name])
00166 elif isinstance(widget, Group):
00167 cfg = find_cfg(config, widget.name)
00168 widget.update_group(cfg)
00169
00170 def close(self):
00171 self.reconf.close()
00172 self.updater.stop()
00173
00174 for w in self.widgets:
00175 w.close()
00176
00177 self.deleteLater()
00178