Skip to content

Commit

Permalink
Fix slider signal connections in _generic_range_slider.py and _generi…
Browse files Browse the repository at this point in the history
…c_slider.py

Fix #21
  • Loading branch information
PierreRaybaut committed Sep 10, 2024
1 parent bbf770c commit d23f82c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
27 changes: 18 additions & 9 deletions plotpy/external/sliders/_generic_range_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,29 @@ class _GenericRangeSlider(_GenericSlider):
integers.
"""

# Emitted when the slider value has changed, with the new slider values
_valuesChanged = Signal(tuple)

# Emitted when sliderDown is true and the slider moves
# This usually happens when the user is dragging the slider
# The value is the positions of *all* handles.
_slidersMoved = Signal(tuple)
# -- BEGIN -- Original implementation, causing segfault on Linux with PySide6
# https://github.com/PlotPyStack/PlotPy/issues/21
# _valuesChanged = Signal(tuple)
# _slidersMoved = Signal(tuple)
# -- END --

# -- BEGIN -- New implementation: avoid segfault by overriding the class attributes
# instead of overriding them through instance attributes in `__init__`
valueChanged = Signal(tuple)
sliderMoved = Signal(tuple)
# -- END --

def __init__(self, *args, **kwargs):
self._style = RangeSliderStyle()

super().__init__(*args, **kwargs)
self.valueChanged = self._valuesChanged
self.sliderMoved = self._slidersMoved

# -- BEGIN -- Original implementation, causing segfault on Linux with PySide6
# https://github.com/PlotPyStack/PlotPy/issues/21
# self.valueChanged = self._valuesChanged
# self.sliderMoved = self._slidersMoved
# -- END --

# list of values
self._value: List[_T] = [20, 80]

Expand Down
27 changes: 21 additions & 6 deletions plotpy/external/sliders/_generic_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
scalar (with one handle per item), and it forms the basis of
QRangeSlider.
"""

import os
import platform
from typing import TypeVar
Expand Down Expand Up @@ -59,9 +60,19 @@


class _GenericSlider(QSlider):
_fvalueChanged = Signal(int)
_fsliderMoved = Signal(int)
_frangeChanged = Signal(int, int)
# -- BEGIN -- Original implementation, causing segfault on Linux with PySide6
# https://github.com/PlotPyStack/PlotPy/issues/21
# _fvalueChanged = Signal(int)
# _fsliderMoved = Signal(int)
# _frangeChanged = Signal(int, int)
# -- END --

# -- BEGIN -- New implementation: avoid segfault by overriding the class attributes
# instead of overriding them through instance attributes in `__init__`
valueChanged = Signal(int)
sliderMoved = Signal(int)
rangeChanged = Signal(int, int)
# -- END --

MAX_DISPLAY = 5000

Expand All @@ -88,9 +99,13 @@ def __init__(self, *args, **kwargs) -> None:
self._control_fraction = 0.04

super().__init__(*args, **kwargs)
self.valueChanged = self._fvalueChanged
self.sliderMoved = self._fsliderMoved
self.rangeChanged = self._frangeChanged

# -- BEGIN -- Original implementation, causing segfault on Linux with PySide6
# https://github.com/PlotPyStack/PlotPy/issues/21
# self.valueChanged = self._fvalueChanged
# self.sliderMoved = self._fsliderMoved
# self.rangeChanged = self._frangeChanged
# -- END --

self.setAttribute(Qt.WidgetAttribute.WA_Hover)
self.setStyleSheet("")
Expand Down

0 comments on commit d23f82c

Please sign in to comment.