2016-11-13 21:07:17 +00:00
|
|
|
# Copyright 2016, Chris PeBenito <pebenito@ieee.org>
|
|
|
|
#
|
2021-11-20 19:03:26 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-only
|
2016-11-13 21:07:17 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
from PyQt5.QtCore import Qt, QModelIndex
|
|
|
|
from PyQt5.QtGui import QKeySequence, QCursor
|
|
|
|
from PyQt5.QtWidgets import QAction, QApplication, QFileDialog, QMenu, QTreeWidget, \
|
2018-08-11 18:38:58 +00:00
|
|
|
QTreeWidgetItemIterator
|
2016-11-13 21:07:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SEToolsTreeWidget(QTreeWidget):
|
|
|
|
|
|
|
|
"""QTreeWidget class extended for SETools use."""
|
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
super(SEToolsTreeWidget, self).__init__(parent)
|
|
|
|
|
|
|
|
# set up right-click context menu
|
|
|
|
self.copy_tree_action = QAction("Copy Tree...", self)
|
|
|
|
self.menu = QMenu(self)
|
|
|
|
self.menu.addAction(self.copy_tree_action)
|
|
|
|
|
|
|
|
# connect signals
|
2022-11-29 18:19:05 +00:00
|
|
|
self.copy_tree_action.triggered.connect(self.copy)
|
2016-11-13 21:07:17 +00:00
|
|
|
|
|
|
|
def contextMenuEvent(self, event):
|
|
|
|
self.menu.popup(QCursor.pos())
|
|
|
|
|
2022-11-29 18:19:05 +00:00
|
|
|
def copy(self):
|
2016-11-13 21:07:17 +00:00
|
|
|
"""Copy the tree to the clipboard."""
|
|
|
|
|
|
|
|
items = []
|
|
|
|
inval_index = QModelIndex()
|
|
|
|
it = QTreeWidgetItemIterator(self)
|
|
|
|
prev_depth = 0
|
|
|
|
while it.value():
|
|
|
|
depth = 0
|
|
|
|
item = it.value()
|
|
|
|
parent = item.parent()
|
|
|
|
while parent:
|
|
|
|
depth += 1
|
|
|
|
parent = parent.parent()
|
|
|
|
|
|
|
|
if depth < prev_depth:
|
2018-08-11 18:38:58 +00:00
|
|
|
items.extend([" |" * depth, "\n"])
|
2016-11-13 21:07:17 +00:00
|
|
|
|
|
|
|
if depth:
|
2018-08-11 18:38:58 +00:00
|
|
|
items.extend([" |" * depth, "--", item.text(0), "\n"])
|
2016-11-13 21:07:17 +00:00
|
|
|
else:
|
|
|
|
items.extend([item.text(0), "\n"])
|
|
|
|
|
|
|
|
prev_depth = depth
|
|
|
|
it += 1
|
|
|
|
|
|
|
|
QApplication.clipboard().setText("".join(items))
|
|
|
|
|
2022-11-29 18:19:05 +00:00
|
|
|
def cut(self):
|
|
|
|
self.copy()
|