Skip to content

wizard

BooleanWizard #

Bases: QObject

BooleanWizard class.

Build a widget to input a boolean.

Source code in cogip/widgets/wizard.py
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
class BooleanWizard(QtCore.QObject):
    """
    BooleanWizard class.

    Build a widget to input a boolean.
    """

    response: qtSignal = qtSignal(bool)

    def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
        """
        Class constructor.

        Arguments:
            wizard: wizard request
            parent: the parent widget
        """
        super().__init__()
        self.wizard = wizard

        layout = QtWidgets.QVBoxLayout()
        layout.setAlignment(QtCore.Qt.AlignHCenter)
        parent.setLayout(layout)

        self.input = QtWidgets.QCheckBox()
        self.input.setChecked(self.wizard.get("value", False))
        layout.addWidget(self.input)

        send_button = QtWidgets.QPushButton("Send")
        layout.addWidget(send_button)
        send_button.clicked.connect(self.send)

    @qtSlot()
    def send(self, clicked: bool):
        """
        Send chosen value to parent dialog on Send button click.
        """
        self.response.emit(self.input.isChecked())

__init__(wizard, parent) #

Class constructor.

Parameters:

Name Type Description Default
wizard dict[str, Any]

wizard request

required
parent QWidget

the parent widget

required
Source code in cogip/widgets/wizard.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
    """
    Class constructor.

    Arguments:
        wizard: wizard request
        parent: the parent widget
    """
    super().__init__()
    self.wizard = wizard

    layout = QtWidgets.QVBoxLayout()
    layout.setAlignment(QtCore.Qt.AlignHCenter)
    parent.setLayout(layout)

    self.input = QtWidgets.QCheckBox()
    self.input.setChecked(self.wizard.get("value", False))
    layout.addWidget(self.input)

    send_button = QtWidgets.QPushButton("Send")
    layout.addWidget(send_button)
    send_button.clicked.connect(self.send)

send(clicked) #

Send chosen value to parent dialog on Send button click.

Source code in cogip/widgets/wizard.py
42
43
44
45
46
47
@qtSlot()
def send(self, clicked: bool):
    """
    Send chosen value to parent dialog on Send button click.
    """
    self.response.emit(self.input.isChecked())

CampWizard #

Bases: QObject

CampWizard class.

Build a widget to select a string.

Source code in cogip/widgets/wizard.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
class CampWizard(QtCore.QObject):
    """
    CampWizard class.

    Build a widget to select a string.
    """

    response: qtSignal = qtSignal(str)

    def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
        """
        Class constructor.

        Arguments:
            wizard: wizard request
            parent: the parent widget
        """
        super().__init__()
        self.wizard = wizard

        layout = QtWidgets.QVBoxLayout()
        parent.setLayout(layout)

        button_layout = QtWidgets.QHBoxLayout()
        layout.addLayout(button_layout)

        self.buttons = QtWidgets.QButtonGroup()

        self.button_blue = QtWidgets.QRadioButton()
        self.button_blue.setObjectName("blueCamp")
        self.button_blue.setCheckable(True)
        self.button_blue.setStyleSheet(
            """
            QRadioButton#blueCamp {
                border-color: #005CE6;
                background-color: #005CE6;
                border-width: 2px;
                border-radius: 10px;
                border-style: inset;
                min-width: 6em;
                padding: 6px;
            }
            QRadioButton#blueCamp:checked {
                border-color: beige;
                border-style: outset;
            }
            QRadioButton#blueCamp::indicator {
                border-width: 0;
            }
            """
        )
        self.buttons.addButton(self.button_blue)
        button_layout.addWidget(self.button_blue)

        self.button_yellow = QtWidgets.QRadioButton()
        self.button_yellow.setObjectName("yellowCamp")
        self.button_yellow.setCheckable(True)
        self.button_yellow.setStyleSheet(
            """
            QRadioButton#yellowCamp {
                border-color: #FFBF00;
                background-color: #FFBF00;
                border-width: 2px;
                border-radius: 10px;
                border-style: inset;
                min-width: 6em;
                padding: 6px;
            }
            QRadioButton#yellowCamp:checked {
                border-color: beige;
                border-style: outset;
            }
            QRadioButton#yellowCamp::indicator {
                border-width: 0;
            }
            """
        )
        self.buttons.addButton(self.button_yellow)
        button_layout.addWidget(self.button_yellow)

        if wizard["value"] == "blue":
            self.button_blue.setChecked(True)
        else:
            self.button_yellow.setChecked(True)
        send_button = QtWidgets.QPushButton("Send")
        layout.addWidget(send_button)
        send_button.clicked.connect(self.send)

    @qtSlot()
    def send(self, clicked: bool):
        color = "blue" if self.button_blue.isChecked() else "yellow"
        self.response.emit(color)

