Skip to content

Commit d265841

Browse files
authored
Merge pull request #47 from Chilipp/onclose
Close the QApplication when closing the app widget
2 parents c863677 + b8345d9 commit d265841

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changed
55
-------
66
- The plotmethod tabs have now a more intuitive gridlayout (see
77
`#46 <https://github.com/psyplot/psy-view/pull/46>`__)
8+
- When closing the mainwindow of psy-view now, one closes all open windows (i.e.
9+
also the open figures, see
10+
`#47 <https://github.com/psyplot/psy-view/pull/47>`__)
811

912
Added
1013
-----

psy_view/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def start_app(
7878

7979
rcParams['help_explorer.use_webengineview'] = False
8080

81-
from psy_view.ds_widget import DatasetWidget
81+
from psy_view.ds_widget import DatasetWidgetStandAlone
8282
from psyplot_gui.common import get_icon
8383

8484
app = QtWidgets.QApplication(sys.argv)
85-
ds_widget = DatasetWidget(ds)
85+
ds_widget = DatasetWidgetStandAlone(ds)
8686
ds_widget.setWindowIcon(QIcon(get_icon('logo.svg')))
8787
if preset is not None:
8888
ds_widget.load_preset(preset)

psy_view/ds_widget.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
from matplotlib.backend_bases import MouseEvent
6565
from psyplot_gui.main import MainWindow
6666

67-
NOTSET_T = Type[object]
68-
NOTSET: NOTSET_T = object
67+
68+
NOTSET = "__NOVARIABLEAVAILABLE"
6969

7070

7171
def get_dims_to_iterate(arr: DataArray) -> List[str]:
@@ -125,6 +125,9 @@ class DatasetWidget(QtWidgets.QSplitter):
125125
#: A :class:`PyQt5.QtWidgets.QGroupBox` that contains the variable buttons
126126
variable_frame: Optional[QtWidgets.QGroupBox] = None
127127

128+
#: Buttons for selecting variables in the :attr:`ds`
129+
variable_buttons: Dict[str, QtWidgets.QPushButton]
130+
128131
_new_plot: bool = False
129132

130133
_preset: Optional[Union[str, Dict]] = None
@@ -318,7 +321,7 @@ def showEvent(self, event):
318321
ret = super().showEvent(event)
319322
current_size = self.size()
320323
current_sizes = self.sizes()
321-
new_sizes = list(current_sizes)
324+
322325
itree = self.indexOf(self.ds_tree)
323326
itable = self.indexOf(self.dimension_table)
324327
diff = 0
@@ -791,7 +794,7 @@ def _load_preset(self) -> None:
791794

792795
def load_preset(self, preset: Optional[Union[str, Dict[str, Any]]]):
793796
"""Load a given preset from disk.
794-
797+
795798
Parameters
796799
----------
797800
preset: str or dict
@@ -990,7 +993,7 @@ def export_project_with_data(self) -> None:
990993
def export_python(self):
991994
"""Export the project as python file.
992995
993-
This method is not yet implemented as the functionality is missing in
996+
This method is not yet implemented as the functionality is missing in
994997
psyplot.
995998
"""
996999
pass
@@ -1022,31 +1025,31 @@ def silence_variable_buttons(self) -> Iterator[None]:
10221025
yield self.block_widgets(*self.variable_buttons.values()) # type: ignore
10231026

10241027
@property
1025-
def variable(self) -> Union[str, NOTSET_T]:
1028+
def variable(self) -> str:
10261029
"""The current variable"""
10271030
for v, btn in self.variable_buttons.items():
10281031
if btn.isChecked():
10291032
return v
10301033
return NOTSET
10311034

10321035
@variable.setter
1033-
def variable(self, value: Union[str, NOTSET_T]) -> None:
1036+
def variable(self, value: str) -> None:
10341037
with self.silence_variable_buttons():
10351038
for v, btn in self.variable_buttons.items():
10361039
btn.setChecked(v == value)
10371040

10381041
@property
10391042
def available_plotmethods(self) -> List[str]:
10401043
"""Get the plotmethods that can visualize the selected variable.
1041-
1044+
10421045
Returns
10431046
-------
10441047
list of str
10451048
A list of plotmethod names that can visualize the current
10461049
:attr:`variable`
10471050
"""
10481051
v = self.variable
1049-
if v is NOTSET:
1052+
if v == NOTSET:
10501053
return []
10511054
ret = []
10521055
ds: Dataset = self.ds # type: ignore
@@ -1141,10 +1144,10 @@ def filter_sp(self, sp: Project, ds_only: bool = False) -> Project:
11411144

11421145
def new_plot(self) -> None:
11431146
"""Select a new variable and make a plot.
1144-
1147+
11451148
This method asks for a variable and them makes a new plot with the
11461149
selected plotmethod.
1147-
1150+
11481151
See Also
11491152
--------
11501153
make_plot: plot the currently selected variable without asking
@@ -1380,7 +1383,7 @@ def change_combo_array(self) -> None:
13801383
vname = self.data.name
13811384
except Exception:
13821385
vname = self.variable
1383-
if vname is not NOTSET:
1386+
if vname != NOTSET:
13841387
self.expand_current_variable(vname)
13851388
self.show_fig(sp[:1])
13861389

@@ -1410,7 +1413,7 @@ def reset_combo_array(self) -> None:
14101413
def refresh(self, reset_combo: bool = True) -> None:
14111414
"""Refresh the state of this widget.
14121415
1413-
This method refreshes the widget based on the selected project,
1416+
This method refreshes the widget based on the selected project,
14141417
variable, etc.
14151418
14161419
Parameters
@@ -1450,7 +1453,7 @@ def refresh(self, reset_combo: bool = True) -> None:
14501453
valid_variables = self.plotmethod_widget.valid_variables(self.ds)
14511454
for v, btn in self.variable_buttons.items():
14521455
btn.setEnabled(v in valid_variables)
1453-
elif self.ds is None or variable is NOTSET or not self.sp:
1456+
elif self.ds is None or variable == NOTSET or not self.sp:
14541457
return
14551458

14561459
table = self.dimension_table
@@ -1557,6 +1560,16 @@ def update():
15571560
return update
15581561

15591562

1563+
class DatasetWidgetStandAlone(DatasetWidget):
1564+
"""A :class:`DatasetWidget` that is supposed to work as a standalone GUI"""
1565+
1566+
def closeEvent(self, event: Any):
1567+
"""Reimplemented close event to stop the running ``QApplication``."""
1568+
ret = super().closeEvent(event)
1569+
QtWidgets.QApplication.instance().quit()
1570+
return ret
1571+
1572+
15601573
class DatasetWidgetPlugin(DatasetWidget, DockMixin):
15611574
"""A :class:`DatasetWidget` plugin for the psyplot GUI.
15621575
@@ -1653,7 +1666,7 @@ def show_fig(self, sp: Optional[Project]) -> None:
16531666

16541667
def setup_ds_tree(self) -> None:
16551668
"""Setup the number of columns and the header of the dataset tree.
1656-
1669+
16571670
Reimplemented to use the :class:`psyplot_gui.content_widget.DatasetTree`
16581671
"""
16591672
self.ds_tree = tree = DatasetTree()

0 commit comments

Comments
 (0)