From 2a787592b62468385f8804222734aa76fb6d7c03 Mon Sep 17 00:00:00 2001 From: Jann Stute <46534683+Computerdores@users.noreply.github.com> Date: Mon, 3 Mar 2025 20:13:49 +0100 Subject: [PATCH] fix: resouce leak in `translate_with_setter` by deleting the offending code (#817) * feat: implement first class for translated widget * feat: add further translated widget types * refactor: replace usages of translate_qobject with appropriate classes * refactor: remove wrapper classes * refactor: remove unnecessary used of Translations.formatted * refactor: remove further unnecessary format calls * refactor: replace calls for Translations.formatted with calls to str.format and remove some unused code * refactor: remove TranslatedString class * refactor: replace translate_with_setter with direct calls to the setter --- tagstudio/src/core/library/alchemy/library.py | 10 +- tagstudio/src/qt/main_window.py | 7 +- tagstudio/src/qt/modals/about.py | 36 ++- tagstudio/src/qt/modals/add_field.py | 11 +- tagstudio/src/qt/modals/build_color.py | 26 +-- tagstudio/src/qt/modals/build_namespace.py | 22 +- tagstudio/src/qt/modals/build_tag.py | 30 +-- tagstudio/src/qt/modals/delete_unlinked.py | 43 ++-- tagstudio/src/qt/modals/drop_import.py | 36 ++- tagstudio/src/qt/modals/file_extension.py | 16 +- tagstudio/src/qt/modals/fix_dupes.py | 40 +--- tagstudio/src/qt/modals/fix_unlinked.py | 28 +-- tagstudio/src/qt/modals/folders_to_tags.py | 14 +- tagstudio/src/qt/modals/merge_dupe_entries.py | 4 +- tagstudio/src/qt/modals/mirror_entities.py | 34 +-- tagstudio/src/qt/modals/relink_unlinked.py | 5 +- tagstudio/src/qt/modals/settings_panel.py | 6 +- tagstudio/src/qt/modals/tag_color_manager.py | 15 +- .../src/qt/modals/tag_color_selection.py | 2 +- tagstudio/src/qt/modals/tag_database.py | 25 +- tagstudio/src/qt/modals/tag_search.py | 18 +- tagstudio/src/qt/translations.py | 73 +----- tagstudio/src/qt/ts_qt.py | 213 +++++++----------- tagstudio/src/qt/widgets/color_box.py | 9 +- tagstudio/src/qt/widgets/item_thumb.py | 11 +- tagstudio/src/qt/widgets/landing.py | 7 +- tagstudio/src/qt/widgets/migration_modal.py | 43 ++-- .../widgets/paged_panel/paged_panel_state.py | 4 +- tagstudio/src/qt/widgets/panel.py | 9 +- .../qt/widgets/preview/field_containers.py | 2 +- .../src/qt/widgets/preview/file_attributes.py | 2 +- .../src/qt/widgets/preview/preview_thumb.py | 10 +- tagstudio/src/qt/widgets/preview_panel.py | 12 +- tagstudio/src/qt/widgets/tag.py | 4 +- tagstudio/src/qt/widgets/tag_color_label.py | 2 +- tagstudio/src/qt/widgets/tag_color_preview.py | 2 +- tagstudio/src/qt/widgets/video_player.py | 6 +- 37 files changed, 287 insertions(+), 550 deletions(-) diff --git a/tagstudio/src/core/library/alchemy/library.py b/tagstudio/src/core/library/alchemy/library.py index d1fa38c0..9a5121a6 100644 --- a/tagstudio/src/core/library/alchemy/library.py +++ b/tagstudio/src/core/library/alchemy/library.py @@ -368,13 +368,9 @@ class Library: db_version = db_result.value # type: ignore if db_version < 6: # NOTE: DB_VERSION 6 is the first supported SQL DB version. - mismatch_text = Translations.translate_formatted( - "status.library_version_mismatch" - ) - found_text = Translations.translate_formatted("status.library_version_found") - expected_text = Translations.translate_formatted( - "status.library_version_expected" - ) + mismatch_text = Translations["status.library_version_mismatch"] + found_text = Translations["status.library_version_found"] + expected_text = Translations["status.library_version_expected"] return LibraryStatus( success=False, message=( diff --git a/tagstudio/src/qt/main_window.py b/tagstudio/src/qt/main_window.py index c76fa7e9..d51a8afd 100644 --- a/tagstudio/src/qt/main_window.py +++ b/tagstudio/src/qt/main_window.py @@ -74,7 +74,7 @@ class Ui_MainWindow(QMainWindow): # Thumbnail Size placeholder self.thumb_size_combobox = QComboBox(self.centralwidget) self.thumb_size_combobox.setObjectName(u"thumbSizeComboBox") - Translations.translate_with_setter(self.thumb_size_combobox.setPlaceholderText, "home.thumbnail_size") + self.thumb_size_combobox.setPlaceholderText(Translations["home.thumbnail_size"]) self.thumb_size_combobox.setCurrentText("") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -142,7 +142,7 @@ class Ui_MainWindow(QMainWindow): self.horizontalLayout_2.addWidget(self.forwardButton) self.searchField = QLineEdit(self.centralwidget) - Translations.translate_with_setter(self.searchField.setPlaceholderText, "home.search_entries") + self.searchField.setPlaceholderText(Translations["home.search_entries"]) self.searchField.setObjectName(u"searchField") self.searchField.setMinimumSize(QSize(0, 32)) @@ -152,8 +152,7 @@ class Ui_MainWindow(QMainWindow): self.searchField.setCompleter(self.searchFieldCompleter) self.horizontalLayout_2.addWidget(self.searchField) - self.searchButton = QPushButton(self.centralwidget) - Translations.translate_qobject(self.searchButton, "home.search") + self.searchButton = QPushButton(Translations["home.search"], self.centralwidget) self.searchButton.setObjectName(u"searchButton") self.searchButton.setMinimumSize(QSize(0, 32)) diff --git a/tagstudio/src/qt/modals/about.py b/tagstudio/src/qt/modals/about.py index 7e04e338..8d921ad5 100644 --- a/tagstudio/src/qt/modals/about.py +++ b/tagstudio/src/qt/modals/about.py @@ -6,13 +6,7 @@ from PIL import ImageQt from PySide6.QtCore import Qt from PySide6.QtGui import QPixmap -from PySide6.QtWidgets import ( - QHBoxLayout, - QLabel, - QPushButton, - QVBoxLayout, - QWidget, -) +from PySide6.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout, QWidget from src.core.constants import VERSION, VERSION_BRANCH from src.qt.modals.ffmpeg_checker import FfmpegChecker from src.qt.resource_manager import ResourceManager @@ -22,7 +16,7 @@ from src.qt.translations import Translations class AboutModal(QWidget): def __init__(self, config_path): super().__init__() - Translations.translate_with_setter(self.setWindowTitle, "about.title") + self.setWindowTitle(Translations["about.title"]) self.fc: FfmpegChecker = FfmpegChecker() self.rm: ResourceManager = ResourceManager() @@ -42,10 +36,6 @@ class AboutModal(QWidget): self.logo_widget.setAlignment(Qt.AlignmentFlag.AlignHCenter) self.logo_widget.setContentsMargins(0, 0, 0, 20) - self.content_widget = QLabel() - self.content_widget.setObjectName("contentLabel") - self.content_widget.setWordWrap(True) - self.content_widget.setOpenExternalLinks(True) ff_version = self.fc.version() ffmpeg = 'Missing' if ff_version["ffmpeg"] is not None: @@ -53,23 +43,25 @@ class AboutModal(QWidget): ffprobe = 'Missing' if ff_version["ffprobe"] is not None: ffprobe = 'Found (' + ff_version["ffprobe"] + ")" - Translations.translate_qobject( - self.content_widget, - "about.content", - version=VERSION, - branch=VERSION_BRANCH, - config_path=config_path, - ffmpeg=ffmpeg, - ffprobe=ffprobe, + self.content_widget = QLabel( + Translations["about.content"].format( + version=VERSION, + branch=VERSION_BRANCH, + config_path=config_path, + ffmpeg=ffmpeg, + ffprobe=ffprobe, + ) ) + self.content_widget.setObjectName("contentLabel") + self.content_widget.setWordWrap(True) + self.content_widget.setOpenExternalLinks(True) self.content_widget.setAlignment(Qt.AlignmentFlag.AlignHCenter) self.button_widget = QWidget() self.button_layout = QHBoxLayout(self.button_widget) self.button_layout.addStretch(1) - self.close_button = QPushButton() - Translations.translate_qobject(self.close_button, "generic.close") + self.close_button = QPushButton(Translations["generic.close"]) self.close_button.clicked.connect(lambda: self.close()) self.close_button.setMaximumWidth(80) diff --git a/tagstudio/src/qt/modals/add_field.py b/tagstudio/src/qt/modals/add_field.py index 34e4021b..ee5d3c25 100644 --- a/tagstudio/src/qt/modals/add_field.py +++ b/tagstudio/src/qt/modals/add_field.py @@ -31,17 +31,16 @@ class AddFieldModal(QWidget): # [Cancel] [Save] super().__init__() self.lib = library - Translations.translate_with_setter(self.setWindowTitle, "library.field.add") + self.setWindowTitle(Translations["library.field.add"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(400, 300) self.root_layout = QVBoxLayout(self) self.root_layout.setContentsMargins(6, 6, 6, 6) - self.title_widget = QLabel() + self.title_widget = QLabel(Translations["library.field.add"]) self.title_widget.setObjectName("fieldTitle") self.title_widget.setWordWrap(True) self.title_widget.setStyleSheet("font-weight:bold;" "font-size:14px;" "padding-top: 6px;") - Translations.translate_qobject(self.title_widget, "library.field.add") self.title_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) self.list_widget = QListWidget() @@ -51,13 +50,11 @@ class AddFieldModal(QWidget): self.button_layout.setContentsMargins(6, 6, 6, 6) self.button_layout.addStretch(1) - self.cancel_button = QPushButton() - Translations.translate_qobject(self.cancel_button, "generic.cancel") + self.cancel_button = QPushButton(Translations["generic.cancel"]) self.cancel_button.clicked.connect(self.hide) self.button_layout.addWidget(self.cancel_button) - self.save_button = QPushButton() - Translations.translate_qobject(self.save_button, "generic.add") + self.save_button = QPushButton(Translations["generic.add"]) self.save_button.setDefault(True) self.save_button.clicked.connect(self.hide) self.save_button.clicked.connect( diff --git a/tagstudio/src/qt/modals/build_color.py b/tagstudio/src/qt/modals/build_color.py index 6914a0be..e9abcbf8 100644 --- a/tagstudio/src/qt/modals/build_color.py +++ b/tagstudio/src/qt/modals/build_color.py @@ -72,30 +72,23 @@ class BuildColorPanel(PanelWidget): self.preview_layout.addWidget(self.preview_button) # Name ----------------------------------------------------------------- - self.name_title = QLabel() - Translations.translate_qobject(self.name_title, "library_object.name") + self.name_title = QLabel(Translations["library_object.name"]) self.name_field = QLineEdit() self.name_field.setFixedHeight(24) self.name_field.textChanged.connect(self.on_text_changed) - Translations.translate_with_setter( - self.name_field.setPlaceholderText, "library_object.name_required" - ) + self.name_field.setPlaceholderText(Translations["library_object.name_required"]) self.form_layout.addRow(self.name_title, self.name_field) # Slug ----------------------------------------------------------------- - self.slug_title = QLabel() - Translations.translate_qobject(self.slug_title, "library_object.slug") + self.slug_title = QLabel(Translations["library_object.slug"]) self.slug_field = QLineEdit() self.slug_field.setEnabled(False) self.slug_field.setFixedHeight(24) - Translations.translate_with_setter( - self.slug_field.setPlaceholderText, "library_object.slug_required" - ) + self.slug_field.setPlaceholderText(Translations["library_object.slug_required"]) self.form_layout.addRow(self.slug_title, self.slug_field) # Primary -------------------------------------------------------------- - self.primary_title = QLabel() - Translations.translate_qobject(self.primary_title, "color.primary") + self.primary_title = QLabel(Translations["color.primary"]) self.primary_button = QPushButton() self.primary_button.setMinimumSize(44, 22) self.primary_button.setMaximumHeight(22) @@ -108,8 +101,7 @@ class BuildColorPanel(PanelWidget): self.secondary_layout = QHBoxLayout(self.secondary_widget) self.secondary_layout.setContentsMargins(0, 0, 0, 0) self.secondary_layout.setSpacing(6) - self.secondary_title = QLabel() - Translations.translate_qobject(self.secondary_title, "color.secondary") + self.secondary_title = QLabel(Translations["color.secondary"]) self.secondary_button = QPushButton() self.secondary_button.setMinimumSize(44, 22) self.secondary_button.setMaximumHeight(22) @@ -117,8 +109,7 @@ class BuildColorPanel(PanelWidget): self.secondary_button.clicked.connect(self.secondary_color_callback) self.secondary_layout.addWidget(self.secondary_button) - self.secondary_reset_button = QPushButton() - Translations.translate_qobject(self.secondary_reset_button, "generic.reset") + self.secondary_reset_button = QPushButton(Translations["generic.reset"]) self.secondary_reset_button.clicked.connect(self.update_secondary) self.secondary_layout.addWidget(self.secondary_reset_button) self.secondary_layout.setStretch(0, 3) @@ -143,8 +134,7 @@ class BuildColorPanel(PanelWidget): ) ) self.border_layout.addWidget(self.border_checkbox) - self.border_label = QLabel() - Translations.translate_qobject(self.border_label, "color.color_border") + self.border_label = QLabel(Translations["color.color_border"]) self.border_layout.addWidget(self.border_label) primary_color = QColor(get_tag_color(ColorType.PRIMARY, TagColorEnum.DEFAULT)) diff --git a/tagstudio/src/qt/modals/build_namespace.py b/tagstudio/src/qt/modals/build_namespace.py index 5b34c2ed..6566d0e4 100644 --- a/tagstudio/src/qt/modals/build_namespace.py +++ b/tagstudio/src/qt/modals/build_namespace.py @@ -48,15 +48,12 @@ class BuildNamespacePanel(PanelWidget): self.name_layout.setContentsMargins(0, 0, 0, 0) self.name_layout.setSpacing(0) self.name_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.name_title = QLabel() - Translations.translate_qobject(self.name_title, "library_object.name") + self.name_title = QLabel(Translations["library_object.name"]) self.name_layout.addWidget(self.name_title) self.name_field = QLineEdit() self.name_field.setFixedHeight(24) self.name_field.textChanged.connect(self.on_text_changed) - Translations.translate_with_setter( - self.name_field.setPlaceholderText, "library_object.name_required" - ) + self.name_field.setPlaceholderText(Translations["library_object.name_required"]) self.name_layout.addWidget(self.name_field) # Slug ----------------------------------------------------------------- @@ -66,26 +63,19 @@ class BuildNamespacePanel(PanelWidget): self.slug_layout.setContentsMargins(0, 0, 0, 0) self.slug_layout.setSpacing(0) self.slug_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.slug_title = QLabel() - Translations.translate_qobject(self.slug_title, "library_object.slug") + self.slug_title = QLabel(Translations["library_object.slug"]) self.slug_layout.addWidget(self.slug_title) self.slug_field = QLineEdit() self.slug_field.setFixedHeight(24) self.slug_field.setEnabled(False) - Translations.translate_with_setter( - self.slug_field.setPlaceholderText, "library_object.slug_required" - ) + self.slug_field.setPlaceholderText(Translations["library_object.slug_required"]) self.slug_layout.addWidget(self.slug_field) # Description ---------------------------------------------------------- - self.desc_label = QLabel() + self.desc_label = QLabel(Translations["namespace.create.description"]) self.desc_label.setWordWrap(True) - Translations.translate_with_setter(self.desc_label.setText, "namespace.create.description") - self.desc_color_label = QLabel() + self.desc_color_label = QLabel(Translations["namespace.create.description_color"]) self.desc_color_label.setWordWrap(True) - Translations.translate_with_setter( - self.desc_color_label.setText, "namespace.create.description_color" - ) # Add Widgets to Layout ================================================ self.root_layout.addWidget(self.name_widget) diff --git a/tagstudio/src/qt/modals/build_tag.py b/tagstudio/src/qt/modals/build_tag.py index 2732a43a..c9657b8f 100644 --- a/tagstudio/src/qt/modals/build_tag.py +++ b/tagstudio/src/qt/modals/build_tag.py @@ -86,15 +86,12 @@ class BuildTagPanel(PanelWidget): self.name_layout.setContentsMargins(0, 0, 0, 0) self.name_layout.setSpacing(0) self.name_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.name_title = QLabel() - Translations.translate_qobject(self.name_title, "tag.name") + self.name_title = QLabel(Translations["tag.name"]) self.name_layout.addWidget(self.name_title) self.name_field = QLineEdit() self.name_field.setFixedHeight(24) self.name_field.textChanged.connect(self.on_name_changed) - Translations.translate_with_setter( - self.name_field.setPlaceholderText, "tag.tag_name_required" - ) + self.name_field.setPlaceholderText(Translations["tag.tag_name_required"]) self.name_layout.addWidget(self.name_field) # Shorthand ------------------------------------------------------------ @@ -104,8 +101,7 @@ class BuildTagPanel(PanelWidget): self.shorthand_layout.setContentsMargins(0, 0, 0, 0) self.shorthand_layout.setSpacing(0) self.shorthand_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.shorthand_title = QLabel() - Translations.translate_qobject(self.shorthand_title, "tag.shorthand") + self.shorthand_title = QLabel(Translations["tag.shorthand"]) self.shorthand_layout.addWidget(self.shorthand_title) self.shorthand_field = QLineEdit() self.shorthand_layout.addWidget(self.shorthand_field) @@ -117,8 +113,7 @@ class BuildTagPanel(PanelWidget): self.aliases_layout.setContentsMargins(0, 0, 0, 0) self.aliases_layout.setSpacing(0) self.aliases_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.aliases_title = QLabel() - Translations.translate_qobject(self.aliases_title, "tag.aliases") + self.aliases_title = QLabel(Translations["tag.aliases"]) self.aliases_layout.addWidget(self.aliases_title) self.aliases_table = QTableWidget(0, 2) @@ -144,8 +139,7 @@ class BuildTagPanel(PanelWidget): self.disam_button_group = QButtonGroup(self) self.disam_button_group.setExclusive(False) - self.parent_tags_title = QLabel() - Translations.translate_qobject(self.parent_tags_title, "tag.parent_tags") + self.parent_tags_title = QLabel(Translations["tag.parent_tags"]) self.parent_tags_layout.addWidget(self.parent_tags_title) self.scroll_contents = QWidget() @@ -173,8 +167,8 @@ class BuildTagPanel(PanelWidget): tsp = TagSearchPanel(self.lib, exclude_ids) tsp.tag_chosen.connect(lambda x: self.add_parent_tag_callback(x)) self.add_tag_modal = PanelModal(tsp) - Translations.translate_with_setter(self.add_tag_modal.setTitle, "tag.parent_tags.add") - Translations.translate_with_setter(self.add_tag_modal.setWindowTitle, "tag.parent_tags.add") + self.add_tag_modal.setTitle(Translations["tag.parent_tags.add"]) + self.add_tag_modal.setWindowTitle(Translations["tag.parent_tags.add"]) self.parent_tags_add_button.clicked.connect(self.add_tag_modal.show) # Color ---------------------------------------------------------------- @@ -184,8 +178,7 @@ class BuildTagPanel(PanelWidget): self.color_layout.setContentsMargins(0, 0, 0, 6) self.color_layout.setSpacing(6) self.color_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.color_title = QLabel() - Translations.translate_qobject(self.color_title, "tag.color") + self.color_title = QLabel(Translations["tag.color"]) self.color_layout.addWidget(self.color_title) self.color_button: TagColorPreview try: @@ -195,7 +188,7 @@ class BuildTagPanel(PanelWidget): logger.error("[BuildTag] Could not access Tag member attributes", error=e) self.color_button = TagColorPreview(self.lib, None) self.tag_color_selection = TagColorSelection(self.lib) - chose_tag_color_title = Translations.translate_formatted("tag.choose_color") + chose_tag_color_title = Translations["tag.choose_color"] self.choose_color_modal = PanelModal( self.tag_color_selection, chose_tag_color_title, @@ -214,8 +207,7 @@ class BuildTagPanel(PanelWidget): self.cat_layout.setContentsMargins(0, 0, 0, 0) self.cat_layout.setSpacing(6) self.cat_layout.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.cat_title = QLabel() - Translations.translate_qobject(self.cat_title, "tag.is_category") + self.cat_title = QLabel(Translations["tag.is_category"]) self.cat_checkbox = QCheckBox() self.cat_checkbox.setFixedSize(22, 22) @@ -404,7 +396,7 @@ class BuildTagPanel(PanelWidget): disam_button = QRadioButton() disam_button.setObjectName(f"disambiguationButton.{parent_id}") disam_button.setFixedSize(22, 22) - disam_button.setToolTip(Translations.translate_formatted("tag.disambiguation.tooltip")) + disam_button.setToolTip(Translations["tag.disambiguation.tooltip"]) disam_button.setStyleSheet( f"QRadioButton{{" f"background: rgba{primary_color.toTuple()};" diff --git a/tagstudio/src/qt/modals/delete_unlinked.py b/tagstudio/src/qt/modals/delete_unlinked.py index e427f30b..c038b7b4 100644 --- a/tagstudio/src/qt/modals/delete_unlinked.py +++ b/tagstudio/src/qt/modals/delete_unlinked.py @@ -7,14 +7,7 @@ from typing import TYPE_CHECKING, override from PySide6 import QtCore, QtGui from PySide6.QtCore import Qt, QThreadPool, Signal from PySide6.QtGui import QStandardItem, QStandardItemModel -from PySide6.QtWidgets import ( - QHBoxLayout, - QLabel, - QListView, - QPushButton, - QVBoxLayout, - QWidget, -) +from PySide6.QtWidgets import QHBoxLayout, QLabel, QListView, QPushButton, QVBoxLayout, QWidget from src.core.utils.missing_files import MissingRegistry from src.qt.helpers.custom_runnable import CustomRunnable from src.qt.translations import Translations @@ -32,20 +25,19 @@ class DeleteUnlinkedEntriesModal(QWidget): super().__init__() self.driver = driver self.tracker = tracker - Translations.translate_with_setter(self.setWindowTitle, "entries.unlinked.delete") + self.setWindowTitle(Translations["entries.unlinked.delete"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(500, 400) self.root_layout = QVBoxLayout(self) self.root_layout.setContentsMargins(6, 6, 6, 6) - self.desc_widget = QLabel() + self.desc_widget = QLabel( + Translations["entries.unlinked.delete.confirm"].format( + count=self.tracker.missing_file_entries_count, + ) + ) self.desc_widget.setObjectName("descriptionLabel") self.desc_widget.setWordWrap(True) - Translations.translate_qobject( - self.desc_widget, - "entries.unlinked.delete.confirm", - count=self.tracker.missing_file_entries_count, - ) self.desc_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) self.list_view = QListView() @@ -57,14 +49,12 @@ class DeleteUnlinkedEntriesModal(QWidget): self.button_layout.setContentsMargins(6, 6, 6, 6) self.button_layout.addStretch(1) - self.cancel_button = QPushButton() - Translations.translate_qobject(self.cancel_button, "generic.cancel_alt") + self.cancel_button = QPushButton(Translations["generic.cancel_alt"]) self.cancel_button.setDefault(True) self.cancel_button.clicked.connect(self.hide) self.button_layout.addWidget(self.cancel_button) - self.delete_button = QPushButton() - Translations.translate_qobject(self.delete_button, "generic.delete_alt") + self.delete_button = QPushButton(Translations["generic.delete_alt"]) self.delete_button.clicked.connect(self.hide) self.delete_button.clicked.connect(lambda: self.delete_entries()) self.button_layout.addWidget(self.delete_button) @@ -75,8 +65,8 @@ class DeleteUnlinkedEntriesModal(QWidget): def refresh_list(self): self.desc_widget.setText( - Translations.translate_formatted( - "entries.unlinked.delete.confirm", count=self.tracker.missing_file_entries_count + Translations["entries.unlinked.delete.confirm"].format( + count=self.tracker.missing_file_entries_count ) ) @@ -87,20 +77,13 @@ class DeleteUnlinkedEntriesModal(QWidget): self.model.appendRow(item) def delete_entries(self): - def displayed_text(x): - return Translations.translate_formatted( - "entries.unlinked.delete.deleting_count", - idx=x, - count=self.tracker.missing_file_entries_count, - ) - pw = ProgressWidget( cancel_button_text=None, minimum=0, maximum=0, ) - Translations.translate_with_setter(pw.setWindowTitle, "entries.unlinked.delete.deleting") - Translations.translate_with_setter(pw.update_label, "entries.unlinked.delete.deleting") + pw.setWindowTitle(Translations["entries.unlinked.delete.deleting"]) + pw.update_label(Translations["entries.unlinked.delete.deleting"]) pw.show() r = CustomRunnable(self.tracker.execute_deletion) diff --git a/tagstudio/src/qt/modals/drop_import.py b/tagstudio/src/qt/modals/drop_import.py index 4354403f..d0d1daff 100644 --- a/tagstudio/src/qt/modals/drop_import.py +++ b/tagstudio/src/qt/modals/drop_import.py @@ -11,14 +11,7 @@ import structlog from PySide6 import QtCore, QtGui from PySide6.QtCore import Qt, QUrl from PySide6.QtGui import QStandardItem, QStandardItemModel -from PySide6.QtWidgets import ( - QHBoxLayout, - QLabel, - QListView, - QPushButton, - QVBoxLayout, - QWidget, -) +from PySide6.QtWidgets import QHBoxLayout, QLabel, QListView, QPushButton, QVBoxLayout, QWidget from src.qt.translations import Translations from src.qt.widgets.progress import ProgressWidget @@ -44,7 +37,7 @@ class DropImportModal(QWidget): self.driver: QtDriver = driver # Widget ====================== - Translations.translate_with_setter(self.setWindowTitle, "drop_import.title") + self.setWindowTitle(Translations["drop_import.title"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(500, 400) self.root_layout = QVBoxLayout(self) @@ -67,26 +60,22 @@ class DropImportModal(QWidget): self.button_layout.setContentsMargins(6, 6, 6, 6) self.button_layout.addStretch(1) - self.skip_button = QPushButton() - Translations.translate_qobject(self.skip_button, "generic.skip_alt") + self.skip_button = QPushButton(Translations["generic.skip_alt"]) self.skip_button.setDefault(True) self.skip_button.clicked.connect(lambda: self.begin_transfer(DuplicateChoice.SKIP)) self.button_layout.addWidget(self.skip_button) - self.overwrite_button = QPushButton() - Translations.translate_qobject(self.overwrite_button, "generic.overwrite_alt") + self.overwrite_button = QPushButton(Translations["generic.overwrite_alt"]) self.overwrite_button.clicked.connect( lambda: self.begin_transfer(DuplicateChoice.OVERWRITE) ) self.button_layout.addWidget(self.overwrite_button) - self.rename_button = QPushButton() - Translations.translate_qobject(self.rename_button, "generic.rename_alt") + self.rename_button = QPushButton(Translations["generic.rename_alt"]) self.rename_button.clicked.connect(lambda: self.begin_transfer(DuplicateChoice.RENAME)) self.button_layout.addWidget(self.rename_button) - self.cancel_button = QPushButton() - Translations.translate_qobject(self.cancel_button, "generic.cancel_alt") + self.cancel_button = QPushButton(Translations["generic.cancel_alt"]) self.cancel_button.clicked.connect(lambda: self.begin_transfer(DuplicateChoice.CANCEL)) self.button_layout.addWidget(self.cancel_button) @@ -142,8 +131,8 @@ class DropImportModal(QWidget): self.desc_widget.setText( Translations["drop_import.duplicates_choice.singular"] if len(self.duplicate_files) == 1 - else Translations.translate_formatted( - "drop_import.duplicates_choice.plural", count=len(self.duplicate_files) + else Translations["drop_import.duplicates_choice.plural"].format( + count=len(self.duplicate_files) ) ) @@ -165,10 +154,11 @@ class DropImportModal(QWidget): return def displayed_text(x): - return Translations.translate_formatted( + return Translations[ "drop_import.progress.label.singular" if x[0] + 1 == 1 - else "drop_import.progress.label.plural", + else "drop_import.progress.label.plural" + ].format( count=x[0] + 1, suffix=f" {x[1]} {self.choice.value}" if self.choice else "", ) @@ -178,8 +168,8 @@ class DropImportModal(QWidget): minimum=0, maximum=len(self.files), ) - Translations.translate_with_setter(pw.setWindowTitle, "drop_import.progress.window_title") - Translations.translate_with_setter(pw.update_label, "drop_import.progress.label.initial") + pw.setWindowTitle(Translations["drop_import.progress.window_title"]) + pw.update_label(Translations["drop_import.progress.label.initial"]) pw.from_iterable_function( self.copy_files, diff --git a/tagstudio/src/qt/modals/file_extension.py b/tagstudio/src/qt/modals/file_extension.py index 49b5b147..8e9c2529 100644 --- a/tagstudio/src/qt/modals/file_extension.py +++ b/tagstudio/src/qt/modals/file_extension.py @@ -36,7 +36,7 @@ class FileExtensionModal(PanelWidget): super().__init__() # Initialize Modal ===================================================== self.lib = library - Translations.translate_with_setter(self.setWindowTitle, "ignore_list.title") + self.setWindowTitle(Translations["ignore_list.title"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(240, 400) self.root_layout = QVBoxLayout(self) @@ -50,8 +50,7 @@ class FileExtensionModal(PanelWidget): self.table.setItemDelegate(FileExtensionItemDelegate()) # Create "Add Button" Widget ------------------------------------------- - self.add_button = QPushButton() - Translations.translate_qobject(self.add_button, "ignore_list.add_extension") + self.add_button = QPushButton(Translations["ignore_list.add_extension"]) self.add_button.clicked.connect(self.add_item) self.add_button.setDefault(True) self.add_button.setMinimumWidth(100) @@ -61,18 +60,13 @@ class FileExtensionModal(PanelWidget): self.mode_layout = QHBoxLayout(self.mode_widget) self.mode_layout.setContentsMargins(0, 0, 0, 0) self.mode_layout.setSpacing(12) - self.mode_label = QLabel() - Translations.translate_qobject(self.mode_label, "ignore_list.mode.label") + self.mode_label = QLabel(Translations["ignore_list.mode.label"]) self.mode_combobox = QComboBox() self.mode_combobox.setEditable(False) self.mode_combobox.addItem("") self.mode_combobox.addItem("") - Translations.translate_with_setter( - lambda text: self.mode_combobox.setItemText(0, text), "ignore_list.mode.include" - ) - Translations.translate_with_setter( - lambda text: self.mode_combobox.setItemText(1, text), "ignore_list.mode.exclude" - ) + self.mode_combobox.setItemText(0, Translations["ignore_list.mode.include"]) + self.mode_combobox.setItemText(1, Translations["ignore_list.mode.exclude"]) is_exclude_list = int(bool(self.lib.prefs(LibraryPrefs.IS_EXCLUDE_LIST))) diff --git a/tagstudio/src/qt/modals/fix_dupes.py b/tagstudio/src/qt/modals/fix_dupes.py index da504b6b..db997e31 100644 --- a/tagstudio/src/qt/modals/fix_dupes.py +++ b/tagstudio/src/qt/modals/fix_dupes.py @@ -7,14 +7,7 @@ from typing import TYPE_CHECKING, override from PySide6 import QtCore, QtGui from PySide6.QtCore import Qt -from PySide6.QtWidgets import ( - QFileDialog, - QHBoxLayout, - QLabel, - QPushButton, - QVBoxLayout, - QWidget, -) +from PySide6.QtWidgets import QFileDialog, QHBoxLayout, QLabel, QPushButton, QVBoxLayout, QWidget from src.core.library import Library from src.core.utils.dupe_files import DupeRegistry from src.qt.modals.mirror_entities import MirrorEntriesModal @@ -32,7 +25,7 @@ class FixDupeFilesModal(QWidget): self.driver = driver self.count = -1 self.filename = "" - Translations.translate_with_setter(self.setWindowTitle, "file.duplicates.fix") + self.setWindowTitle(Translations["file.duplicates.fix"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(400, 300) self.root_layout = QVBoxLayout(self) @@ -40,11 +33,10 @@ class FixDupeFilesModal(QWidget): self.tracker = DupeRegistry(library=self.lib) - self.desc_widget = QLabel() + self.desc_widget = QLabel(Translations["file.duplicates.description"]) self.desc_widget.setObjectName("descriptionLabel") self.desc_widget.setWordWrap(True) self.desc_widget.setStyleSheet("text-align:left;") - Translations.translate_qobject(self.desc_widget, "file.duplicates.description") self.desc_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) self.dupe_count = QLabel() @@ -52,35 +44,29 @@ class FixDupeFilesModal(QWidget): self.dupe_count.setStyleSheet("font-weight:bold;" "font-size:14px;" "") self.dupe_count.setAlignment(Qt.AlignmentFlag.AlignCenter) - self.file_label = QLabel() + self.file_label = QLabel(Translations["file.duplicates.dupeguru.no_file"]) self.file_label.setObjectName("fileLabel") - Translations.translate_qobject(self.file_label, "file.duplicates.dupeguru.no_file") - self.open_button = QPushButton() - Translations.translate_qobject(self.open_button, "file.duplicates.dupeguru.load_file") + self.open_button = QPushButton(Translations["file.duplicates.dupeguru.load_file"]) self.open_button.clicked.connect(self.select_file) self.mirror_modal = MirrorEntriesModal(self.driver, self.tracker) self.mirror_modal.done.connect(self.refresh_dupes) - self.mirror_button = QPushButton() - Translations.translate_qobject(self.mirror_button, "file.duplicates.mirror_entries") + self.mirror_button = QPushButton(Translations["file.duplicates.mirror_entries"]) self.mirror_button.clicked.connect(self.mirror_modal.show) - self.mirror_desc = QLabel() + self.mirror_desc = QLabel(Translations["file.duplicates.mirror.description"]) self.mirror_desc.setWordWrap(True) - Translations.translate_qobject(self.mirror_desc, "file.duplicates.mirror.description") - self.advice_label = QLabel() + self.advice_label = QLabel(Translations["file.duplicates.dupeguru.advice"]) self.advice_label.setWordWrap(True) - Translations.translate_qobject(self.advice_label, "file.duplicates.dupeguru.advice") self.button_container = QWidget() self.button_layout = QHBoxLayout(self.button_container) self.button_layout.setContentsMargins(6, 6, 6, 6) self.button_layout.addStretch(1) - self.done_button = QPushButton() - Translations.translate_qobject(self.done_button, "generic.done_alt") + self.done_button = QPushButton(Translations["generic.done_alt"]) self.done_button.setDefault(True) self.done_button.clicked.connect(self.hide) self.button_layout.addWidget(self.done_button) @@ -128,14 +114,10 @@ class FixDupeFilesModal(QWidget): self.dupe_count.setText(Translations["file.duplicates.matches_uninitialized"]) elif count == 0: self.mirror_button.setDisabled(True) - self.dupe_count.setText( - Translations.translate_formatted("file.duplicates.matches", count=count) - ) + self.dupe_count.setText(Translations["file.duplicates.matches"].format(count=count)) else: self.mirror_button.setDisabled(False) - self.dupe_count.setText( - Translations.translate_formatted("file.duplicates.matches", count=count) - ) + self.dupe_count.setText(Translations["file.duplicates.matches"].format(count=count)) @override def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: # noqa N802 diff --git a/tagstudio/src/qt/modals/fix_unlinked.py b/tagstudio/src/qt/modals/fix_unlinked.py index e4eb5ed4..4b3dd9d2 100644 --- a/tagstudio/src/qt/modals/fix_unlinked.py +++ b/tagstudio/src/qt/modals/fix_unlinked.py @@ -31,17 +31,16 @@ class FixUnlinkedEntriesModal(QWidget): self.missing_count = -1 self.dupe_count = -1 - Translations.translate_with_setter(self.setWindowTitle, "entries.unlinked.title") + self.setWindowTitle(Translations["entries.unlinked.title"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(400, 300) self.root_layout = QVBoxLayout(self) self.root_layout.setContentsMargins(6, 6, 6, 6) - self.unlinked_desc_widget = QLabel() + self.unlinked_desc_widget = QLabel(Translations["entries.unlinked.description"]) self.unlinked_desc_widget.setObjectName("unlinkedDescriptionLabel") self.unlinked_desc_widget.setWordWrap(True) self.unlinked_desc_widget.setStyleSheet("text-align:left;") - Translations.translate_qobject(self.unlinked_desc_widget, "entries.unlinked.description") self.missing_count_label = QLabel() self.missing_count_label.setObjectName("missingCountLabel") @@ -53,15 +52,13 @@ class FixUnlinkedEntriesModal(QWidget): self.dupe_count_label.setStyleSheet("font-weight:bold;" "font-size:14px;") self.dupe_count_label.setAlignment(Qt.AlignmentFlag.AlignCenter) - self.refresh_unlinked_button = QPushButton() - Translations.translate_qobject(self.refresh_unlinked_button, "entries.unlinked.refresh_all") + self.refresh_unlinked_button = QPushButton(Translations["entries.unlinked.refresh_all"]) self.refresh_unlinked_button.clicked.connect(self.refresh_missing_files) self.merge_class = MergeDuplicateEntries(self.lib, self.driver) self.relink_class = RelinkUnlinkedEntries(self.tracker) - self.search_button = QPushButton() - Translations.translate_qobject(self.search_button, "entries.unlinked.search_and_relink") + self.search_button = QPushButton(Translations["entries.unlinked.search_and_relink"]) self.relink_class.done.connect( # refresh the grid lambda: ( @@ -71,11 +68,10 @@ class FixUnlinkedEntriesModal(QWidget): ) self.search_button.clicked.connect(self.relink_class.repair_entries) - self.manual_button = QPushButton() - Translations.translate_qobject(self.manual_button, "entries.unlinked.relink.manual") + self.manual_button = QPushButton(Translations["entries.unlinked.relink.manual"]) self.manual_button.setHidden(True) - self.delete_button = QPushButton() + self.delete_button = QPushButton(Translations["entries.unlinked.delete_alt"]) self.delete_modal = DeleteUnlinkedEntriesModal(self.driver, self.tracker) self.delete_modal.done.connect( lambda: ( @@ -84,7 +80,6 @@ class FixUnlinkedEntriesModal(QWidget): self.driver.filter_items(), ) ) - Translations.translate_qobject(self.delete_button, "entries.unlinked.delete_alt") self.delete_button.clicked.connect(self.delete_modal.show) self.button_container = QWidget() @@ -92,8 +87,7 @@ class FixUnlinkedEntriesModal(QWidget): self.button_layout.setContentsMargins(6, 6, 6, 6) self.button_layout.addStretch(1) - self.done_button = QPushButton() - Translations.translate_qobject(self.done_button, "generic.done_alt") + self.done_button = QPushButton(Translations["generic.done_alt"]) self.done_button.setDefault(True) self.done_button.clicked.connect(self.hide) self.button_layout.addWidget(self.done_button) @@ -116,8 +110,8 @@ class FixUnlinkedEntriesModal(QWidget): minimum=0, maximum=self.lib.entries_count, ) - Translations.translate_with_setter(pw.setWindowTitle, "library.scan_library.title") - Translations.translate_with_setter(pw.update_label, "entries.unlinked.scanning") + pw.setWindowTitle(Translations["library.scan_library.title"]) + pw.update_label(Translations["entries.unlinked.scanning"]) pw.from_iterable_function( self.tracker.refresh_missing_files, @@ -141,9 +135,7 @@ class FixUnlinkedEntriesModal(QWidget): self.search_button.setDisabled(self.missing_count == 0) self.delete_button.setDisabled(self.missing_count == 0) self.missing_count_label.setText( - Translations.translate_formatted( - "entries.unlinked.missing_count.some", count=self.missing_count - ) + Translations["entries.unlinked.missing_count.some"].format(count=self.missing_count) ) @override diff --git a/tagstudio/src/qt/modals/folders_to_tags.py b/tagstudio/src/qt/modals/folders_to_tags.py index 0b50fa46..fc045158 100644 --- a/tagstudio/src/qt/modals/folders_to_tags.py +++ b/tagstudio/src/qt/modals/folders_to_tags.py @@ -166,17 +166,16 @@ class FoldersToTagsModal(QWidget): self.count = -1 self.filename = "" - Translations.translate_with_setter(self.setWindowTitle, "folders_to_tags.title") + self.setWindowTitle(Translations["folders_to_tags.title"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(640, 640) self.root_layout = QVBoxLayout(self) self.root_layout.setContentsMargins(6, 6, 6, 6) - self.title_widget = QLabel() + self.title_widget = QLabel(Translations["folders_to_tags.title"]) self.title_widget.setObjectName("title") self.title_widget.setWordWrap(True) self.title_widget.setStyleSheet("font-weight:bold;" "font-size:14px;" "padding-top: 6px") - Translations.translate_qobject(self.title_widget, "folders_to_tags.title") self.title_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) self.desc_widget = QLabel() @@ -191,11 +190,9 @@ class FoldersToTagsModal(QWidget): self.open_close_button_w = QWidget() self.open_close_button_layout = QHBoxLayout(self.open_close_button_w) - self.open_all_button = QPushButton() - Translations.translate_qobject(self.open_all_button, "folders_to_tags.open_all") + self.open_all_button = QPushButton(Translations["folders_to_tags.open_all"]) self.open_all_button.clicked.connect(lambda: self.set_all_branches(False)) - self.close_all_button = QPushButton() - Translations.translate_qobject(self.close_all_button, "folders_to_tags.close_all") + self.close_all_button = QPushButton(Translations["folders_to_tags.close_all"]) self.close_all_button.clicked.connect(lambda: self.set_all_branches(True)) self.open_close_button_layout.addWidget(self.open_all_button) @@ -213,8 +210,7 @@ class FoldersToTagsModal(QWidget): self.scroll_area.setFrameShape(QFrame.Shape.NoFrame) self.scroll_area.setWidget(self.scroll_contents) - self.apply_button = QPushButton() - Translations.translate_qobject(self.apply_button, "generic.apply_alt") + self.apply_button = QPushButton(Translations["generic.apply_alt"]) self.apply_button.setMinimumWidth(100) self.apply_button.clicked.connect(self.on_apply) diff --git a/tagstudio/src/qt/modals/merge_dupe_entries.py b/tagstudio/src/qt/modals/merge_dupe_entries.py index 35bdf7c1..cd9baed8 100644 --- a/tagstudio/src/qt/modals/merge_dupe_entries.py +++ b/tagstudio/src/qt/modals/merge_dupe_entries.py @@ -30,7 +30,7 @@ class MergeDuplicateEntries(QObject): minimum=0, maximum=self.tracker.groups_count, ) - Translations.translate_with_setter(pw.setWindowTitle, "entries.duplicate.merge.label") - Translations.translate_with_setter(pw.update_label, "entries.duplicate.merge.label") + pw.setWindowTitle(Translations["entries.duplicate.merge.label"]) + pw.update_label(Translations["entries.duplicate.merge.label"]) pw.from_iterable_function(self.tracker.merge_dupe_entries, None, self.done.emit) diff --git a/tagstudio/src/qt/modals/mirror_entities.py b/tagstudio/src/qt/modals/mirror_entities.py index 4cb37a1c..2096af57 100644 --- a/tagstudio/src/qt/modals/mirror_entities.py +++ b/tagstudio/src/qt/modals/mirror_entities.py @@ -8,14 +8,7 @@ from time import sleep from PySide6.QtCore import Qt, Signal from PySide6.QtGui import QStandardItem, QStandardItemModel -from PySide6.QtWidgets import ( - QHBoxLayout, - QLabel, - QListView, - QPushButton, - QVBoxLayout, - QWidget, -) +from PySide6.QtWidgets import QHBoxLayout, QLabel, QListView, QPushButton, QVBoxLayout, QWidget from src.core.utils.dupe_files import DupeRegistry from src.qt.translations import Translations from src.qt.widgets.progress import ProgressWidget @@ -31,19 +24,18 @@ class MirrorEntriesModal(QWidget): def __init__(self, driver: "QtDriver", tracker: DupeRegistry): super().__init__() self.driver = driver - Translations.translate_with_setter(self.setWindowTitle, "entries.mirror.window_title") + self.setWindowTitle(Translations["entries.mirror.window_title"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(500, 400) self.root_layout = QVBoxLayout(self) self.root_layout.setContentsMargins(6, 6, 6, 6) self.tracker = tracker - self.desc_widget = QLabel() + self.desc_widget = QLabel( + Translations["entries.mirror.confirmation"].format(count=self.tracker.groups_count) + ) self.desc_widget.setObjectName("descriptionLabel") self.desc_widget.setWordWrap(True) - Translations.translate_qobject( - self.desc_widget, "entries.mirror.confirmation", count=self.tracker.groups_count - ) self.desc_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) self.list_view = QListView() @@ -55,14 +47,12 @@ class MirrorEntriesModal(QWidget): self.button_layout.setContentsMargins(6, 6, 6, 6) self.button_layout.addStretch(1) - self.cancel_button = QPushButton() - Translations.translate_qobject(self.cancel_button, "generic.cancel_alt") + self.cancel_button = QPushButton(Translations["generic.cancel_alt"]) self.cancel_button.setDefault(True) self.cancel_button.clicked.connect(self.hide) self.button_layout.addWidget(self.cancel_button) - self.mirror_button = QPushButton() - Translations.translate_qobject(self.mirror_button, "entries.mirror") + self.mirror_button = QPushButton(Translations["entries.mirror"]) self.mirror_button.clicked.connect(self.hide) self.mirror_button.clicked.connect(self.mirror_entries) self.button_layout.addWidget(self.mirror_button) @@ -73,9 +63,7 @@ class MirrorEntriesModal(QWidget): def refresh_list(self): self.desc_widget.setText( - Translations.translate_formatted( - "entries.mirror.confirmation", count=self.tracker.groups_count - ) + Translations["entries.mirror.confirmation"].format(count=self.tracker.groups_count) ) self.model.clear() @@ -84,8 +72,8 @@ class MirrorEntriesModal(QWidget): def mirror_entries(self): def displayed_text(x): - return Translations.translate_formatted( - "entries.mirror.label", idx=x + 1, count=self.tracker.groups_count + return Translations["entries.mirror.label"].format( + idx=x + 1, count=self.tracker.groups_count ) pw = ProgressWidget( @@ -93,7 +81,7 @@ class MirrorEntriesModal(QWidget): minimum=0, maximum=self.tracker.groups_count, ) - Translations.translate_with_setter(pw.setWindowTitle, "entries.mirror.title") + pw.setWindowTitle(Translations["entries.mirror.title"]) pw.from_iterable_function( self.mirror_entries_runnable, diff --git a/tagstudio/src/qt/modals/relink_unlinked.py b/tagstudio/src/qt/modals/relink_unlinked.py index 6dbd6f4c..51b88dee 100644 --- a/tagstudio/src/qt/modals/relink_unlinked.py +++ b/tagstudio/src/qt/modals/relink_unlinked.py @@ -18,8 +18,7 @@ class RelinkUnlinkedEntries(QObject): def repair_entries(self): def displayed_text(x): - return Translations.translate_formatted( - "entries.unlinked.relink.attempting", + return Translations["entries.unlinked.relink.attempting"].format( idx=x, missing_count=self.tracker.missing_file_entries_count, fixed_count=self.tracker.files_fixed_count, @@ -31,6 +30,6 @@ class RelinkUnlinkedEntries(QObject): minimum=0, maximum=self.tracker.missing_file_entries_count, ) - Translations.translate_with_setter(pw.setWindowTitle, "entries.unlinked.relink.title") + pw.setWindowTitle(Translations["entries.unlinked.relink.title"]) pw.from_iterable_function(self.tracker.fix_unlinked_entries, displayed_text, self.done.emit) diff --git a/tagstudio/src/qt/modals/settings_panel.py b/tagstudio/src/qt/modals/settings_panel.py index a499f6dd..476f3cf4 100644 --- a/tagstudio/src/qt/modals/settings_panel.py +++ b/tagstudio/src/qt/modals/settings_panel.py @@ -22,13 +22,11 @@ class SettingsPanel(PanelWidget): self.form_layout = QFormLayout(self.form_container) self.form_layout.setContentsMargins(0, 0, 0, 0) - self.restart_label = QLabel() + self.restart_label = QLabel(Translations["settings.restart_required"]) self.restart_label.setHidden(True) - Translations.translate_qobject(self.restart_label, "settings.restart_required") self.restart_label.setAlignment(Qt.AlignmentFlag.AlignCenter) - language_label = QLabel() - Translations.translate_qobject(language_label, "settings.language") + language_label = QLabel(Translations["settings.language"]) self.languages = { # "Cantonese (Traditional)": "yue_Hant", # Empty "Chinese (Traditional)": "zh_Hant", diff --git a/tagstudio/src/qt/modals/tag_color_manager.py b/tagstudio/src/qt/modals/tag_color_manager.py index 9b5f6b94..ecd6f625 100644 --- a/tagstudio/src/qt/modals/tag_color_manager.py +++ b/tagstudio/src/qt/modals/tag_color_manager.py @@ -44,7 +44,7 @@ class TagColorManager(QWidget): super().__init__() self.driver = driver self.lib = driver.lib - Translations.translate_with_setter(self.setWindowTitle, "color_manager.title") + self.setWindowTitle(Translations["color_manager.title"]) self.setWindowModality(Qt.WindowModality.ApplicationModal) self.setMinimumSize(800, 600) self.is_initialized = False @@ -91,8 +91,7 @@ class TagColorManager(QWidget): self.button_layout = QHBoxLayout(self.button_container) self.button_layout.setContentsMargins(6, 6, 6, 6) - self.new_namespace_button = QPushButton() - Translations.translate_qobject(self.new_namespace_button, "namespace.new.button") + self.new_namespace_button = QPushButton(Translations["namespace.new.button"]) self.new_namespace_button.clicked.connect(self.create_namespace) self.button_layout.addWidget(self.new_namespace_button) @@ -102,8 +101,7 @@ class TagColorManager(QWidget): self.button_layout.addStretch(1) - self.done_button = QPushButton() - Translations.translate_qobject(self.done_button, "generic.done_alt") + self.done_button = QPushButton(Translations["generic.done_alt"]) self.done_button.clicked.connect(self.hide) self.button_layout.addWidget(self.done_button) @@ -156,8 +154,7 @@ class TagColorManager(QWidget): ns_layout = QHBoxLayout(ns_container) ns_layout.setAlignment(Qt.AlignmentFlag.AlignCenter) ns_layout.setContentsMargins(0, 18, 0, 18) - namespace_prompt = QPushButton() - Translations.translate_qobject(namespace_prompt, "namespace.new.prompt") + namespace_prompt = QPushButton(Translations["namespace.new.prompt"]) namespace_prompt.setFixedSize(namespace_prompt.sizeHint().width() + 8, 24) namespace_prompt.clicked.connect(self.create_namespace) ns_layout.addWidget(namespace_prompt) @@ -195,9 +192,7 @@ class TagColorManager(QWidget): def delete_namespace_dialog(self, prompt: str, callback: Callable) -> None: message_box = QMessageBox() message_box.setText(prompt) - Translations.translate_with_setter( - message_box.setWindowTitle, "color.namespace.delete.title" - ) + message_box.setWindowTitle(Translations["color.namespace.delete.title"]) message_box.setIcon(QMessageBox.Icon.Warning) cancel_button = message_box.addButton( Translations["generic.cancel_alt"], QMessageBox.ButtonRole.RejectRole diff --git a/tagstudio/src/qt/modals/tag_color_selection.py b/tagstudio/src/qt/modals/tag_color_selection.py index f0f1585b..0d647fa2 100644 --- a/tagstudio/src/qt/modals/tag_color_selection.py +++ b/tagstudio/src/qt/modals/tag_color_selection.py @@ -139,7 +139,7 @@ class TagColorSelection(PanelWidget): self.scroll_layout.addSpacerItem(QSpacerItem(1, 6)) def add_no_color_widget(self): - no_color_str: str = Translations.translate_formatted("color.title.no_color") + no_color_str: str = Translations["color.title.no_color"] self.scroll_layout.addWidget(QLabel(f"