Override copy() and cut() functions for custom tree/table widgets

The Ctrl-C and Ctrl-X shortcuts are handled by the copy() and cut()
functions in the ApolMainWindow, which just get the currently focused
widget and call its function of the same name.

However, the custom SEToolsTableView and SEToolsTreeView widgets do not
use these functions to implement Ctrl-C/X, but instead override the
event() function and check if each received event is a copy/cut key
sequence. Functionally this is the same as copy() and cut(), but this
leads to an abort in newer versions for Fedora and/or PyQT5 (the reason
is not obvious).

To avoid the abort, and arguably make things a little more clear, this
overrides the copy() and cut() functions in these widgets, moves the
specialize copy logic into them, and removes the event() function.

Closes #77

Signed-off-by: Steve Lawrence <slawrence@owlcyberdefense.com>
This commit is contained in:
Steve Lawrence 2022-11-29 13:19:05 -05:00
parent cbf0b2f5b8
commit 8ecedcdf9c
2 changed files with 24 additions and 30 deletions

View File

@ -28,8 +28,7 @@ class SEToolsTableView(QTableView):
def contextMenuEvent(self, event):
self.menu.popup(QCursor.pos())
def event(self, e):
if e == QKeySequence.Copy or e == QKeySequence.Cut:
def copy(self):
datamodel = self.model()
selected_text = []
@ -52,10 +51,9 @@ class SEToolsTableView(QTableView):
prev_col = current_col
QApplication.clipboard().setText("".join(selected_text))
return True
else:
return super(SEToolsTableView, self).event(e)
def cut(self):
self.copy()
def choose_csv_save_location(self):
filename = QFileDialog.getSaveFileName(self, "Save to CSV", "table.csv",

View File

@ -22,12 +22,12 @@ class SEToolsTreeWidget(QTreeWidget):
self.menu.addAction(self.copy_tree_action)
# connect signals
self.copy_tree_action.triggered.connect(self.copy_tree)
self.copy_tree_action.triggered.connect(self.copy)
def contextMenuEvent(self, event):
self.menu.popup(QCursor.pos())
def copy_tree(self):
def copy(self):
"""Copy the tree to the clipboard."""
items = []
@ -55,9 +55,5 @@ class SEToolsTreeWidget(QTreeWidget):
QApplication.clipboard().setText("".join(items))
def event(self, e):
if e == QKeySequence.Copy or e == QKeySequence.Cut:
self.copy_tree()
return True
else:
return super(SEToolsTreeWidget, self).event(e)
def cut(self):
self.copy()