def checkbox_toggled(self, node: QTreeWidgetItem, column: int): if node.checkState(column) == Qt.Checked: self.selectedList.append( [node.text(0), node.text(1), node.text(2)]) elif node.checkState(column) == Qt.Unchecked: if len(self.selectedList) > 1: self.selectedList.remove( [node.text(0), node.text(1), node.text(2)]) else: self.selectedList = []
def on_treeitem_clicked(self, treeItem: QtWidgets.QTreeWidgetItem): label = treeItem.text(0) identifier = treeItem.text(2) print(treeItem, label, identifier) controller = self.controllers[identifier] if identifier not in self.subviews: sub = self.mdi.addSubWindow(controller.view) self.subviews[identifier] = sub else: for subview in self.subviews.values(): subview.hide() self.show_subview(self.subviews[identifier])
def item_clicked(item: QtWidgets.QTreeWidgetItem): if item.parent() is None: return value = self.redis.get(item.text(0)) value = value.decode() text = json.dumps(json.loads(value), ensure_ascii=False, indent=4) text = text.replace(" ", " ").replace("\n", "<br/>").replace(":", "<font color=red>:</font>") text = re.sub(r'"(.*?)(?<!\\)"', r'<font color=green>"\g<1>"</font>', text) self.label.setHtml(text)
def choose_ticker(self, item: QtWidgets.QTreeWidgetItem, column: int): """Click on an item inside the treewidget :param item: The selected item :type item: QTreeWidgetItem :param column: The column selected :type column: int """ ticker_name = item.text(0) self.signal.sig_ticker_choosen.emit(ticker_name) self.close()
def get_path_for_item(self, item: QtWidgets.QTreeWidgetItem) -> str: """Returns the absolute os path for given item.""" path = [] path.append(item.text(0)) parent = item.parent() while parent is not None: path.insert(0, parent.text(0)) parent = parent.parent() return os.path.join(self.root_path, *path)
def maintain_model(item: QTreeWidgetItem, _): option = item.text(0) if not is_option(option): return checked = item.checkState(0) if (option in self._options) == checked: return if checked: self._options.add(option) else: self._options.remove(option) for child in children_items: if child is not item and child.text(0) == option: child.setCheckState(0, checked)
def extractOnlyOneFile(self, archive: zipfile.ZipFile, item: QtWidgets.QTreeWidgetItem) -> None: path = archive.extract(item.text(6), tempDir.name) archive.close() self.showFileSignal.emit(path)
def init_ui(self): self.setWindowTitle('Trace Event Window') self.setGeometry(100, 100, 800, 600) bar = self.menuBar() file_ = bar.addMenu('File') export_log = QAction('Save to File', self, triggered=lambda: self.save_log()) options = bar.addMenu('Options') auto_refresh = QAction( 'Auto Refresh', self, checkable=True, triggered=lambda: self.timer.start(100) if auto_refresh.isChecked() else self.timer.stop()) auto_refresh.setChecked(True) options.addAction(auto_refresh) file_.addAction(export_log) vgrid = QVBoxLayout() grid = QHBoxLayout() self.tree = QTreeWidget() self.tree.setHeaderLabels(['Name']) self.top = [] self.lst = [] for n, event in enumerate(self.trace_events): word = event.split('_')[0] if word not in self.top: self.top.append(word) item = QTreeWidgetItem(self.tree) self.lst.append(item) item.setText(0, word) subitem = QTreeWidgetItem(item) subitem.setText(0, ' ' + event.split(' : ')[0]) # subitem.setCheckState(0, Qt.Unchecked) cbox = QCheckBox() cbox.stateChanged.connect(lambda state, text=subitem.text(0): self. handle_checked(state, text)) self.tree.setItemWidget(subitem, 0, cbox) # self.tree.setColumnWidth(0, 25) self.tracelist = QLabel() self.disp_output() self.traceview = QScrollArea() self.traceview.setWidget(self.tracelist) self.traceview.setWidgetResizable(True) search = QHBoxLayout() self.search_bar = QLineEdit(self) self.completer = QCompleter(self.top, self) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.search_bar.setCompleter(self.completer) search_button = QPushButton('Search') search_button.clicked.connect(lambda: self.tree.setCurrentItem( self.lst[self.top.index(self.search_bar.text())])) expand = QPushButton('▼') expand.setFixedSize(QSize(25, 25)) expand.clicked.connect(lambda: self.tree.expandAll()) collapse = QPushButton('▲') collapse.setFixedSize(QSize(25, 25)) collapse.clicked.connect(lambda: self.tree.collapseAll()) self.search_bar.returnPressed.connect(lambda: search_button.click()) search.addWidget(self.search_bar) search.addWidget(search_button) search.addWidget(expand) search.addWidget(collapse) self.digest = QLabel() vgrid.addLayout(search) vgrid.addWidget(self.tree) vgridwid = QWidget() vgridwid.setLayout(vgrid) split = QSplitter(Qt.Horizontal) split.addWidget(vgridwid) split.addWidget(self.traceview) split.setStretchFactor(1, 1) # grid.addLayout(vgrid) grid.addWidget(split) # grid.addWidget(self.tracelist) self.disp_output() center = QWidget() center.setLayout(grid) self.setCentralWidget(center) self.show()