__init__(wizard, parent) #

Class constructor.

Parameters:

Name Type Description Default
wizard dict[str, Any]

wizard request

required
parent QWidget

the parent widget

required
Source code in cogip/widgets/wizard.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
    """
    Class constructor.

    Arguments:
        wizard: wizard request
        parent: the parent widget
    """
    super().__init__()
    self.wizard = wizard

    layout = QtWidgets.QVBoxLayout()
    parent.setLayout(layout)

    button_layout = QtWidgets.QHBoxLayout()
    layout.addLayout(button_layout)

    self.buttons = QtWidgets.QButtonGroup()

    self.button_blue = QtWidgets.QRadioButton()
    self.button_blue.setObjectName("blueCamp")
    self.button_blue.setCheckable(True)
    self.button_blue.setStyleSheet(
        """
        QRadioButton#blueCamp {
            border-color: #005CE6;
            background-color: #005CE6;
            border-width: 2px;
            border-radius: 10px;
            border-style: inset;
            min-width: 6em;
            padding: 6px;
        }
        QRadioButton#blueCamp:checked {
            border-color: beige;
            border-style: outset;
        }
        QRadioButton#blueCamp::indicator {
            border-width: 0;
        }
        """
    )
    self.buttons.addButton(self.button_blue)
    button_layout.addWidget(self.button_blue)

    self.button_yellow = QtWidgets.QRadioButton()
    self.button_yellow.setObjectName("yellowCamp")
    self.button_yellow.setCheckable(True)
    self.button_yellow.setStyleSheet(
        """
        QRadioButton#yellowCamp {
            border-color: #FFBF00;
            background-color: #FFBF00;
            border-width: 2px;
            border-radius: 10px;
            border-style: inset;
            min-width: 6em;
            padding: 6px;
        }
        QRadioButton#yellowCamp:checked {
            border-color: beige;
            border-style: outset;
        }
        QRadioButton#yellowCamp::indicator {
            border-width: 0;
        }
        """
    )
    self.buttons.addButton(self.button_yellow)
    button_layout.addWidget(self.button_yellow)

    if wizard["value"] == "blue":
        self.button_blue.setChecked(True)
    else:
        self.button_yellow.setChecked(True)
    send_button = QtWidgets.QPushButton("Send")
    layout.addWidget(send_button)
    send_button.clicked.connect(self.send)

ChoiceWizard #

Bases: QObject

ChoiceWizard class.

Build a widget to choose a integer, float or string from a list.

Source code in cogip/widgets/wizard.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
class ChoiceWizard(QtCore.QObject):
    """
    ChoiceWizard class.

    Build a widget to choose a integer, float or string from a list.
    """

    response: qtSignal = qtSignal(str)

    def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
        """
        Class constructor.

        Arguments:
            wizard: wizard request
            parent: the parent widget
        """
        super().__init__()
        self.wizard = wizard

        layout = QtWidgets.QVBoxLayout()
        parent.setLayout(layout)

        self.buttons = QtWidgets.QButtonGroup(layout)
        for v in wizard["choices"]:
            button = QtWidgets.QRadioButton(str(v))
            self.buttons.addButton(button)
            button.setChecked(v == wizard["value"])
            layout.addWidget(button)
        send_button = QtWidgets.QPushButton("Send")
        layout.addWidget(send_button)
        send_button.clicked.connect(self.send)

    @qtSlot()
    def send(self, clicked: bool):
        """
        Send chosen value to parent dialog on Send button click.
        """
        self.response.emit(self.buttons.checkedButton().text())

