Krita Source Code Documentation
Loading...
Searching...
No Matches
slider_spinbox_test_script.py
Go to the documentation of this file.
2# SPDX-FileCopyrightText: 2023 Freya Lupen <penguinflyer2222@gmail.com>
3#
4# SPDX-License-Identifier: GPL-3.0-or-later
5#
6
7# This script creates a dialog for manually testing the functions
8# of the SliderSpinBox and DoubleSliderSpinBox.
9
10from krita import SliderSpinBox, DoubleSliderSpinBox
11try:
12 from PyQt6.QtWidgets import QDialog, QHBoxLayout, QFormLayout, QLabel, QSpinBox, QDoubleSpinBox, QCheckBox
13except:
14 from PyQt5.QtWidgets import QDialog, QHBoxLayout, QFormLayout, QLabel, QSpinBox, QDoubleSpinBox, QCheckBox
15
16dialog = QDialog()
17hLayout = QHBoxLayout()
18
19# SliderSpinBox --
20layout = QFormLayout()
21
22sliderSpinBox = SliderSpinBox()
23layout.addRow("SliderSpinBox.widget():", sliderSpinBox.widget())
24
25finishedLabel = QLabel("0")
26layout.addRow("draggingFinished:", finishedLabel)
28 finishedLabel.setText(str(sliderSpinBox.widget().value()))
29sliderSpinBox.draggingFinished.connect(intChanged)
30
31isDraggingLabel = QLabel(str(sliderSpinBox.isDragging()))
33 isDraggingLabel.setText(str(sliderSpinBox.isDragging()))
34sliderSpinBox.widget().valueChanged.connect(setDraggingLabel)
35sliderSpinBox.draggingFinished.connect(setDraggingLabel)
36layout.addRow("Is Dragging:", isDraggingLabel)
37
38layout.addWidget(QLabel("Pass values to functions here:"))
39
40setIntBox = QSpinBox()
41setIntBox.setValue(sliderSpinBox.widget().value())
42setIntBox.valueChanged.connect(sliderSpinBox.setValue)
43layout.addRow("Value:", setIntBox)
44
45layout.addRow("Range", QLabel("(min, max, computeNewFastSliderStep):"))
46rangeMinBox = QSpinBox()
47rangeMinBox.setMaximum(999)
48rangeMaxBox = QSpinBox()
49rangeMaxBox.setMaximum(999)
50rangeRecomputeStepBox = QCheckBox()
52 sliderSpinBox.setRange(rangeMinBox.value(), rangeMaxBox.value(), rangeRecomputeStepBox.isChecked())
53rangeMinBox.valueChanged.connect(setRange)
54rangeMaxBox.valueChanged.connect(setRange)
55rangeRecomputeStepBox.clicked.connect(setRange)
56layout.addWidget(rangeMinBox)
57layout.addWidget(rangeMaxBox)
58layout.addWidget(rangeRecomputeStepBox)
59layout.addWidget(QLabel()) # empty line to somewhat align with the double side
60
61layout.addRow("Minimum", QLabel("(computeNewFastSliderStep):"))
62minBox = QSpinBox()
63minBox.setMaximum(999)
64minRecomputeStepBox = QCheckBox()
65def setMin():
66 sliderSpinBox.setMinimum(minBox.value(), minRecomputeStepBox.isChecked())
67minBox.valueChanged.connect(setMin)
68minRecomputeStepBox.clicked.connect(setMin)
69layout.addWidget(minBox)
70layout.addWidget(minRecomputeStepBox)
71
72layout.addRow("Maximum", QLabel("(computeNewFastSliderStep):"))
73maxBox = QSpinBox()
74maxBox.setMaximum(999)
75maxRecomputeStepBox = QCheckBox()
76def setMax():
77 sliderSpinBox.setMaximum(maxBox.value(), maxRecomputeStepBox.isChecked())
78maxBox.valueChanged.connect(setMax)
79maxRecomputeStepBox.clicked.connect(setMax)
80layout.addWidget(maxBox)
81layout.addWidget(maxRecomputeStepBox)
82
83exponentRatioBox = QDoubleSpinBox()
84exponentRatioBox.setValue(1) # 1 is the default value (there's no getter function)
85exponentRatioBox.valueChanged.connect(sliderSpinBox.setExponentRatio)
86layout.addRow("Exponent Ratio:", exponentRatioBox)
87
88blockSignalOnDragBox = QCheckBox()
89blockSignalOnDragBox.clicked.connect(sliderSpinBox.setBlockUpdateSignalOnDrag)
90layout.addRow("Block Update Signal On Drag:", blockSignalOnDragBox)
91
92fastStepBox = QSpinBox()
93fastStepBox.setValue(sliderSpinBox.fastSliderStep())
94fastStepBox.valueChanged.connect(sliderSpinBox.setFastSliderStep)
95layout.addRow("Fast Slider Step:", fastStepBox)
96
97layout.addRow("Soft Range", QLabel("(min, max):"))
98softRangeMinBox = QSpinBox()
99softRangeMinBox.setMaximum(999)
100softRangeMaxBox = QSpinBox()
101softRangeMaxBox.setMaximum(999)
102softRangeRecomputeStepBox = QCheckBox()
104 sliderSpinBox.setSoftRange(softRangeMinBox.value(), softRangeMaxBox.value())
105softRangeMinBox.valueChanged.connect(setSoftRange)
106softRangeMaxBox.valueChanged.connect(setSoftRange)
107layout.addWidget(softRangeMinBox)
108layout.addWidget(softRangeMaxBox)
109
110softMinBox = QSpinBox()
111softMinBox.setMaximum(999)
112softMinBox.setValue(sliderSpinBox.softMinimum())
113softMinBox.valueChanged.connect(sliderSpinBox.setSoftMinimum)
114layout.addRow("Soft Minimum:", softMinBox)
115
116softMaxBox = QSpinBox()
117softMaxBox.setMaximum(999)
118softMaxBox.setValue(sliderSpinBox.softMaximum())
119softMaxBox.valueChanged.connect(sliderSpinBox.setSoftMaximum)
120layout.addRow("Soft Maximum:", softMaxBox)
121
122hLayout.addLayout(layout)
123
124#
125hLayout.addWidget(QLabel()) # add a little spacing
126
127# DoubleSliderSpinBox --
128dblLayout = QFormLayout()
129
130doubleSliderSpinBox = DoubleSliderSpinBox()
131dblLayout.addRow("DoubleSliderSpinBox.widget():", doubleSliderSpinBox.widget())
132
133dblFinishedLabel = QLabel("0.00")
134dblLayout.addRow("draggingFinished:", dblFinishedLabel)
136 dblFinishedLabel.setText(str(doubleSliderSpinBox.widget().value()))
137doubleSliderSpinBox.draggingFinished.connect(doubleChanged)
138
139dblIsDraggingBox = QLabel(str(doubleSliderSpinBox.isDragging()))
141 dblIsDraggingBox.setText(str(doubleSliderSpinBox.isDragging()))
142doubleSliderSpinBox.widget().valueChanged.connect(dblSetDraggingLabel)
143doubleSliderSpinBox.draggingFinished.connect(dblSetDraggingLabel)
144dblLayout.addRow("Is Dragging:", dblIsDraggingBox)
145
146dblLayout.addWidget(QLabel("Pass values to functions here:"))
147
148setDoubleBox = QDoubleSpinBox()
149setDoubleBox.setValue(doubleSliderSpinBox.widget().value())
150setDoubleBox.valueChanged.connect(doubleSliderSpinBox.setValue)
151dblLayout.addRow("Value:", setDoubleBox)
152
153dblLayout.addRow("Range", QLabel("(min, max, numDecimals, computeNewFastSliderStep):"))
154dblRangeMinBox = QDoubleSpinBox()
155dblRangeMinBox.setMaximum(999)
156dblRangeMaxBox = QDoubleSpinBox()
157dblRangeMaxBox.setMaximum(999)
158dblNumDecimalsBox = QSpinBox()
159dblRangeRecomputeStepBox = QCheckBox()
161 doubleSliderSpinBox.setRange(dblRangeMinBox.value(), dblRangeMaxBox.value(),
162 dblNumDecimalsBox.value(), dblRangeRecomputeStepBox.isChecked())
163dblRangeMinBox.valueChanged.connect(dblSetRange)
164dblRangeMaxBox.valueChanged.connect(dblSetRange)
165dblNumDecimalsBox.valueChanged.connect(dblSetRange)
166dblRangeRecomputeStepBox.clicked.connect(dblSetRange)
167dblLayout.addWidget(dblRangeMinBox)
168dblLayout.addWidget(dblRangeMaxBox)
169dblLayout.addWidget(dblNumDecimalsBox)
170dblLayout.addWidget(dblRangeRecomputeStepBox)
171
172dblLayout.addRow("Minimum", QLabel("(computeNewFastSliderStep):"))
173dblMinBox = QDoubleSpinBox()
174dblMinBox.setMaximum(999)
175dblMinRecomputeStepBox = QCheckBox()
177 doubleSliderSpinBox.setMinimum(dblMinBox.value(), dblMinRecomputeStepBox.isChecked())
178dblMinBox.valueChanged.connect(dblSetMin)
179dblMinRecomputeStepBox.clicked.connect(dblSetMin)
180dblLayout.addWidget(dblMinBox)
181dblLayout.addWidget(dblMinRecomputeStepBox)
182
183dblLayout.addRow("Maximum", QLabel("(computeNewFastSliderStep):"))
184dblMaxBox = QDoubleSpinBox()
185dblMaxBox.setMaximum(999)
186dblMaxRecomputeStepBox = QCheckBox()
188 doubleSliderSpinBox.setMaximum(dblMaxBox.value(), dblMaxRecomputeStepBox.isChecked())
189dblMaxBox.valueChanged.connect(dblSetMax)
190dblMaxRecomputeStepBox.clicked.connect(dblSetMax)
191dblLayout.addWidget(dblMaxBox)
192dblLayout.addWidget(dblMaxRecomputeStepBox)
193
194dblExponentRatioBox = QDoubleSpinBox()
195dblExponentRatioBox.setValue(1) # 1 is the default value (there's no getter function)
196dblExponentRatioBox.valueChanged.connect(doubleSliderSpinBox.setExponentRatio)
197dblLayout.addRow("Exponent Ratio:", dblExponentRatioBox)
198
199dblBlockSignalOnDragBox = QCheckBox()
200dblBlockSignalOnDragBox.clicked.connect(doubleSliderSpinBox.setBlockUpdateSignalOnDrag)
201dblLayout.addRow("Block Update Signal On Drag:", dblBlockSignalOnDragBox)
202
203dblFastStepBox = QDoubleSpinBox()
204dblFastStepBox.setValue(doubleSliderSpinBox.fastSliderStep())
205dblFastStepBox.valueChanged.connect(doubleSliderSpinBox.setFastSliderStep)
206dblLayout.addRow("Fast Slider Step:", dblFastStepBox)
207
208dblLayout.addRow("Soft Range", QLabel("(min, max):"))
209dblSoftRangeMinBox = QDoubleSpinBox()
210dblSoftRangeMinBox.setMaximum(999)
211dblSoftRangeMaxBox = QDoubleSpinBox()
212dblSoftRangeMaxBox.setMaximum(999)
214 doubleSliderSpinBox.setSoftRange(dblSoftRangeMinBox.value(), dblSoftRangeMaxBox.value())
215dblSoftRangeMinBox.valueChanged.connect(dblSetSoftRange)
216dblSoftRangeMaxBox.valueChanged.connect(dblSetSoftRange)
217dblLayout.addWidget(dblSoftRangeMinBox)
218dblLayout.addWidget(dblSoftRangeMaxBox)
219
220dblSoftMinBox = QDoubleSpinBox()
221dblSoftMinBox.setMaximum(999)
222dblSoftMinBox.setValue(doubleSliderSpinBox.softMinimum())
223dblSoftMinBox.valueChanged.connect(doubleSliderSpinBox.setSoftMinimum)
224dblLayout.addRow("Soft Minimum:", dblSoftMinBox)
225
226dblSoftMaxBox = QDoubleSpinBox()
227dblSoftMaxBox.setMaximum(999)
228dblSoftMaxBox.setValue(doubleSliderSpinBox.softMaximum())
229dblSoftMaxBox.valueChanged.connect(doubleSliderSpinBox.setSoftMaximum)
230dblLayout.addRow("Soft Maximum:", dblSoftMaxBox)
231
232hLayout.addLayout(dblLayout)
233
234# --
235
236dialog.setLayout(hLayout)
237dialog.exec()
float value(const T *src, size_t ch)