File indexing completed on 2024-12-22 04:15:07
0001 # 0002 # SPDX-FileCopyrightText: 2023 Freya Lupen <penguinflyer2222@gmail.com> 0003 # 0004 # SPDX-License-Identifier: GPL-3.0-or-later 0005 # 0006 0007 # This script creates a dialog for manually testing the functions 0008 # of the SliderSpinBox and DoubleSliderSpinBox. 0009 0010 from krita import SliderSpinBox, DoubleSliderSpinBox 0011 from PyQt5.QtWidgets import QDialog, QHBoxLayout, QFormLayout, QLabel, QSpinBox, QDoubleSpinBox, QCheckBox 0012 0013 dialog = QDialog() 0014 hLayout = QHBoxLayout() 0015 0016 # SliderSpinBox -- 0017 layout = QFormLayout() 0018 0019 sliderSpinBox = SliderSpinBox() 0020 layout.addRow("SliderSpinBox.widget():", sliderSpinBox.widget()) 0021 0022 finishedLabel = QLabel("0") 0023 layout.addRow("draggingFinished:", finishedLabel) 0024 def intChanged(): 0025 finishedLabel.setText(str(sliderSpinBox.widget().value())) 0026 sliderSpinBox.draggingFinished.connect(intChanged) 0027 0028 isDraggingLabel = QLabel(str(sliderSpinBox.isDragging())) 0029 def setDraggingLabel(): 0030 isDraggingLabel.setText(str(sliderSpinBox.isDragging())) 0031 sliderSpinBox.widget().valueChanged.connect(setDraggingLabel) 0032 sliderSpinBox.draggingFinished.connect(setDraggingLabel) 0033 layout.addRow("Is Dragging:", isDraggingLabel) 0034 0035 layout.addWidget(QLabel("Pass values to functions here:")) 0036 0037 setIntBox = QSpinBox() 0038 setIntBox.setValue(sliderSpinBox.widget().value()) 0039 setIntBox.valueChanged.connect(sliderSpinBox.setValue) 0040 layout.addRow("Value:", setIntBox) 0041 0042 layout.addRow("Range", QLabel("(min, max, computeNewFastSliderStep):")) 0043 rangeMinBox = QSpinBox() 0044 rangeMinBox.setMaximum(999) 0045 rangeMaxBox = QSpinBox() 0046 rangeMaxBox.setMaximum(999) 0047 rangeRecomputeStepBox = QCheckBox() 0048 def setRange(): 0049 sliderSpinBox.setRange(rangeMinBox.value(), rangeMaxBox.value(), rangeRecomputeStepBox.isChecked()) 0050 rangeMinBox.valueChanged.connect(setRange) 0051 rangeMaxBox.valueChanged.connect(setRange) 0052 rangeRecomputeStepBox.clicked.connect(setRange) 0053 layout.addWidget(rangeMinBox) 0054 layout.addWidget(rangeMaxBox) 0055 layout.addWidget(rangeRecomputeStepBox) 0056 layout.addWidget(QLabel()) # empty line to somewhat align with the double side 0057 0058 layout.addRow("Minimum", QLabel("(computeNewFastSliderStep):")) 0059 minBox = QSpinBox() 0060 minBox.setMaximum(999) 0061 minRecomputeStepBox = QCheckBox() 0062 def setMin(): 0063 sliderSpinBox.setMinimum(minBox.value(), minRecomputeStepBox.isChecked()) 0064 minBox.valueChanged.connect(setMin) 0065 minRecomputeStepBox.clicked.connect(setMin) 0066 layout.addWidget(minBox) 0067 layout.addWidget(minRecomputeStepBox) 0068 0069 layout.addRow("Maximum", QLabel("(computeNewFastSliderStep):")) 0070 maxBox = QSpinBox() 0071 maxBox.setMaximum(999) 0072 maxRecomputeStepBox = QCheckBox() 0073 def setMax(): 0074 sliderSpinBox.setMaximum(maxBox.value(), maxRecomputeStepBox.isChecked()) 0075 maxBox.valueChanged.connect(setMax) 0076 maxRecomputeStepBox.clicked.connect(setMax) 0077 layout.addWidget(maxBox) 0078 layout.addWidget(maxRecomputeStepBox) 0079 0080 exponentRatioBox = QDoubleSpinBox() 0081 exponentRatioBox.setValue(1) # 1 is the default value (there's no getter function) 0082 exponentRatioBox.valueChanged.connect(sliderSpinBox.setExponentRatio) 0083 layout.addRow("Exponent Ratio:", exponentRatioBox) 0084 0085 blockSignalOnDragBox = QCheckBox() 0086 blockSignalOnDragBox.clicked.connect(sliderSpinBox.setBlockUpdateSignalOnDrag) 0087 layout.addRow("Block Update Signal On Drag:", blockSignalOnDragBox) 0088 0089 fastStepBox = QSpinBox() 0090 fastStepBox.setValue(sliderSpinBox.fastSliderStep()) 0091 fastStepBox.valueChanged.connect(sliderSpinBox.setFastSliderStep) 0092 layout.addRow("Fast Slider Step:", fastStepBox) 0093 0094 layout.addRow("Soft Range", QLabel("(min, max):")) 0095 softRangeMinBox = QSpinBox() 0096 softRangeMinBox.setMaximum(999) 0097 softRangeMaxBox = QSpinBox() 0098 softRangeMaxBox.setMaximum(999) 0099 softRangeRecomputeStepBox = QCheckBox() 0100 def setSoftRange(): 0101 sliderSpinBox.setSoftRange(softRangeMinBox.value(), softRangeMaxBox.value()) 0102 softRangeMinBox.valueChanged.connect(setSoftRange) 0103 softRangeMaxBox.valueChanged.connect(setSoftRange) 0104 layout.addWidget(softRangeMinBox) 0105 layout.addWidget(softRangeMaxBox) 0106 0107 softMinBox = QSpinBox() 0108 softMinBox.setMaximum(999) 0109 softMinBox.setValue(sliderSpinBox.softMinimum()) 0110 softMinBox.valueChanged.connect(sliderSpinBox.setSoftMinimum) 0111 layout.addRow("Soft Minimum:", softMinBox) 0112 0113 softMaxBox = QSpinBox() 0114 softMaxBox.setMaximum(999) 0115 softMaxBox.setValue(sliderSpinBox.softMaximum()) 0116 softMaxBox.valueChanged.connect(sliderSpinBox.setSoftMaximum) 0117 layout.addRow("Soft Maximum:", softMaxBox) 0118 0119 hLayout.addLayout(layout) 0120 0121 # 0122 hLayout.addWidget(QLabel()) # add a little spacing 0123 0124 # DoubleSliderSpinBox -- 0125 dblLayout = QFormLayout() 0126 0127 doubleSliderSpinBox = DoubleSliderSpinBox() 0128 dblLayout.addRow("DoubleSliderSpinBox.widget():", doubleSliderSpinBox.widget()) 0129 0130 dblFinishedLabel = QLabel("0.00") 0131 dblLayout.addRow("draggingFinished:", dblFinishedLabel) 0132 def doubleChanged(): 0133 dblFinishedLabel.setText(str(doubleSliderSpinBox.widget().value())) 0134 doubleSliderSpinBox.draggingFinished.connect(doubleChanged) 0135 0136 dblIsDraggingBox = QLabel(str(doubleSliderSpinBox.isDragging())) 0137 def dblSetDraggingLabel(): 0138 dblIsDraggingBox.setText(str(doubleSliderSpinBox.isDragging())) 0139 doubleSliderSpinBox.widget().valueChanged.connect(dblSetDraggingLabel) 0140 doubleSliderSpinBox.draggingFinished.connect(dblSetDraggingLabel) 0141 dblLayout.addRow("Is Dragging:", dblIsDraggingBox) 0142 0143 dblLayout.addWidget(QLabel("Pass values to functions here:")) 0144 0145 setDoubleBox = QDoubleSpinBox() 0146 setDoubleBox.setValue(doubleSliderSpinBox.widget().value()) 0147 setDoubleBox.valueChanged.connect(doubleSliderSpinBox.setValue) 0148 dblLayout.addRow("Value:", setDoubleBox) 0149 0150 dblLayout.addRow("Range", QLabel("(min, max, numDecimals, computeNewFastSliderStep):")) 0151 dblRangeMinBox = QDoubleSpinBox() 0152 dblRangeMinBox.setMaximum(999) 0153 dblRangeMaxBox = QDoubleSpinBox() 0154 dblRangeMaxBox.setMaximum(999) 0155 dblNumDecimalsBox = QSpinBox() 0156 dblRangeRecomputeStepBox = QCheckBox() 0157 def dblSetRange(): 0158 doubleSliderSpinBox.setRange(dblRangeMinBox.value(), dblRangeMaxBox.value(), 0159 dblNumDecimalsBox.value(), dblRangeRecomputeStepBox.isChecked()) 0160 dblRangeMinBox.valueChanged.connect(dblSetRange) 0161 dblRangeMaxBox.valueChanged.connect(dblSetRange) 0162 dblNumDecimalsBox.valueChanged.connect(dblSetRange) 0163 dblRangeRecomputeStepBox.clicked.connect(dblSetRange) 0164 dblLayout.addWidget(dblRangeMinBox) 0165 dblLayout.addWidget(dblRangeMaxBox) 0166 dblLayout.addWidget(dblNumDecimalsBox) 0167 dblLayout.addWidget(dblRangeRecomputeStepBox) 0168 0169 dblLayout.addRow("Minimum", QLabel("(computeNewFastSliderStep):")) 0170 dblMinBox = QDoubleSpinBox() 0171 dblMinBox.setMaximum(999) 0172 dblMinRecomputeStepBox = QCheckBox() 0173 def dblSetMin(): 0174 doubleSliderSpinBox.setMinimum(dblMinBox.value(), dblMinRecomputeStepBox.isChecked()) 0175 dblMinBox.valueChanged.connect(dblSetMin) 0176 dblMinRecomputeStepBox.clicked.connect(dblSetMin) 0177 dblLayout.addWidget(dblMinBox) 0178 dblLayout.addWidget(dblMinRecomputeStepBox) 0179 0180 dblLayout.addRow("Maximum", QLabel("(computeNewFastSliderStep):")) 0181 dblMaxBox = QDoubleSpinBox() 0182 dblMaxBox.setMaximum(999) 0183 dblMaxRecomputeStepBox = QCheckBox() 0184 def dblSetMax(): 0185 doubleSliderSpinBox.setMaximum(dblMaxBox.value(), dblMaxRecomputeStepBox.isChecked()) 0186 dblMaxBox.valueChanged.connect(dblSetMax) 0187 dblMaxRecomputeStepBox.clicked.connect(dblSetMax) 0188 dblLayout.addWidget(dblMaxBox) 0189 dblLayout.addWidget(dblMaxRecomputeStepBox) 0190 0191 dblExponentRatioBox = QDoubleSpinBox() 0192 dblExponentRatioBox.setValue(1) # 1 is the default value (there's no getter function) 0193 dblExponentRatioBox.valueChanged.connect(doubleSliderSpinBox.setExponentRatio) 0194 dblLayout.addRow("Exponent Ratio:", dblExponentRatioBox) 0195 0196 dblBlockSignalOnDragBox = QCheckBox() 0197 dblBlockSignalOnDragBox.clicked.connect(doubleSliderSpinBox.setBlockUpdateSignalOnDrag) 0198 dblLayout.addRow("Block Update Signal On Drag:", dblBlockSignalOnDragBox) 0199 0200 dblFastStepBox = QDoubleSpinBox() 0201 dblFastStepBox.setValue(doubleSliderSpinBox.fastSliderStep()) 0202 dblFastStepBox.valueChanged.connect(doubleSliderSpinBox.setFastSliderStep) 0203 dblLayout.addRow("Fast Slider Step:", dblFastStepBox) 0204 0205 dblLayout.addRow("Soft Range", QLabel("(min, max):")) 0206 dblSoftRangeMinBox = QDoubleSpinBox() 0207 dblSoftRangeMinBox.setMaximum(999) 0208 dblSoftRangeMaxBox = QDoubleSpinBox() 0209 dblSoftRangeMaxBox.setMaximum(999) 0210 def dblSetSoftRange(): 0211 doubleSliderSpinBox.setSoftRange(dblSoftRangeMinBox.value(), dblSoftRangeMaxBox.value()) 0212 dblSoftRangeMinBox.valueChanged.connect(dblSetSoftRange) 0213 dblSoftRangeMaxBox.valueChanged.connect(dblSetSoftRange) 0214 dblLayout.addWidget(dblSoftRangeMinBox) 0215 dblLayout.addWidget(dblSoftRangeMaxBox) 0216 0217 dblSoftMinBox = QDoubleSpinBox() 0218 dblSoftMinBox.setMaximum(999) 0219 dblSoftMinBox.setValue(doubleSliderSpinBox.softMinimum()) 0220 dblSoftMinBox.valueChanged.connect(doubleSliderSpinBox.setSoftMinimum) 0221 dblLayout.addRow("Soft Minimum:", dblSoftMinBox) 0222 0223 dblSoftMaxBox = QDoubleSpinBox() 0224 dblSoftMaxBox.setMaximum(999) 0225 dblSoftMaxBox.setValue(doubleSliderSpinBox.softMaximum()) 0226 dblSoftMaxBox.valueChanged.connect(doubleSliderSpinBox.setSoftMaximum) 0227 dblLayout.addRow("Soft Maximum:", dblSoftMaxBox) 0228 0229 hLayout.addLayout(dblLayout) 0230 0231 # -- 0232 0233 dialog.setLayout(hLayout) 0234 dialog.exec()