From 9572ecf10562ab0747e168c37a4ca4e7e9034a14 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Tue, 13 May 2025 20:24:21 -0700 Subject: [PATCH 1/4] BUG: stop designer from setting line-edits in ui file to be readOnly when PYDM_DESIGNER_ONLINE enabled when editing a lineedit widget in designer after doing 'export PYDM_DESIGNER_ONLINE=1', we want widgets to act as read-only so PVs are not accidentally changed when modifying screens. this is enforced by the dataplugins themselves and is_read_only() (set during designer setup: https://github.com/slaclab/pydm/blob/master/pydm/qtdesigner.py#L47) but we don't want the readOnly=true status to be saved into the ui file containing the lineedit. to avoid this, don't let lineedit set itself to readOnly if it's loaded in designer with live data enabled. (it will still act in a read-only way thanks to dataplugins themselves) --- pydm/widgets/line_edit.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pydm/widgets/line_edit.py b/pydm/widgets/line_edit.py index 8fc04e4c0..f9a6fd511 100755 --- a/pydm/widgets/line_edit.py +++ b/pydm/widgets/line_edit.py @@ -10,7 +10,7 @@ from .base import PyDMWritableWidget, TextFormatter, str_types, PostParentClassInitSetup from pydm import utilities from .display_format import DisplayFormat, parse_value_for_display -from pydm.utilities import ACTIVE_QT_WRAPPER, QtWrapperTypes +from pydm.utilities import ACTIVE_QT_WRAPPER, QtWrapperTypes, is_qt_designer logger = logging.getLogger(__name__) @@ -162,7 +162,13 @@ def send_value(self): def setReadOnly(self, readOnly): self._user_set_read_only = readOnly - super().setReadOnly(True if self._user_set_read_only else not self._write_access) + shouldSetReadOnly = True if self._user_set_read_only else (not self._write_access) + # When in designer and reading in live data (DESIGNER_ONLINE), don't set and therefore save to + # the ui file readOnly=True setting. While we do want widgets to act in read-only way in designer + # (so don't accidentally write data during editing), this is handled in the data_plugins themselves. + if is_qt_designer() and config.DESIGNER_ONLINE: + shouldSetReadOnly = False + super().setReadOnly(shouldSetReadOnly) def write_access_changed(self, new_write_access): """ @@ -170,6 +176,12 @@ def write_access_changed(self, new_write_access): """ super().write_access_changed(new_write_access) if not self._user_set_read_only: + shouldSetReadOnly = not new_write_access + # When in designer and reading in live data (DESIGNER_ONLINE), don't set and therefore save to + # the ui file readOnly=True setting. While we do want widgets to act in read-only way in designer + # (so don't accidentally write data during editing), this is handled in the data_plugins themselves. + if is_qt_designer() and config.DESIGNER_ONLINE: + shouldSetReadOnly = False super().setReadOnly(not new_write_access) def unit_changed(self, new_unit): From c7f916d14f4e791d46228ba22bd54c3219dfc9a8 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Wed, 14 May 2025 16:18:45 -0700 Subject: [PATCH 2/4] BUG: oops accidently removed importing of config in last commit, adding back in --- pydm/widgets/line_edit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydm/widgets/line_edit.py b/pydm/widgets/line_edit.py index f9a6fd511..b9ffbb692 100755 --- a/pydm/widgets/line_edit.py +++ b/pydm/widgets/line_edit.py @@ -8,7 +8,7 @@ from qtpy.QtCore import Property, Qt from qtpy.QtGui import QFocusEvent from .base import PyDMWritableWidget, TextFormatter, str_types, PostParentClassInitSetup -from pydm import utilities +from pydm import utilities, config from .display_format import DisplayFormat, parse_value_for_display from pydm.utilities import ACTIVE_QT_WRAPPER, QtWrapperTypes, is_qt_designer From aa92c5452a00ed51a42982a948c6544962751cb7 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Wed, 14 May 2025 16:52:39 -0700 Subject: [PATCH 3/4] STY: make if statement more 'pythonic/pep8y' --- pydm/widgets/line_edit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pydm/widgets/line_edit.py b/pydm/widgets/line_edit.py index b9ffbb692..c0d5d73ec 100755 --- a/pydm/widgets/line_edit.py +++ b/pydm/widgets/line_edit.py @@ -162,12 +162,13 @@ def send_value(self): def setReadOnly(self, readOnly): self._user_set_read_only = readOnly - shouldSetReadOnly = True if self._user_set_read_only else (not self._write_access) # When in designer and reading in live data (DESIGNER_ONLINE), don't set and therefore save to # the ui file readOnly=True setting. While we do want widgets to act in read-only way in designer # (so don't accidentally write data during editing), this is handled in the data_plugins themselves. if is_qt_designer() and config.DESIGNER_ONLINE: shouldSetReadOnly = False + else: + shouldSetReadOnly = self._user_set_read_only or not self._write_access super().setReadOnly(shouldSetReadOnly) def write_access_changed(self, new_write_access): @@ -176,12 +177,13 @@ def write_access_changed(self, new_write_access): """ super().write_access_changed(new_write_access) if not self._user_set_read_only: - shouldSetReadOnly = not new_write_access # When in designer and reading in live data (DESIGNER_ONLINE), don't set and therefore save to # the ui file readOnly=True setting. While we do want widgets to act in read-only way in designer # (so don't accidentally write data during editing), this is handled in the data_plugins themselves. if is_qt_designer() and config.DESIGNER_ONLINE: shouldSetReadOnly = False + else: + shouldSetReadOnly = not new_write_access super().setReadOnly(not new_write_access) def unit_changed(self, new_unit): From eaafa008509be34f50e5f51f77bb44a246846f39 Mon Sep 17 00:00:00 2001 From: nstelter-slac Date: Wed, 14 May 2025 16:54:21 -0700 Subject: [PATCH 4/4] BUG: actually use correct var in setReadOnly call --- pydm/widgets/line_edit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydm/widgets/line_edit.py b/pydm/widgets/line_edit.py index c0d5d73ec..7ff97a85b 100755 --- a/pydm/widgets/line_edit.py +++ b/pydm/widgets/line_edit.py @@ -184,7 +184,7 @@ def write_access_changed(self, new_write_access): shouldSetReadOnly = False else: shouldSetReadOnly = not new_write_access - super().setReadOnly(not new_write_access) + super().setReadOnly(shouldSetReadOnly) def unit_changed(self, new_unit): """