Skip to content

Commit

Permalink
ENH: add editable modes to entry widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Oct 23, 2024
1 parent 2a99030 commit 0a1ecc4
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 72 deletions.
148 changes: 81 additions & 67 deletions superscore/ui/parameter_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>452</width>
<height>199</height>
<width>432</width>
<height>229</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -17,69 +17,83 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="pv_value_hlayout">
<item>
<widget class="QLabel" name="pv_label">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>PV Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pv_edit">
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="eq_label">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>=</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="value_stored_placeholder" native="true"/>
</item>
<item>
<widget class="QLabel" name="value_live_label">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>(Live)</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="refresh_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="pv_value_widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="pv_label">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>PV Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pv_edit">
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="eq_label">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>=</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="value_stored_placeholder" native="true"/>
</item>
<item>
<widget class="QLabel" name="value_live_label">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>(Live)</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="refresh_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="options_hlayout">
Expand Down Expand Up @@ -200,14 +214,14 @@
</property>
<item>
<layout class="QFormLayout" name="timeout_form_layout">
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="timeout_label">
<property name="text">
<string>timeout</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="timeout_spinbox"/>
</item>
</layout>
Expand Down
54 changes: 49 additions & 5 deletions superscore/widgets/page/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def setup_ui(self):

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

self.set_editable(self.editable)

def set_editable(self, editable: bool) -> None:
for col in self.sub_pv_table_view._model.header_enum:
self.sub_pv_table_view.set_editable(col, editable)

for col in self.sub_coll_table_view._model.header_enum:
self.sub_coll_table_view.set_editable(col, editable)

if editable:
self.save_button.show()
else:
self.save_button.hide()

self.editable = editable

def save(self):
self.client.save(self.data)
self._last_data = deepcopy(self.data)
Expand Down Expand Up @@ -104,11 +120,14 @@ class BaseParameterPage(Display, DataWidget):
meta_widget: NameDescTagsWidget

# Container widgets
pv_value_hlayout: QtWidgets.QHBoxLayout
pv_value_widget: QtWidgets.QWidget
options_hlayout: QtWidgets.QHBoxLayout
tol_widget: QtWidgets.QWidget
tol_form_layout: QtWidgets.QFormLayout
ss_widget: QtWidgets.QWidget
ss_form_layout: QtWidgets.QFormLayout
timeout_widget: QtWidgets.QWidget
timeout_form_layout: QtWidgets.QFormLayout
rbv_widget: QtWidgets.QWidget

# dynamic display/edit widgets
Expand Down Expand Up @@ -220,6 +239,7 @@ def setup_ui(self):
self.setup_rbv_widget()

self.track_changes()
self.set_editable(self.editable)

def get_edata(self) -> None:
if self._edata_thread and self._edata_thread.isRunning():
Expand All @@ -230,6 +250,29 @@ def get_edata(self) -> None:
def _get_edata(self):
self.edata = self.client.cl.get(self.data.pv_name)

def set_editable(self, editable: bool) -> None:
self.pv_edit.setReadOnly(not editable)
if self.value_stored_widget is not None:
self.value_stored_widget.setEnabled(editable)

for form_layout in (self.ss_form_layout, self.tol_form_layout,
self.timeout_form_layout):
for i in range(form_layout.rowCount()):
item = form_layout.itemAt(i, QtWidgets.QFormLayout.FieldRole)

# designer can sometimes sneak blank rows or start at i=1
if item is not None:
item.widget().setEnabled(editable)

self.open_rbv_button.setEnabled(editable)

if editable:
self.save_button.show()
else:
self.save_button.hide()

self.editable = editable

def update_stored_edit_widget(self):
data = self.edata
if not isinstance(data, EpicsData):
Expand All @@ -242,10 +285,11 @@ def update_stored_edit_widget(self):
else:
new_widget = edit_widget_from_epics_data(data)

if self.value_stored_widget:
insert_widget(new_widget, self.value_stored_widget)
else:
insert_widget(new_widget, self.value_stored_placeholder)
insert_widget(new_widget, self.value_stored_placeholder)
self.value_stored_widget = new_widget

# update edit status in case new widgets created
self.set_editable(self.editable)

def update_live_value(self):
data = self.edata
Expand Down

0 comments on commit 0a1ecc4

Please sign in to comment.