|
64 | 64 | from matplotlib.backend_bases import MouseEvent |
65 | 65 | from psyplot_gui.main import MainWindow |
66 | 66 |
|
67 | | -NOTSET_T = Type[object] |
68 | | -NOTSET: NOTSET_T = object |
| 67 | + |
| 68 | +NOTSET = "__NOVARIABLEAVAILABLE" |
69 | 69 |
|
70 | 70 |
|
71 | 71 | def get_dims_to_iterate(arr: DataArray) -> List[str]: |
@@ -125,6 +125,9 @@ class DatasetWidget(QtWidgets.QSplitter): |
125 | 125 | #: A :class:`PyQt5.QtWidgets.QGroupBox` that contains the variable buttons |
126 | 126 | variable_frame: Optional[QtWidgets.QGroupBox] = None |
127 | 127 |
|
| 128 | + #: Buttons for selecting variables in the :attr:`ds` |
| 129 | + variable_buttons: Dict[str, QtWidgets.QPushButton] |
| 130 | + |
128 | 131 | _new_plot: bool = False |
129 | 132 |
|
130 | 133 | _preset: Optional[Union[str, Dict]] = None |
@@ -318,7 +321,7 @@ def showEvent(self, event): |
318 | 321 | ret = super().showEvent(event) |
319 | 322 | current_size = self.size() |
320 | 323 | current_sizes = self.sizes() |
321 | | - new_sizes = list(current_sizes) |
| 324 | + |
322 | 325 | itree = self.indexOf(self.ds_tree) |
323 | 326 | itable = self.indexOf(self.dimension_table) |
324 | 327 | diff = 0 |
@@ -791,7 +794,7 @@ def _load_preset(self) -> None: |
791 | 794 |
|
792 | 795 | def load_preset(self, preset: Optional[Union[str, Dict[str, Any]]]): |
793 | 796 | """Load a given preset from disk. |
794 | | - |
| 797 | +
|
795 | 798 | Parameters |
796 | 799 | ---------- |
797 | 800 | preset: str or dict |
@@ -990,7 +993,7 @@ def export_project_with_data(self) -> None: |
990 | 993 | def export_python(self): |
991 | 994 | """Export the project as python file. |
992 | 995 |
|
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 |
994 | 997 | psyplot. |
995 | 998 | """ |
996 | 999 | pass |
@@ -1022,31 +1025,31 @@ def silence_variable_buttons(self) -> Iterator[None]: |
1022 | 1025 | yield self.block_widgets(*self.variable_buttons.values()) # type: ignore |
1023 | 1026 |
|
1024 | 1027 | @property |
1025 | | - def variable(self) -> Union[str, NOTSET_T]: |
| 1028 | + def variable(self) -> str: |
1026 | 1029 | """The current variable""" |
1027 | 1030 | for v, btn in self.variable_buttons.items(): |
1028 | 1031 | if btn.isChecked(): |
1029 | 1032 | return v |
1030 | 1033 | return NOTSET |
1031 | 1034 |
|
1032 | 1035 | @variable.setter |
1033 | | - def variable(self, value: Union[str, NOTSET_T]) -> None: |
| 1036 | + def variable(self, value: str) -> None: |
1034 | 1037 | with self.silence_variable_buttons(): |
1035 | 1038 | for v, btn in self.variable_buttons.items(): |
1036 | 1039 | btn.setChecked(v == value) |
1037 | 1040 |
|
1038 | 1041 | @property |
1039 | 1042 | def available_plotmethods(self) -> List[str]: |
1040 | 1043 | """Get the plotmethods that can visualize the selected variable. |
1041 | | - |
| 1044 | +
|
1042 | 1045 | Returns |
1043 | 1046 | ------- |
1044 | 1047 | list of str |
1045 | 1048 | A list of plotmethod names that can visualize the current |
1046 | 1049 | :attr:`variable` |
1047 | 1050 | """ |
1048 | 1051 | v = self.variable |
1049 | | - if v is NOTSET: |
| 1052 | + if v == NOTSET: |
1050 | 1053 | return [] |
1051 | 1054 | ret = [] |
1052 | 1055 | ds: Dataset = self.ds # type: ignore |
@@ -1141,10 +1144,10 @@ def filter_sp(self, sp: Project, ds_only: bool = False) -> Project: |
1141 | 1144 |
|
1142 | 1145 | def new_plot(self) -> None: |
1143 | 1146 | """Select a new variable and make a plot. |
1144 | | - |
| 1147 | +
|
1145 | 1148 | This method asks for a variable and them makes a new plot with the |
1146 | 1149 | selected plotmethod. |
1147 | | - |
| 1150 | +
|
1148 | 1151 | See Also |
1149 | 1152 | -------- |
1150 | 1153 | make_plot: plot the currently selected variable without asking |
@@ -1380,7 +1383,7 @@ def change_combo_array(self) -> None: |
1380 | 1383 | vname = self.data.name |
1381 | 1384 | except Exception: |
1382 | 1385 | vname = self.variable |
1383 | | - if vname is not NOTSET: |
| 1386 | + if vname != NOTSET: |
1384 | 1387 | self.expand_current_variable(vname) |
1385 | 1388 | self.show_fig(sp[:1]) |
1386 | 1389 |
|
@@ -1410,7 +1413,7 @@ def reset_combo_array(self) -> None: |
1410 | 1413 | def refresh(self, reset_combo: bool = True) -> None: |
1411 | 1414 | """Refresh the state of this widget. |
1412 | 1415 |
|
1413 | | - This method refreshes the widget based on the selected project, |
| 1416 | + This method refreshes the widget based on the selected project, |
1414 | 1417 | variable, etc. |
1415 | 1418 |
|
1416 | 1419 | Parameters |
@@ -1450,7 +1453,7 @@ def refresh(self, reset_combo: bool = True) -> None: |
1450 | 1453 | valid_variables = self.plotmethod_widget.valid_variables(self.ds) |
1451 | 1454 | for v, btn in self.variable_buttons.items(): |
1452 | 1455 | 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: |
1454 | 1457 | return |
1455 | 1458 |
|
1456 | 1459 | table = self.dimension_table |
@@ -1557,6 +1560,16 @@ def update(): |
1557 | 1560 | return update |
1558 | 1561 |
|
1559 | 1562 |
|
| 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 | + |
1560 | 1573 | class DatasetWidgetPlugin(DatasetWidget, DockMixin): |
1561 | 1574 | """A :class:`DatasetWidget` plugin for the psyplot GUI. |
1562 | 1575 |
|
@@ -1653,7 +1666,7 @@ def show_fig(self, sp: Optional[Project]) -> None: |
1653 | 1666 |
|
1654 | 1667 | def setup_ds_tree(self) -> None: |
1655 | 1668 | """Setup the number of columns and the header of the dataset tree. |
1656 | | - |
| 1669 | +
|
1657 | 1670 | Reimplemented to use the :class:`psyplot_gui.content_widget.DatasetTree` |
1658 | 1671 | """ |
1659 | 1672 | self.ds_tree = tree = DatasetTree() |
|
0 commit comments