|
14 | 14 | import json |
15 | 15 | from pathlib import Path |
16 | 16 | import tempfile |
17 | | - |
18 | 17 | import pandas as pd |
19 | | -from PySide6.QtCore import QMetaObject, QObject, QStandardPaths, Qt, QUrl, QSize, Slot |
| 18 | +from PySide6.QtCore import QMetaObject, QObject, QSize, QStandardPaths, Qt, QUrl, Slot |
20 | 19 | from PySide6.QtWebChannel import QWebChannel |
21 | 20 | from PySide6.QtWebEngineCore import QWebEngineDownloadRequest, QWebEngineScript |
22 | 21 | from PySide6.QtWebEngineWidgets import QWebEngineView |
23 | | -from PySide6.QtWidgets import QFileDialog, QVBoxLayout, QWidget |
| 22 | +from PySide6.QtWidgets import QDialog, QDialogButtonBox, QFileDialog, QLabel, QVBoxLayout, QWidget |
| 23 | + |
| 24 | + |
| 25 | +class WarnUser(QDialog): |
| 26 | + def __init__(self, msg: str, parent=None): |
| 27 | + super().__init__(parent) |
| 28 | + |
| 29 | + self.setWindowTitle("Warning!") |
| 30 | + self.buttonbox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok) |
| 31 | + self.buttonbox.accepted.connect(self.accept) |
| 32 | + |
| 33 | + layout = QVBoxLayout() |
| 34 | + self.message = QLabel(msg) |
| 35 | + layout.addWidget(self.message) |
| 36 | + layout.addWidget(self.buttonbox) |
| 37 | + self.setLayout(layout) |
24 | 38 |
|
25 | 39 |
|
26 | 40 | class PlotWidget(QWidget): |
@@ -108,11 +122,18 @@ def downloadFilteredCsv(self, visible_keys_json: str): |
108 | 122 | # - all legend items are hidden, export all w/ warning (FIXME) |
109 | 123 | # - first value is "ALL" when no legend is present, e.g. bar charts |
110 | 124 | filtered = self._plot.dataframe |
| 125 | + if len(visible_keys) == 0: |
| 126 | + warn_user = WarnUser( |
| 127 | + "All legend items are hidden, ignoring selection and exporting all data.", self._plot |
| 128 | + ) |
| 129 | + warn_user.exec() |
111 | 130 | case [str(), *_] as visible_keys: |
112 | 131 | filtered = self._plot.dataframe.query("|".join(visible_keys)) |
113 | 132 | if filtered.empty: |
114 | 133 | # FIXME: warn user |
115 | 134 | filtered = self._plot.dataframe |
| 135 | + warn_user = WarnUser("Empty selection, ignoring and exporting all data.", self._plot) |
| 136 | + warn_user.exec() |
116 | 137 | case keys: |
117 | 138 | raise RuntimeError(f"webchannel returned {keys}, something went terribly wrong!") |
118 | 139 |
|
|
0 commit comments