Krita Source Code Documentation
Loading...
Searching...
No Matches
parse_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 IntParseSpinBox and DoubleParseSpinBox.
9
10from krita import IntParseSpinBox, DoubleParseSpinBox
11try:
12 from PyQt6.QtWidgets import QDialog, QFormLayout, QHBoxLayout, QSpinBox, QDoubleSpinBox, QLabel, QCheckBox
13except:
14 from PyQt5.QtWidgets import QDialog, QFormLayout, QHBoxLayout, QSpinBox, QDoubleSpinBox, QLabel, QCheckBox
15
16dialog = QDialog()
17hLayout = QHBoxLayout()
18
19# IntParseSpinBox --
20layout = QFormLayout()
21
22intParseSpinBox = IntParseSpinBox()
23layout.addRow("IntParseSpinBox.widget():", intParseSpinBox.widget())
24
25intValueChangedLabel = QLabel()
26def setIntVal(value):
27 intValueChangedLabel.setText(str(value))
28intParseSpinBox.widget().valueChanged.connect(setIntVal)
29layout.addRow("widget().valueChanged:", intValueChangedLabel)
30
31isValidLabel = QLabel()
32def setValid(_value):
33 isValidLabel.setText(str(intParseSpinBox.isLastValid()))
34intParseSpinBox.widget().valueChanged.connect(setValid)
35layout.addRow("Is Last Valid:", isValidLabel)
36
37statusLabel = QLabel("Valid")
39 statusLabel.setText("Error")
40def setOkay():
41 statusLabel.setText("Valid")
42intParseSpinBox.errorWhileParsing.connect(setError)
43intParseSpinBox.noMoreParsingError.connect(setOkay)
44layout.addRow("Status:", statusLabel)
45
46layout.addWidget(QLabel("Pass values to functions here:"))
47
48stepByBox = QSpinBox()
49stepByBox.valueChanged.connect(intParseSpinBox.stepBy)
50layout.addRow("Step By:", stepByBox)
51
52valueBox = QSpinBox()
53valueBox.setMaximum(100)
54overwriteCheckBox = QCheckBox()
55def setValue(_value):
56 intParseSpinBox.setValue(valueBox.value(), overwriteCheckBox.isChecked())
57valueBox.valueChanged.connect(setValue)
58overwriteCheckBox.clicked.connect(setValue)
59layout.addRow("Value", valueBox)
60layout.addRow(" (overWriteExisting):", overwriteCheckBox)
61testOverwriteCheckBox = QCheckBox()
63 if testOverwriteCheckBox.isChecked():
64 intParseSpinBox.widget().textChanged.connect(setValue)
65 else:
66 intParseSpinBox.widget().textChanged.disconnect(setValue)
67testOverwriteCheckBox.clicked.connect(toggleOverwriteTest)
68layout.addRow(" Test overwrite while typing?", testOverwriteCheckBox)
69
70hLayout.addLayout(layout)
71
72#
73hLayout.addWidget(QLabel()) # add a little spacing
74
75# DoubleParseSpinBox --
76dblLayout = QFormLayout()
77
78doubleParseSpinBox = DoubleParseSpinBox()
79dblLayout.addRow("DoubleParseSpinBox.widget():", doubleParseSpinBox.widget())
80
81dblValueChangedLabel = QLabel()
82def setDoubleVal(value):
83 dblValueChangedLabel.setText(str(value))
84doubleParseSpinBox.widget().valueChanged.connect(setDoubleVal)
85dblLayout.addRow("widget().valueChanged:", dblValueChangedLabel)
86
87dblIsValidLabel = QLabel()
88def dblSetValid(_value):
89 dblIsValidLabel.setText(str(doubleParseSpinBox.isLastValid()))
90doubleParseSpinBox.widget().valueChanged.connect(dblSetValid)
91dblLayout.addRow("Is Last Valid:", dblIsValidLabel)
92
93dblStatusLabel = QLabel("Valid")
95 dblStatusLabel.setText("Error")
97 dblStatusLabel.setText("Valid")
98doubleParseSpinBox.errorWhileParsing.connect(dblSetError)
99doubleParseSpinBox.noMoreParsingError.connect(dblSetOkay)
100dblLayout.addRow("Status:", dblStatusLabel)
101
102dblLayout.addWidget(QLabel("Pass values to functions here:"))
103
104dblStepByBox = QSpinBox()
105dblStepByBox.valueChanged.connect(doubleParseSpinBox.stepBy)
106dblLayout.addRow("Step By:", dblStepByBox)
107
108dblValueBox = QDoubleSpinBox()
109dblOverwriteCheckBox = QCheckBox()
110def dblSetValue(_value):
111 doubleParseSpinBox.setValue(dblValueBox.value(), dblOverwriteCheckBox.isChecked())
112dblValueBox.valueChanged.connect(dblSetValue)
113dblOverwriteCheckBox.clicked.connect(dblSetValue)
114dblLayout.addRow("Value", dblValueBox)
115dblLayout.addRow(" (overwriteExisting):", dblOverwriteCheckBox)
116dblTestOverwriteCheckBox = QCheckBox()
118 if dblTestOverwriteCheckBox.isChecked():
119 doubleParseSpinBox.widget().textChanged.connect(dblSetValue)
120 else:
121 doubleParseSpinBox.widget().textChanged.disconnect(dblSetValue)
122dblTestOverwriteCheckBox.clicked.connect(dblToggleOverwriteTest)
123dblLayout.addRow(" Test overwrite while typing?", dblTestOverwriteCheckBox)
124
125hLayout.addLayout(dblLayout)
126
127#--
128
129dialog.setLayout(hLayout)
130dialog.exec()