Skip to content

Commit

Permalink
Add bool FormInputType
Browse files Browse the repository at this point in the history
  • Loading branch information
y-richie-y committed Jul 16, 2024
1 parent 9aaf12f commit c67a5f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions zxlive/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ColorScheme(TypedDict):
"tab-bar-location": QTabWidget.TabPosition.North,
"snap-granularity": '4',
"input-circuit-format": 'openqasm',
'sound-effects': False,
}

font_defaults: dict[str, str | int | None] = {
Expand Down
11 changes: 9 additions & 2 deletions zxlive/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from PySide6.QtWidgets import (
QDialog, QFileDialog, QFormLayout, QLineEdit, QPushButton, QWidget,
QVBoxLayout, QSpinBox, QDoubleSpinBox, QLabel, QHBoxLayout, QTabWidget,
QComboBox, QApplication
QComboBox, QApplication, QCheckBox
)

from .common import get_settings_value, T, get_data
Expand All @@ -43,6 +43,7 @@ class FormInputType(IntEnum):
Float = 2
Folder = 3
Combo = 4
Bool = 5


class SettingsData(TypedDict):
Expand Down Expand Up @@ -78,7 +79,7 @@ class SettingsData(TypedDict):
{"id": "tab-bar-location", "label": "Tab bar location", "type": FormInputType.Combo, "data": tab_positioning_data},
{"id": "snap-granularity", "label": "Snap-to-grid granularity", "type": FormInputType.Combo, "data": snap_to_grid_data},
{"id": "input-circuit-format", "label": "Input Circuit as", "type": FormInputType.Combo, "data": input_circuit_formats},
{"id": "sound-effects", "label": "Sound Effects", "type": FormInputType.CheckBox},
{"id": "sound-effects", "label": "Sound Effects", "type": FormInputType.Bool},
]


Expand Down Expand Up @@ -196,6 +197,11 @@ def init_okay_cancel_buttons(self, layout: QVBoxLayout) -> None:
cancel_button.clicked.connect(self.cancel)
hlayout.addWidget(cancel_button)

def make_bool_form_input(self, data: SettingsData) -> QCheckBox:
widget = QCheckBox()
widget.setChecked(self.get_settings_from_data(data, bool))
return widget

def make_str_form_input(self, data: SettingsData) -> QLineEdit:
widget = QLineEdit()
widget.setText(self.get_settings_from_data(data, str))
Expand Down Expand Up @@ -248,6 +254,7 @@ def add_setting_to_form(self, form: QFormLayout, settings_data: SettingsData) ->
FormInputType.Float: self.make_float_form_input,
FormInputType.Folder: self.make_folder_form_input,
FormInputType.Combo: self.make_combo_form_input,
FormInputType.Bool: self.make_bool_form_input,
}
setting_widget_maker = setting_maker[settings_data["type"]]
widget: QWidget = setting_widget_maker(settings_data)
Expand Down

0 comments on commit c67a5f3

Please sign in to comment.