Skip to content

Commit

Permalink
MNT: expand EditTree by default, add copy-to-clipboard button, hide s…
Browse files Browse the repository at this point in the history
…uccess by default, quote any piece of data with a comma for csv parsing
  • Loading branch information
tangkong committed Nov 1, 2023
1 parent 30d168e commit 00b7fc3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
21 changes: 16 additions & 5 deletions atef/ui/results_summary.ui
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,22 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QPushButton" name="save_text_button">
<property name="text">
<string>Save Text Output</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="save_text_button">
<property name="text">
<string>Save Text Output</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clipboard_button">
<property name="text">
<string>Copy to Clipboard</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down
45 changes: 30 additions & 15 deletions atef/widgets/config/result_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class ResultsSummaryWidget(DesignerDisplay, QtWidgets.QWidget):

refresh_button: QtWidgets.QToolButton
save_text_button: QtWidgets.QPushButton
clipboard_button: QtWidgets.QPushButton

def __init__(self, *args, file: Any, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -390,16 +391,9 @@ def setup_ui(self) -> None:
self.results_table.setSortingEnabled(True)
self.results_table.horizontalHeader().setStretchLastSection(True)

self.success_check.setChecked(True)
self.warning_check.setChecked(True)
self.error_check.setChecked(True)

# setup type combo box
self.type_combo = CheckableComboBox()
insert_widget(self.type_combo, self.type_combo_placeholder)
# Fill combo box with types
for dclass_type in self.model.dclass_types():
self.type_combo.addItem(dclass_type)

# connect filter widgets
self.name_edit.textChanged.connect(self.filters_changed)
Expand All @@ -414,8 +408,11 @@ def setup_ui(self) -> None:
self.refresh_button.setIcon(refresh_icon)
self.refresh_button.clicked.connect(self.refresh_results)

# setup save button
# setup save buttons
self.save_text_button.clicked.connect(self.save_text)
self.clipboard_button.clicked.connect(self.copy_to_clipboard)

self.refresh_results()

def filters_changed(self, *args, **kwargs) -> None:
""" Update all the filters on the proxy model """
Expand Down Expand Up @@ -451,12 +448,13 @@ def get_plain_text(self) -> str:
row = []
for j in range(self.proxy_model.columnCount()):
index = self.proxy_model.index(i, j)
row.append(
self.proxy_model.data(index, Qt.DisplayRole) or ''
)
data = self.proxy_model.data(index, Qt.DisplayRole) or ''
if ',' in data:
data = f'"{data}"'
row.append(data)
if row[0].startswith('['):
row[0] = row[0][4:] # strip out icon from plain text
text += ', '.join(row)
text += ','.join(row)
return text

def update_plain_text(self) -> None:
Expand All @@ -477,8 +475,10 @@ def refresh_results(self) -> None:
# reset all the settings/filters
self.name_edit.setText('')
self.reason_edit.setText('')
for box in self.status_map.values():
box.setChecked(True)

self.success_check.setChecked(False)
self.warning_check.setChecked(True)
self.error_check.setChecked(True)

# re-setup type combo box
self.type_combo.clear()
Expand All @@ -503,4 +503,19 @@ def save_text(self) -> None:
with open(filename, 'w') as fd:
writer = csv.writer(fd)
for row in text:
writer.writerow(row.split(','))
writer.writerow(row.split(',', 3))

def copy_to_clipboard(self) -> None:
""" Copy the plain-text results table to the clipboard """
text = self.get_plain_text()
if not text:
return

QtGui.QGuiApplication.clipboard().setText(text)

self._msg = QtWidgets.QMessageBox(parent=self)
self._msg.setText(
'Plain-text results copied to clipboard.',
)
self._msg.setWindowTitle('Results Copied!')
self._msg.exec()
1 change: 1 addition & 0 deletions atef/widgets/config/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def __init__(
self.show_selected_display
)
self.tree_widget.setCurrentItem(self.root_item)
self.tree_widget.expandAll()

def assemble_tree(self):
"""
Expand Down

0 comments on commit 00b7fc3

Please sign in to comment.