34 from python_qt_binding.QtCore
import Qt, Signal
35 from python_qt_binding.QtGui
import QStandardItem, QStandardItemModel
42 _column_names = [
'topic',
'type',
'rate',
'expression']
43 item_value_changed = Signal(int, str, str, str, object)
46 super(PublisherTreeModel, self).
__init__(parent)
56 super(PublisherTreeModel, self).
clear()
64 self.removeRow(item.row())
71 topic_name = item._path
73 if item.isCheckable():
74 new_value = str(item.checkState() == Qt.Checked)
76 new_value = item.text().strip()
81 item._user_data[
'publisher_id'], topic_name, column_name, new_value, item.setText)
87 for top_level_row_number
in range(self.rowCount()):
88 item = self.item(top_level_row_number)
89 if item
is not None and item._user_data[
'publisher_id'] == publisher_id:
90 self.removeRow(top_level_row_number)
91 return top_level_row_number
101 slot = publisher_info[
'message_instance']
102 slot_name = publisher_info[
'topic_name']
103 slot_type_name = publisher_info[
'message_instance']._type
104 slot_path = publisher_info[
'topic_name']
105 user_data = {
'publisher_id': publisher_info[
'publisher_id']}
107 'user_data': user_data,
108 'top_level_row_number': top_level_row_number,
109 'expressions': publisher_info[
'expressions'],
112 parent, slot, slot_name, slot_type_name, slot_path, **kwargs)
115 if publisher_info[
'enabled']:
116 top_level_row[self.
_column_index[
'topic']].setCheckState(Qt.Checked)
117 top_level_row[self.
_column_index[
'rate']].setText(str(publisher_info[
'rate']))
120 if slot_name.startswith(
'/'):
125 expression_item = QStandardItem(
'')
126 expression_item.setToolTip(
127 'enter valid Python expression here, using "i" as counter and functions from math, '
128 'random and time modules')
130 QStandardItem(slot_type_name),
135 self, parent, slot, slot_name, slot_type_name, slot_path, expressions={}, **kwargs):
137 parent, slot, slot_name, slot_type_name, slot_path, expressions=expressions, **kwargs)
139 expression_text = expressions.get(slot_path, repr(slot))
140 row[self.
_column_index[
'expression']].setText(expression_text)
144 flags = super(PublisherTreeModel, self).
flags(index)
152 Qt.DisplayRole) ==
'bool'
154 flags |= Qt.ItemIsUserCheckable
165 Qt.DisplayRole) ==
'bool'
167 if role == Qt.CheckStateRole:
171 index.row(), index.column(), index.parent()),
178 return Qt.PartiallyChecked
179 return super(PublisherTreeModel, self).
data(index, role)
183 index.column() == index.column() == self.
_column_index[
'expression']
and
187 Qt.DisplayRole) ==
'bool'
189 if role == Qt.CheckStateRole:
190 value = str(value == Qt.Checked)
191 return QStandardItemModel.setData(self, index, value, Qt.EditRole)
192 return QStandardItemModel.setData(self, index, value, role)