MCPcopy Index your code
hub / github.com/DeepLabCut/DeepLabCut / DictViewer

Class DictViewer

deeplabcut/gui/widgets.py:281–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279
280
281class DictViewer(QtWidgets.QWidget):
282 def __init__(self, cfg, filename="", parent=None):
283 super().__init__(parent)
284 self.cfg = cfg
285 self.filename = filename
286 self.parent = parent
287 self.tree = QtWidgets.QTreeWidget()
288 self.tree.setHeaderLabels(["Parameter", "Value"])
289 self.tree.header().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
290 self.tree.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
291 self.tree.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectItems)
292 self.tree.setAlternatingRowColors(True)
293 self.tree.setSortingEnabled(False)
294 self.tree.setHeaderHidden(False)
295 self.tree.itemChanged.connect(self.edit_value)
296 self.tree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
297 self.tree.customContextMenuRequested.connect(self.pop_context_menu)
298
299 self.root = self.tree.invisibleRootItem()
300 self.tree.addTopLevelItem(self.root)
301 self.populate_tree(cfg, self.root)
302
303 layout = QtWidgets.QHBoxLayout()
304 layout.addWidget(self.tree)
305 layout2 = QtWidgets.QVBoxLayout()
306 layout2.addWidget(QtWidgets.QLabel(filename))
307 layout2.addWidget(self.tree)
308 self.setLayout(layout2)
309
310 def pop_context_menu(self, point):
311 index = self.tree.indexAt(point)
312 if not index.isValid():
313 return
314 menu = ContextMenu(self)
315 menu.exec_(self.tree.mapToGlobal(point))
316
317 def get_position_in_parent(self, item):
318 parent = item.parent() or self.root
319 index = parent.indexOfChild(item)
320 return index, parent
321
322 def insert(self, item):
323 current = self.tree.selectedItems()[0]
324 ind, parent = self.get_position_in_parent(current)
325 parent.insertChild(ind + 1, item)
326
327 value = self.cast_to_right_type(item.text(1))
328 if parent is self.root:
329 self.set_value(self.cfg, [item.text(0)], value)
330 else:
331 keys, _ = self.walk_recursively_to_root(current)
332 self.set_value(self.cfg, keys, value, ind + 1)
333
334 def remove(self, item):
335 ind, parent = self.get_position_in_parent(item)
336 keys, value = self.walk_recursively_to_root(item)
337 if item.parent() and item.childCount(): # Handle nested dict or list
338 keys = [keys[0], value]

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected