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 IntParseSpinBox and DoubleParseSpinBox. 0009 0010 from krita import IntParseSpinBox, DoubleParseSpinBox 0011 from PyQt5.QtWidgets import QDialog, QFormLayout, QHBoxLayout, QSpinBox, QDoubleSpinBox, QLabel, QCheckBox 0012 0013 dialog = QDialog() 0014 hLayout = QHBoxLayout() 0015 0016 # IntParseSpinBox -- 0017 layout = QFormLayout() 0018 0019 intParseSpinBox = IntParseSpinBox() 0020 layout.addRow("IntParseSpinBox.widget():", intParseSpinBox.widget()) 0021 0022 intValueChangedLabel = QLabel() 0023 def setIntVal(value): 0024 intValueChangedLabel.setText(str(value)) 0025 intParseSpinBox.widget().valueChanged.connect(setIntVal) 0026 layout.addRow("widget().valueChanged:", intValueChangedLabel) 0027 0028 isValidLabel = QLabel() 0029 def setValid(_value): 0030 isValidLabel.setText(str(intParseSpinBox.isLastValid())) 0031 intParseSpinBox.widget().valueChanged.connect(setValid) 0032 layout.addRow("Is Last Valid:", isValidLabel) 0033 0034 statusLabel = QLabel("Valid") 0035 def setError(): 0036 statusLabel.setText("Error") 0037 def setOkay(): 0038 statusLabel.setText("Valid") 0039 intParseSpinBox.errorWhileParsing.connect(setError) 0040 intParseSpinBox.noMoreParsingError.connect(setOkay) 0041 layout.addRow("Status:", statusLabel) 0042 0043 layout.addWidget(QLabel("Pass values to functions here:")) 0044 0045 stepByBox = QSpinBox() 0046 stepByBox.valueChanged.connect(intParseSpinBox.stepBy) 0047 layout.addRow("Step By:", stepByBox) 0048 0049 valueBox = QSpinBox() 0050 valueBox.setMaximum(100) 0051 overwriteCheckBox = QCheckBox() 0052 def setValue(_value): 0053 intParseSpinBox.setValue(valueBox.value(), overwriteCheckBox.isChecked()) 0054 valueBox.valueChanged.connect(setValue) 0055 overwriteCheckBox.clicked.connect(setValue) 0056 layout.addRow("Value", valueBox) 0057 layout.addRow(" (overWriteExisting):", overwriteCheckBox) 0058 testOverwriteCheckBox = QCheckBox() 0059 def toggleOverwriteTest(): 0060 if testOverwriteCheckBox.isChecked(): 0061 intParseSpinBox.widget().textChanged.connect(setValue) 0062 else: 0063 intParseSpinBox.widget().textChanged.disconnect(setValue) 0064 testOverwriteCheckBox.clicked.connect(toggleOverwriteTest) 0065 layout.addRow(" Test overwrite while typing?", testOverwriteCheckBox) 0066 0067 hLayout.addLayout(layout) 0068 0069 # 0070 hLayout.addWidget(QLabel()) # add a little spacing 0071 0072 # DoubleParseSpinBox -- 0073 dblLayout = QFormLayout() 0074 0075 doubleParseSpinBox = DoubleParseSpinBox() 0076 dblLayout.addRow("DoubleParseSpinBox.widget():", doubleParseSpinBox.widget()) 0077 0078 dblValueChangedLabel = QLabel() 0079 def setDoubleVal(value): 0080 dblValueChangedLabel.setText(str(value)) 0081 doubleParseSpinBox.widget().valueChanged.connect(setDoubleVal) 0082 dblLayout.addRow("widget().valueChanged:", dblValueChangedLabel) 0083 0084 dblIsValidLabel = QLabel() 0085 def dblSetValid(_value): 0086 dblIsValidLabel.setText(str(doubleParseSpinBox.isLastValid())) 0087 doubleParseSpinBox.widget().valueChanged.connect(dblSetValid) 0088 dblLayout.addRow("Is Last Valid:", dblIsValidLabel) 0089 0090 dblStatusLabel = QLabel("Valid") 0091 def dblSetError(): 0092 dblStatusLabel.setText("Error") 0093 def dblSetOkay(): 0094 dblStatusLabel.setText("Valid") 0095 doubleParseSpinBox.errorWhileParsing.connect(dblSetError) 0096 doubleParseSpinBox.noMoreParsingError.connect(dblSetOkay) 0097 dblLayout.addRow("Status:", dblStatusLabel) 0098 0099 dblLayout.addWidget(QLabel("Pass values to functions here:")) 0100 0101 dblStepByBox = QSpinBox() 0102 dblStepByBox.valueChanged.connect(doubleParseSpinBox.stepBy) 0103 dblLayout.addRow("Step By:", dblStepByBox) 0104 0105 dblValueBox = QDoubleSpinBox() 0106 dblOverwriteCheckBox = QCheckBox() 0107 def dblSetValue(_value): 0108 doubleParseSpinBox.setValue(dblValueBox.value(), dblOverwriteCheckBox.isChecked()) 0109 dblValueBox.valueChanged.connect(dblSetValue) 0110 dblOverwriteCheckBox.clicked.connect(dblSetValue) 0111 dblLayout.addRow("Value", dblValueBox) 0112 dblLayout.addRow(" (overwriteExisting):", dblOverwriteCheckBox) 0113 dblTestOverwriteCheckBox = QCheckBox() 0114 def dblToggleOverwriteTest(): 0115 if dblTestOverwriteCheckBox.isChecked(): 0116 doubleParseSpinBox.widget().textChanged.connect(dblSetValue) 0117 else: 0118 doubleParseSpinBox.widget().textChanged.disconnect(dblSetValue) 0119 dblTestOverwriteCheckBox.clicked.connect(dblToggleOverwriteTest) 0120 dblLayout.addRow(" Test overwrite while typing?", dblTestOverwriteCheckBox) 0121 0122 hLayout.addLayout(dblLayout) 0123 0124 #-- 0125 0126 dialog.setLayout(hLayout) 0127 dialog.exec()