Skip to content

Commit a8d9e6e

Browse files
committed
plotting: warn user when exporting empty data file
1 parent 190f101 commit a8d9e6e

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

spinetoolbox/widgets/plot_widget.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,27 @@
1414
import json
1515
from pathlib import Path
1616
import tempfile
17-
1817
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
2019
from PySide6.QtWebChannel import QWebChannel
2120
from PySide6.QtWebEngineCore import QWebEngineDownloadRequest, QWebEngineScript
2221
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)
2438

2539

2640
class PlotWidget(QWidget):
@@ -108,11 +122,18 @@ def downloadFilteredCsv(self, visible_keys_json: str):
108122
# - all legend items are hidden, export all w/ warning (FIXME)
109123
# - first value is "ALL" when no legend is present, e.g. bar charts
110124
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()
111130
case [str(), *_] as visible_keys:
112131
filtered = self._plot.dataframe.query("|".join(visible_keys))
113132
if filtered.empty:
114133
# FIXME: warn user
115134
filtered = self._plot.dataframe
135+
warn_user = WarnUser("Empty selection, ignoring and exporting all data.", self._plot)
136+
warn_user.exec()
116137
case keys:
117138
raise RuntimeError(f"webchannel returned {keys}, something went terribly wrong!")
118139

0 commit comments

Comments
 (0)