From 56f172e7b518e51304c20dc14318576009bbcde0 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Fri, 15 Sep 2023 23:46:13 +0100 Subject: [PATCH 1/2] Add combo box support to talker settings generator --- comictaggerlib/ui/talkeruigenerator.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/comictaggerlib/ui/talkeruigenerator.py b/comictaggerlib/ui/talkeruigenerator.py index 6028600..21b6dc2 100644 --- a/comictaggerlib/ui/talkeruigenerator.py +++ b/comictaggerlib/ui/talkeruigenerator.py @@ -167,6 +167,20 @@ def generate_password_textbox(option: settngs.Setting, layout: QtWidgets.QGridLa return widget +def generate_combobox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QComboBox: + row = layout.rowCount() + lbl = QtWidgets.QLabel(option.display_name) + lbl.setToolTip(option.help) + layout.addWidget(lbl, row, 0) + widget = QtWidgets.QComboBox() + for choice in option.choices: # type: ignore + widget.addItem(str(choice).capitalize(), str(choice)) + widget.setToolTip(option.help) + layout.addWidget(widget, row, 1) + + return widget + + def settings_to_talker_form(sources: Sources, config: settngs.Config[ct_ns]) -> None: # Set the active talker via id in sources combo box sources[0].setCurrentIndex(sources[0].findData(config[0].Sources_source)) @@ -180,6 +194,9 @@ def settings_to_talker_form(sources: Sources, config: settngs.Config[ct_ns]) -> try: if isinstance(value, str) and value and isinstance(widget, QtWidgets.QLineEdit) and not default: widget.setText(value) + if isinstance(value, str) and value and isinstance(widget, QtWidgets.QComboBox) and not default: + idx = widget.findData(value) + widget.setCurrentIndex(idx) if isinstance(value, (float, int)) and isinstance( widget, (QtWidgets.QSpinBox, QtWidgets.QDoubleSpinBox) ): @@ -199,6 +216,8 @@ def get_config_dict(tab: TalkerTab) -> dict[str, Any]: widget_value = widget.value() elif isinstance(widget, QtWidgets.QLineEdit): widget_value = widget.text().strip() + elif isinstance(widget, QtWidgets.QComboBox): + widget_value = widget.currentData() elif isinstance(widget, QtWidgets.QCheckBox): widget_value = widget.isChecked() @@ -274,7 +293,10 @@ def generate_source_option_tabs( tab.widgets[option.dest] = current_widget elif option._guess_type() is str: - current_widget = generate_textbox(option, layout_grid) + if option.choices is not None: + current_widget = generate_combobox(option, layout_grid) + else: + current_widget = generate_textbox(option, layout_grid) tab.widgets[option.dest] = current_widget else: logger.debug(f"Unsupported talker option found. Name: {option.internal_name} Type: {option.type}") From 8feade923a931eab72c272b3af77cd367b2a0d47 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Sun, 17 Sep 2023 20:54:20 +0100 Subject: [PATCH 2/2] Don't capitalise and therefore no need to use data on the combobox --- comictaggerlib/ui/talkeruigenerator.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/comictaggerlib/ui/talkeruigenerator.py b/comictaggerlib/ui/talkeruigenerator.py index 21b6dc2..16c18e1 100644 --- a/comictaggerlib/ui/talkeruigenerator.py +++ b/comictaggerlib/ui/talkeruigenerator.py @@ -174,7 +174,7 @@ def generate_combobox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> layout.addWidget(lbl, row, 0) widget = QtWidgets.QComboBox() for choice in option.choices: # type: ignore - widget.addItem(str(choice).capitalize(), str(choice)) + widget.addItem(str(choice)) widget.setToolTip(option.help) layout.addWidget(widget, row, 1) @@ -195,8 +195,7 @@ def settings_to_talker_form(sources: Sources, config: settngs.Config[ct_ns]) -> if isinstance(value, str) and value and isinstance(widget, QtWidgets.QLineEdit) and not default: widget.setText(value) if isinstance(value, str) and value and isinstance(widget, QtWidgets.QComboBox) and not default: - idx = widget.findData(value) - widget.setCurrentIndex(idx) + widget.setCurrentIndex(widget.findText(value)) if isinstance(value, (float, int)) and isinstance( widget, (QtWidgets.QSpinBox, QtWidgets.QDoubleSpinBox) ): @@ -217,7 +216,7 @@ def get_config_dict(tab: TalkerTab) -> dict[str, Any]: elif isinstance(widget, QtWidgets.QLineEdit): widget_value = widget.text().strip() elif isinstance(widget, QtWidgets.QComboBox): - widget_value = widget.currentData() + widget_value = widget.currentText() elif isinstance(widget, QtWidgets.QCheckBox): widget_value = widget.isChecked()