Skip to content

Commit

Permalink
MNT: add save button and change tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Oct 23, 2024
1 parent d8288e6 commit 2a99030
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions superscore/ui/nestable_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
</widget>
</widget>
</item>
<item>
<widget class="QPushButton" name="save_button">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
7 changes: 7 additions & 0 deletions superscore/ui/parameter_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="save_button">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
39 changes: 39 additions & 0 deletions superscore/widgets/page/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Widgets for visualizing and editing core model dataclasses
"""
import logging
from copy import deepcopy
from typing import Optional, Union

import qtawesome as qta
Expand Down Expand Up @@ -32,6 +33,8 @@ class NestablePage(Display, DataWidget):
sub_coll_table_view: NestableTableView
sub_pv_table_view: LivePVTableView

save_button: QtWidgets.QPushButton

data: Nestable

def __init__(
Expand All @@ -47,6 +50,7 @@ def __init__(
self.client = client
self.editable = editable
self.open_page_slot = open_page_slot
self._last_data = deepcopy(self.data)
self.setup_ui()

def setup_ui(self):
Expand All @@ -59,9 +63,25 @@ def setup_ui(self):

self.sub_pv_table_view.client = self.client
self.sub_pv_table_view.set_data(self.data)
self.sub_pv_table_view.data_updated.connect(self.track_changes)

self.sub_coll_table_view.client = self.client
self.sub_coll_table_view.set_data(self.data)
self.sub_coll_table_view.data_updated.connect(self.track_changes)

self.save_button.clicked.connect(self.save)

def save(self):
self.client.save(self.data)
self._last_data = deepcopy(self.data)

def track_changes(self):
if not self.data == self._last_data:
self.save_button.setText("Save *")
self.save_button.setEnabled(True)
else:
self.save_button.setText("Save")
self.save_button.setEnabled(False)

def closeEvent(self, a0: QCloseEvent) -> None:
logger.debug(f"Stopping polling threads for {type(self.data)}")
Expand Down Expand Up @@ -110,6 +130,8 @@ class BaseParameterPage(Display, DataWidget):
open_rbv_button: QtWidgets.QPushButton
rbv_pv_label: QtWidgets.QLabel

save_button: QtWidgets.QPushButton

_edata_thread: Optional[BusyCursorThread]
data: Union[Parameter, Setpoint, Readback]

Expand All @@ -128,6 +150,7 @@ def __init__(
self.value_stored_widget = None
self.edata = None
self._edata_thread: Optional[BusyCursorThread] = None
self._last_data = deepcopy(self.data)
self.setup_ui()

def setup_ui(self):
Expand All @@ -147,6 +170,8 @@ def setup_ui(self):
self.refresh_button.clicked.connect(self.get_edata)
self.get_edata()

self.save_button.clicked.connect(self.save)

try:
self.bridge.data.data
except AttributeError:
Expand Down Expand Up @@ -194,6 +219,8 @@ def setup_ui(self):
else:
self.setup_rbv_widget()

self.track_changes()

def get_edata(self) -> None:
if self._edata_thread and self._edata_thread.isRunning():
return
Expand Down Expand Up @@ -286,6 +313,18 @@ def setup_rbv_widget(self):
self.rbv_pv_label.setText(self.data.readback.pv_name)
self.open_rbv_button.clicked.connect(self.open_rbv_page)

def save(self):
self.client.save(self.data)
self._last_data = deepcopy(self.data)

def track_changes(self):
if not self.data == self._last_data:
self.save_button.setText("Save *")
self.save_button.setEnabled(True)
else:
self.save_button.setText("Save")
self.save_button.setEnabled(False)


class ParameterPage(BaseParameterPage):
data: Parameter
Expand Down
2 changes: 2 additions & 0 deletions superscore/widgets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def setData(self, index: QtCore.QModelIndex, value: Any, role: int) -> bool:
success = False

self.layoutChanged.emit()
self.dataChanged.emit(index, index)
return success

def flags(self, index: QtCore.QModelIndex) -> QtCore.Qt.ItemFlag:
Expand Down Expand Up @@ -1119,6 +1120,7 @@ def maybe_setup_model(self):
**self.model_kwargs
)
self.setModel(self._model)
self._model.dataChanged.connect(self.data_updated)
else:
self._model.set_entries(self.sub_entries)

Expand Down

0 comments on commit 2a99030

Please sign in to comment.