__init__(wizard, parent) #

Class constructor.

Parameters:

Name Type Description Default
wizard dict[str, Any]

wizard request

required
parent QWidget

the parent widget

required
Source code in cogip/widgets/wizard.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
    """
    Class constructor.

    Arguments:
        wizard: wizard request
        parent: the parent widget
    """
    super().__init__()
    self.wizard = wizard

    layout = QtWidgets.QVBoxLayout()
    parent.setLayout(layout)

    self.buttons = QtWidgets.QButtonGroup(layout)
    for v in wizard["choices"]:
        button = QtWidgets.QRadioButton(str(v))
        self.buttons.addButton(button)
        button.setChecked(v == wizard["value"])
        layout.addWidget(button)
    send_button = QtWidgets.QPushButton("Send")
    layout.addWidget(send_button)
    send_button.clicked.connect(self.send)

send(clicked) #

Send chosen value to parent dialog on Send button click.

Source code in cogip/widgets/wizard.py
169
170
171
172
173
174
@qtSlot()
def send(self, clicked: bool):
    """
    Send chosen value to parent dialog on Send button click.
    """
    self.response.emit(self.buttons.checkedButton().text())

InputWizard #

Bases: QObject

InputWizard class.

Build a widget to input an integer, float or string.

Source code in cogip/widgets/wizard.py
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
class InputWizard(QtCore.QObject):
    """
    InputWizard class.

    Build a widget to input an integer, float or string.
    """

    response: qtSignal = qtSignal(str)

    def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
        """
        Class constructor.

        Arguments:
            wizard: wizard request
            parent: the parent widget
        """
        super().__init__()
        self.wizard = wizard

        layout = QtWidgets.QVBoxLayout()
        parent.setLayout(layout)

        match self.wizard["type"]:
            case "integer":
                self.input = QtWidgets.QSpinBox()
                self.input.setValue(int(self.wizard.get("value", 0)))
            case "floating":
                self.input = QtWidgets.QDoubleSpinBox()
                self.input.setValue(float(self.wizard.get("value", 0.0)))
            case "str":
                self.input = QtWidgets.QLineEdit()
                self.input.setText(self.wizard.get("value", ""))
        layout.addWidget(self.input)
        send_button = QtWidgets.QPushButton("Send")
        layout.addWidget(send_button)
        send_button.clicked.connect(self.send)

    @qtSlot()
    def send(self, clicked: bool):
        """
        Send chosen value to parent dialog on Send button click.
        """
        self.response.emit(self.input.text())

__init__(wizard, parent) #

Class constructor.

Parameters:

Name Type Description Default
wizard dict[str, Any]

wizard request

required
parent QWidget

the parent widget

required
Source code in cogip/widgets/wizard.py
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
def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
    """
    Class constructor.

    Arguments:
        wizard: wizard request
        parent: the parent widget
    """
    super().__init__()
    self.wizard = wizard

    layout = QtWidgets.QVBoxLayout()
    parent.setLayout(layout)

    match self.wizard["type"]:
        case "integer":
            self.input = QtWidgets.QSpinBox()
            self.input.setValue(int(self.wizard.get("value", 0)))
        case "floating":
            self.input = QtWidgets.QDoubleSpinBox()
            self.input.setValue(float(self.wizard.get("value", 0.0)))
        case "str":
            self.input = QtWidgets.QLineEdit()
            self.input.setText(self.wizard.get("value", ""))
    layout.addWidget(self.input)
    send_button = QtWidgets.QPushButton("Send")
    layout.addWidget(send_button)
    send_button.clicked.connect(self.send)

send(clicked) #

Send chosen value to parent dialog on Send button click.

