6 import vigir_footstep_planning_msgs.msg
8 from python_qt_binding.QtCore
import Qt, QPoint, QModelIndex, Slot
9 from python_qt_binding.QtGui
import QWidget, QTreeWidget, QTreeWidgetItem, QMenu, QAction, QAbstractItemView, QColor, QIcon
11 from vigir_generic_params.msg
import ParameterSetMsg
20 def __init__(self, parent=None, logger=Logger()):
21 QTreeWidget.__init__(self, parent)
25 self.setHeaderLabels([
"Name",
"Type",
"Value"])
26 self.sortItems(0, Qt.AscendingOrder)
28 self.setContextMenuPolicy(Qt.CustomContextMenu)
29 self.itemActivated.connect(self.
edit_item)
39 self._action_item_add.setEnabled(
False)
41 self._action_item_remove.setEnabled(
False)
48 if self.selectionModel().hasSelection():
55 menu.exec_(self.mapToGlobal(point))
67 def recursive_set_expanded(index):
68 if (index != QModelIndex())
and (index.column() == 0):
69 self.setExpanded(index, expanded)
75 for index
in self.selectedIndexes():
76 recursive_set_expanded(index)
78 @Slot(QTreeWidgetItem, int)
80 if (column == 0)
or (item.is_leaf()
and (column == 2)):
81 item.setFlags(item.flags() | Qt.ItemIsEditable)
82 self.editItem(item, column)
83 item.setFlags(item.flags() & ~Qt.ItemIsEditable)
85 @Slot(QTreeWidgetItem, QTreeWidgetItem)
88 if not prev.update_value():
89 self.logger.log_error(
"Couldn't update value for '" + prev.get_name() +
"' in '" + prev.get_namespace() +
"'. Check input syntax!")
90 if current
is not None:
91 if not current.update_value():
92 self.logger.log_error(
"Couldn't update value for '" + current.get_name() +
"' in '" + current.get_namespace() +
"'. Check input syntax!")
99 self.root.setExpanded(
True)
101 for p
in param_set_msg.params:
102 self.root.add_param(Parameter(msg=p))
106 params = self.root.get_params()
109 top_len = len(self.root.get_name()) + 2
111 p.set_name(p.get_name()[top_len:])
114 param_set_msg = ParameterSet()
115 param_set_msg.name.data = self.root.get_name()
117 param_set_msg.parameters.append(p.to_msg())
128 def __init__(self, parent=None, logger=Logger(), param =
None, name=str(), namespace=str()):
129 QTreeWidgetItem.__init__(self, parent)
132 if param
is not None:
142 return self.
param is not None 147 self.param.set_name(self.text(0))
148 result = self.param.set_value(self.text(2))
151 for i
in range(self.columnCount()):
152 self.setBackgroundColor(i, Qt.white)
154 for i
in range(self.columnCount()):
155 self.setBackgroundColor(i, QColor(255, 165, 0))
159 self.setText(0, name)
161 self.param.set_name(name)
173 self.setText(0, self.param.get_name())
174 self.setText(1, str(self.param.get_type_as_text()))
175 self.setText(2, str(self.param.get_value()))
185 self.logger.log_warn(
"Value for '" + self.
get_name() +
"' in '" + self.
get_namespace() +
"' has invalid changes. Check input syntax!")
191 for i
in range(self.childCount()):
198 def find_branch(name):
199 for i
in range(self.childCount()):
200 if self.child(i).text(0) == name:
205 def add_param_to_branch(param, branch_name):
206 branch = find_branch(branch_name)
209 branch.add_param(param)
212 print "Error: Can't add parameter '" + param.get_name() +
"' to the leaf '" + self.
get_name() +
"'!" 216 param.set_name(param.get_name().
strip(
'/'))
217 i = param.get_name().find(
'/')
224 branch_name = param.get_name()[:i]
225 param.set_name(param.get_name()[i+1:])
226 add_param_to_branch(param, branch_name)