-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternalWidgets.py
111 lines (89 loc) · 4.11 KB
/
internalWidgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# https://pyapp-kit.github.io/superqt/widgets/
from qtpy.QtCore import Signal
from superqt import QRangeSlider
from abstracts import AbstractModelWidget
from gui.slider_filter_ui import Ui_SliderFilter
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QFrame
class QtSliderFilterWidgetPlugin(AbstractModelWidget, QFrame, Ui_SliderFilter):
trimmerChanged = Signal(tuple) #spinner changed or slider changed in any way or any cain
selectionCountChanged = Signal(int) #When selection in slider changed
selectionCnt = 0
mainSeriesMin: 1 # min value on current main series
mainSeriesMax: 1 # max value on current main series
_min = 0 # current min value
_max = 0 # current max value
def _setupUi(self) -> None:
self._insertRangeSlider()
self._min = 0
self._max = 0
self.trimmerChanged.connect(self.model.trimRows)
self.model.mainSeriesLengthChanged.connect(lambda value: self.setMainRange(0, value))
def _insertRangeSlider(self):
self.setEnabled(False)
self.sliderFilter = QRangeSlider(self)
self.sliderFilter.setOrientation(Qt.Orientation.Horizontal)
self.sliderFilter.setObjectName("verticalSlider")
self.sliderFilter.setRange(0, 1)
self.sliderFilter.applyMacStylePatch()
self.sliderFilter.setSliderPosition([self._max, self._min])
self.spinBoxRangeMax.setValue(self._max)
self.spinBoxRangeMin.setValue(self._min)
self.horizontalLayout.insertWidget(1, self.sliderFilter, 1)
self.spinBoxRangeMax.valueChanged.connect(self.maxSpinnerChanged)
self.spinBoxRangeMin.valueChanged.connect(self.minSpinnerChanged)
self.sliderFilter.valueChanged.connect(self.sliderValueChanged)
def setMainRange(self, min:int, max:int):
if min > max: raise ValueError("Value error for setting range Max < Min!!!")
if min == self._min and max == self._max: return
self.mainSeriesMin = min
self.mainSeriesMax = max
self._min = min
self._max = max
self._blockAllSignals(True)
self.spinBoxRangeMin.setRange(min, max)
self.spinBoxRangeMax.setRange(min , max)
self.sliderFilter.setRange(min, max if max > min else min + 1)
self.spinBoxRangeMin.setValue(min)
self.spinBoxRangeMax.setValue(max)
self.sliderFilter.setSliderPosition([min, max])
self._blockAllSignals(False)
self._trimmerChanged()
self.setEnabled(self._max - self._min > 0)
def sliderValueChanged(self, tuple):
min, max = tuple
self._blockAllSignals(True)
if self.spinBoxRangeMin.value() != int(min):
self.spinBoxRangeMin.setValue(int(min))
self.spinBoxRangeMax.setRange(int(min) + 1, self.mainSeriesMax)
if self.spinBoxRangeMax.value() != int(max):
self.spinBoxRangeMax.setValue(int(max))
self.spinBoxRangeMin.setRange(self.mainSeriesMin, int(max))
self._blockAllSignals(False)
self._trimmerChanged()
pass
def minSpinnerChanged(self, value):
self._blockAllSignals(True)
self.sliderFilter.setSliderPosition((value, self._max))
self.spinBoxRangeMax.setRange(value + 1, self.mainSeriesMax)
self._blockAllSignals(False)
self._trimmerChanged()
pass
def maxSpinnerChanged(self, value):
self._blockAllSignals(True)
self.sliderFilter.setSliderPosition((self._min, value))
self.spinBoxRangeMin.setRange(self.mainSeriesMin, value-1)
self._blockAllSignals(False)
self._trimmerChanged()
pass
def _trimmerChanged(self):
if (self.spinBoxRangeMin.value() != int(self._min) or
self.spinBoxRangeMax.value() != int(self._max)):
self._min = self.spinBoxRangeMin.value()
self._max = self.spinBoxRangeMax.value()
self.trimmerChanged.emit((self._min, self._max))
pass
def _blockAllSignals(self, isBlocked: bool):
self.spinBoxRangeMax.blockSignals(isBlocked)
self.spinBoxRangeMin.blockSignals(isBlocked)
self.sliderFilter.blockSignals(isBlocked)