Source code in cogip/widgets/wizard.py
88
89
90
91
92
93
@qtSlot()
def send(self, clicked: bool):
    """
    Send chosen value to parent dialog on Send button click.
    """
    self.response.emit(self.input.text())

MessageWizard #

Bases: QObject

MessageWizard class.

Build a widget to display a message.

Source code in cogip/widgets/wizard.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class MessageWizard(QtCore.QObject):
    """
    MessageWizard class.

    Build a widget to display a message.
    """

    response: qtSignal = qtSignal(str)

    def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
        """
        Class constructor.

        Arguments:
            wizard: wizard request
            parent: the parent widget
        """
        super().__init__()
        self.wizard = wizard

        layout = QtWidgets.QVBoxLayout()
        layout.setAlignment(QtCore.Qt.AlignHCenter)
        parent.setLayout(layout)

        self.input = QtWidgets.QLabel()
        self.input.setText(self.wizard.get("value", False))
        layout.addWidget(self.input)

        send_button = QtWidgets.QPushButton("Ok")
        layout.addWidget(send_button)
        send_button.clicked.connect(self.send)

    @qtSlot()
    def send(self, clicked: bool):
        """
        Send chosen value to parent dialog on Send button click.
        """
        self.response.emit("")

__init__(wizard, parent) #

Class constructor.

Parameters:

Name Type Description Default
wizard dict[str, Any]

wizard request

required
parent QWidget

the parent widget

required
Source code in cogip/widgets/wizard.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
    """
    Class constructor.

    Arguments:
        wizard: wizard request
        parent: the parent widget
    """
    super().__init__()
    self.wizard = wizard

    layout = QtWidgets.QVBoxLayout()
    layout.setAlignment(QtCore.Qt.AlignHCenter)
    parent.setLayout(layout)

    self.input = QtWidgets.QLabel()
    self.input.setText(self.wizard.get("value", False))
    layout.addWidget(self.input)

    send_button = QtWidgets.QPushButton("Ok")
    layout.addWidget(send_button)
    send_button.clicked.connect(self.send)

send(clicked) #

Send chosen value to parent dialog on Send button click.

Source code in cogip/widgets/wizard.py
128
129
130
131
132
133
@qtSlot()
def send(self, clicked: bool):
    """
    Send chosen value to parent dialog on Send button click.
    """
    self.response.emit("")

SelectWizard #

Bases: QObject

SelectWizard class.

Build a widget to select one or more integer, float or string from a list.

Source code in cogip/widgets/wizard.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
class SelectWizard(QtCore.QObject):
    """
    SelectWizard class.

    Build a widget to select one or more integer, float or string from a list.
    """

    response: qtSignal = qtSignal(list)

    def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
        """
        Class constructor.

        Arguments:
            wizard: wizard request
            parent: the parent widget
        """
        super().__init__()
        self.wizard = wizard

        layout = QtWidgets.QVBoxLayout()
        parent.setLayout(layout)

        self.buttons = []
        for v in wizard["choices"]:
            button = QtWidgets.QCheckBox(str(v))
            self.buttons.append(button)
            button.setChecked(v in wizard["value"])
            layout.addWidget(button)
        send_button = QtWidgets.QPushButton("Send")
        layout.addWidget(send_button)
        send_button.clicked.connect(self.send)

    @qtSlot()
    def send(self, clicked: bool):
        """
        Send chosen value to parent dialog on Send button click.
        """
        print([button.text() for button in self.buttons if button.isChecked()])
        self.response.emit([button.text() for button in self.buttons if button.isChecked()])

__init__(wizard, parent) #

Class constructor.

Parameters:

Name Type Description Default
wizard dict[str, Any]

wizard request

required
parent QWidget

the parent widget

required
Source code in cogip/widgets/wizard.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
def __init__(self, wizard: dict[str, Any], parent: QtWidgets.QWidget):
    """
    Class constructor.

    Arguments:
        wizard: wizard request
        parent: the parent widget
    """
    super().__init__()
    self.wizard = wizard

    layout = QtWidgets.QVBoxLayout()
    parent.setLayout(layout)

    self.buttons = []
    for v in wizard["choices"]:
        button = QtWidgets.QCheckBox(str(v))
        self.buttons.append(button)
        button.setChecked(v in wizard["value"])
        layout.addWidget(button)
    send_button = QtWidgets.QPushButton("Send")
    layout.addWidget(send_button)
    send_button.clicked.connect(self.send)

