Skip to content

Commit

Permalink
Merge pull request #1079 from YektaY/pr-1078
Browse files Browse the repository at this point in the history
FIX: Fix to clicking on PyDMSilder running on MacOS
  • Loading branch information
jbellister-slac authored May 23, 2024
2 parents cd256db + 8e3bf5f commit ae70a5e
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions pydm/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -29,12 +28,40 @@
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.maximum() - self.value())
* (self.height() - self.handleWidth())
/ (self.maximum() - self.minimum())
)
click_pos = event.pos().y()

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:
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_SliderLength, None, self)
else:
return self.style().pixelMetric(self.style().PM_SliderThickness, None, self)


class PyDMSlider(QFrame, TextFormatter, PyDMWritableWidget, new_properties=_step_size_properties):
"""
Expand Down

0 comments on commit ae70a5e

Please sign in to comment.