Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add(parent, name):
item = self.find(parent, name)
if item is None:
item = QtWidgets.QTreeWidgetItem(parent, [name])
if os.path.splitext(name)[-1] in self.fileExtensions:
fnt = QtGui.QFont()
item.setFont(0, fnt)
else:
pass
if isinstance(parent, DataFileList):
parent.addTopLevelItem(item)
else:
parent.addChild(item)
return item
for grpName, grpData in data.items():
self.data[grpName] = data[grpName]
grpItem = QtWidgets.QTreeWidgetItem(self, [grpName])
self.groupItems.append(grpItem)
self.addTopLevelItem(grpItem)
dataParent = QtWidgets.QTreeWidgetItem(grpItem, ['[DATA]'])
metaParent = QtWidgets.QTreeWidgetItem(grpItem, ['[META]'])
for dn, dv in grpData.data_items():
vals = [grpData.label(dn), str(grpData.meta_val('shape', dn))]
if dn in grpData.dependents():
vals.append(f'Data (depends on {str(tuple(grpData.axes(dn)))[1:]}')
else:
vals.append('Data (independent)')
ditem = QtWidgets.QTreeWidgetItem(dataParent, vals)
for mn, mv in grpData.meta_items(dn):
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(ditem, vals)
for mn, mv in grpData.meta_items():
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(metaParent, vals)
grpItem.setExpanded(True)
dataParent.setExpanded(True)
for i in range(self.columnCount()-1):
self.resizeColumnToContents(i)
def setData(self, data: Dict[str, DataDict]):
"""Set the data to display."""
self.clear()
self.data = {}
self.groupItems = []
for grpName, grpData in data.items():
self.data[grpName] = data[grpName]
grpItem = QtWidgets.QTreeWidgetItem(self, [grpName])
self.groupItems.append(grpItem)
self.addTopLevelItem(grpItem)
dataParent = QtWidgets.QTreeWidgetItem(grpItem, ['[DATA]'])
metaParent = QtWidgets.QTreeWidgetItem(grpItem, ['[META]'])
for dn, dv in grpData.data_items():
vals = [grpData.label(dn), str(grpData.meta_val('shape', dn))]
if dn in grpData.dependents():
vals.append(f'Data (depends on {str(tuple(grpData.axes(dn)))[1:]}')
else:
vals.append('Data (independent)')
ditem = QtWidgets.QTreeWidgetItem(dataParent, vals)
for mn, mv in grpData.meta_items(dn):
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(ditem, vals)
for mn, mv in grpData.meta_items():
vals = [mn, str(mv)]
self.groupItems.append(grpItem)
self.addTopLevelItem(grpItem)
dataParent = QtWidgets.QTreeWidgetItem(grpItem, ['[DATA]'])
metaParent = QtWidgets.QTreeWidgetItem(grpItem, ['[META]'])
for dn, dv in grpData.data_items():
vals = [grpData.label(dn), str(grpData.meta_val('shape', dn))]
if dn in grpData.dependents():
vals.append(f'Data (depends on {str(tuple(grpData.axes(dn)))[1:]}')
else:
vals.append('Data (independent)')
ditem = QtWidgets.QTreeWidgetItem(dataParent, vals)
for mn, mv in grpData.meta_items(dn):
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(ditem, vals)
for mn, mv in grpData.meta_items():
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(metaParent, vals)
grpItem.setExpanded(True)
dataParent.setExpanded(True)
for i in range(self.columnCount()-1):
self.resizeColumnToContents(i)
for dn, dv in grpData.data_items():
vals = [grpData.label(dn), str(grpData.meta_val('shape', dn))]
if dn in grpData.dependents():
vals.append(f'Data (depends on {str(tuple(grpData.axes(dn)))[1:]}')
else:
vals.append('Data (independent)')
ditem = QtWidgets.QTreeWidgetItem(dataParent, vals)
for mn, mv in grpData.meta_items(dn):
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(ditem, vals)
for mn, mv in grpData.meta_items():
vals = [mn, str(mv)]
_ = QtWidgets.QTreeWidgetItem(metaParent, vals)
grpItem.setExpanded(True)
dataParent.setExpanded(True)
for i in range(self.columnCount()-1):
self.resizeColumnToContents(i)
def remove(i):
parent = i.parent()
if isinstance(parent, DataFileList):
idx = parent.indexOfTopLevelItem(i)
parent.takeTopLevelItem(idx)
elif isinstance(parent, QtWidgets.QTreeWidgetItem):
parent.removeChild(i)
if parent.childCount() == 0:
remove(parent)