From d46bf4ea4d5161d9550a91525d203f18fdc30acf Mon Sep 17 00:00:00 2001 From: YektaY Date: Mon, 20 May 2024 15:56:06 -0700 Subject: [PATCH 1/3] fix for mac left click issue --- pydm/widgets/slider.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pydm/widgets/slider.py b/pydm/widgets/slider.py index 07eea2914..50558041e 100644 --- a/pydm/widgets/slider.py +++ b/pydm/widgets/slider.py @@ -19,7 +19,6 @@ from .base import PyDMWritableWidget, TextFormatter, is_channel_valid from .channel import PyDMChannel - logger = logging.getLogger(__name__) _step_size_properties = { "Set Step Size ": ["step_size", float], @@ -29,12 +28,30 @@ class PyDMPrimitiveSlider(QSlider): def mousePressEvent(self, event): if event.button() == Qt.MiddleButton: - # Ignore middle-click events return - else: - # Call the default mousePressEvent implementation for other mouse buttons + + if event.button() == Qt.RightButton: super().mousePressEvent(event) + if event.button() == Qt.LeftButton: + if self.orientation() == Qt.Horizontal: + handle_pos = self.value() * (self.width() - self.handleWidth()) / (self.maximum() - self.minimum()) + click_pos = event.pos().x() + else: + handle_pos = self.value() * (self.height() - self.handleWidth()) / (self.maximum() - self.minimum()) + click_pos = event.pos().y() + + if click_pos > handle_pos: + self.setValue(self.value() + self.singleStep()) + else: + self.setValue(self.value() - self.singleStep()) + + def handleWidth(self): + if self.orientation() == Qt.Horizontal: + return self.style().pixelMetric(self.style().PM_SliderThickness, None, self) + else: + return self.style().pixelMetric(self.style().PM_SliderLength, None, self) + class PyDMSlider(QFrame, TextFormatter, PyDMWritableWidget, new_properties=_step_size_properties): """ From 3d0376e9195041b13bc8cda2f32e2cb1f1c78206 Mon Sep 17 00:00:00 2001 From: YektaY Date: Wed, 22 May 2024 15:12:13 -0700 Subject: [PATCH 2/3] formatting fix --- pydm/widgets/slider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydm/widgets/slider.py b/pydm/widgets/slider.py index 50558041e..173f92f59 100644 --- a/pydm/widgets/slider.py +++ b/pydm/widgets/slider.py @@ -51,7 +51,7 @@ def handleWidth(self): return self.style().pixelMetric(self.style().PM_SliderThickness, None, self) else: return self.style().pixelMetric(self.style().PM_SliderLength, None, self) - + class PyDMSlider(QFrame, TextFormatter, PyDMWritableWidget, new_properties=_step_size_properties): """ From 8e3bf5f02f812e6923181440485b72ca1190769a Mon Sep 17 00:00:00 2001 From: YektaY Date: Thu, 23 May 2024 12:14:15 -0700 Subject: [PATCH 3/3] fixed issue with vertical slider --- pydm/widgets/slider.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pydm/widgets/slider.py b/pydm/widgets/slider.py index 9683aefc3..db67101a4 100644 --- a/pydm/widgets/slider.py +++ b/pydm/widgets/slider.py @@ -38,19 +38,29 @@ def mousePressEvent(self, event): handle_pos = self.value() * (self.width() - self.handleWidth()) / (self.maximum() - self.minimum()) click_pos = event.pos().x() else: - handle_pos = self.value() * (self.height() - self.handleWidth()) / (self.maximum() - self.minimum()) + handle_pos = ( + (self.maximum() - self.value()) + * (self.height() - self.handleWidth()) + / (self.maximum() - self.minimum()) + ) click_pos = event.pos().y() - if click_pos > handle_pos: - self.setValue(self.value() + self.singleStep()) + if self.orientation() == Qt.Horizontal: + if click_pos > handle_pos + self.handleWidth() / 2: + self.setValue(self.value() + self.singleStep()) + else: + self.setValue(self.value() - self.singleStep()) else: - self.setValue(self.value() - self.singleStep()) + if click_pos < handle_pos + self.handleWidth() / 2: + self.setValue(self.value() + self.singleStep()) + else: + self.setValue(self.value() - self.singleStep()) def handleWidth(self): if self.orientation() == Qt.Horizontal: - return self.style().pixelMetric(self.style().PM_SliderThickness, None, self) - else: return self.style().pixelMetric(self.style().PM_SliderLength, None, self) + else: + return self.style().pixelMetric(self.style().PM_SliderThickness, None, self) class PyDMSlider(QFrame, TextFormatter, PyDMWritableWidget, new_properties=_step_size_properties):