send(clicked) #

Send chosen value to parent dialog on Send button click.

Source code in cogip/widgets/wizard.py
210
211
212
213
214
215
216
@qtSlot()
def send(self, clicked: bool):
    """
    Send chosen value to parent dialog on Send button click.
    """
    print([button.text() for button in self.buttons if button.isChecked()])
    self.response.emit([button.text() for button in self.buttons if button.isChecked()])

WizardDialog #

Bases: QDialog

WizardDialog class

Build a modal for wizard request.

Attributes:

Name Type Description
property_updated

Qt signal emitted when a property is updated

closed

Qt signal emitted when the window is hidden

Source code in cogip/widgets/wizard.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
class WizardDialog(QtWidgets.QDialog):
    """
    WizardDialog class

    Build a modal for wizard request.

    Attributes:
        property_updated: Qt signal emitted when a property is updated
        closed: Qt signal emitted when the window is hidden
    """

    response: qtSignal = qtSignal(dict)

    def __init__(self, message: dict[str, Any], parent: QtWidgets.QWidget = None):
        """
        Class constructor.

        Arguments:
            message: JSON Schema of properties with current values and namespace
            parent: The parent widget
        """
        super().__init__(parent)
        self.message = message
        self.setWindowTitle(self.message["name"])
        self.setModal(False)
        self.setMinimumWidth(300)

        match wizard_type := self.message["type"]:
            case "boolean":
                self.wizard = BooleanWizard(self.message, self)
            case "integer" | "floating" | "str":
                self.wizard = InputWizard(self.message, self)
            case "message":
                self.wizard = MessageWizard(self.message, self)
            case "choice_integer" | "choice_floating" | "choice_str":
                self.wizard = ChoiceWizard(self.message, self)
            case "select_integer" | "select_floating" | "select_str":
                self.wizard = SelectWizard(self.message, self)
            case "camp":
                self.wizard = CampWizard(self.message, self)
            case _:
                logger.warning(f"Wizard message '{wizard_type} unsupported'")
                return

        self.wizard.response.connect(self.respond)
        self.rejected.connect(self.force_close)

    def respond(self, response: str | list[str]):
        self.message["value"] = response
        self.response.emit(self.message)
        self.accept()

    def force_close(self):
        self.message["value"] = None
        self.response.emit(self.message)
        self.accept()

__init__(message, parent=None) #

Class constructor.

Parameters:

Name Type Description Default
message dict[str, Any]

JSON Schema of properties with current values and namespace

required
parent QWidget

The parent widget

None
Source code in cogip/widgets/wizard.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
def __init__(self, message: dict[str, Any], parent: QtWidgets.QWidget = None):
    """
    Class constructor.

    Arguments:
        message: JSON Schema of properties with current values and namespace
        parent: The parent widget
    """
    super().__init__(parent)
    self.message = message
    self.setWindowTitle(self.message["name"])
    self.setModal(False)
    self.setMinimumWidth(300)

    match wizard_type := self.message["type"]:
        case "boolean":
            self.wizard = BooleanWizard(self.message, self)
        case "integer" | "floating" | "str":
            self.wizard = InputWizard(self.message, self)
        case "message":
            self.wizard = MessageWizard(self.message, self)
        case "choice_integer" | "choice_floating" | "choice_str":
            self.wizard = ChoiceWizard(self.message, self)
        case "select_integer" | "select_floating" | "select_str":
            self.wizard = SelectWizard(self.message, self)
        case "camp":
            self.wizard = CampWizard(self.message, self)
        case _:
            logger.warning(f"Wizard message '{wizard_type} unsupported'")
            return

    self.wizard.response.connect(self.respond)
    self.rejected.connect(self.force_close)