From 56d7093b1a0f1669be578ad73176e5edb97d77a4 Mon Sep 17 00:00:00 2001 From: xxyzz Date: Wed, 17 Jan 2024 18:55:26 +0800 Subject: [PATCH] Add buttons to enable or disable all displayed lemma rows --- custom_lemmas.py | 23 +++++++++++++++++++++-- custom_x_ray.py | 2 +- data/deps.json | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/custom_lemmas.py b/custom_lemmas.py index ed4542c..3d6188c 100644 --- a/custom_lemmas.py +++ b/custom_lemmas.py @@ -2,6 +2,7 @@ import base64 import sqlite3 +from functools import partial from pathlib import Path from typing import TYPE_CHECKING, Any @@ -81,7 +82,7 @@ def __init__( vl.addWidget(self.init_dialog_buttons()) def init_sql_table(self, is_kindle: bool) -> None: - self.lemmas_table = QTableView() + self.lemmas_table = QTableView(self) self.lemmas_table.setAlternatingRowColors(True) if is_kindle: self.check_empty_kindle_gloss() @@ -89,7 +90,7 @@ def init_sql_table(self, is_kindle: bool) -> None: db = QSqlDatabase.addDatabase("QSQLITE", self.db_connection_name) db.setDatabaseName(str(self.db_path)) db.open() - self.lemmas_model: LemmasTableModel = LemmasTableModel(db, is_kindle) + self.lemmas_model = LemmasTableModel(db, is_kindle) self.lemmas_model.setEditStrategy(QSqlTableModel.EditStrategy.OnFieldChange) self.lemmas_model.setTable("senses") self.lemmas_model.setRelation( @@ -136,6 +137,15 @@ def init_filters(self, form_layout: QFormLayout) -> None: self.filter_difficulty_box.currentIndexChanged.connect(self.filter_data) form_layout.addRow(_("Filter difficulty"), self.filter_difficulty_box) + hl = QHBoxLayout() + enable_all_button = QPushButton(_("Enable all")) + disable_all_button = QPushButton(_("Disable all")) + enable_all_button.clicked.connect(partial(self.enable_or_disable_words, True)) + disable_all_button.clicked.connect(partial(self.enable_or_disable_words, False)) + hl.addWidget(enable_all_button) + hl.addWidget(disable_all_button) + form_layout.addRow("", hl) + def init_wiktionary_buttons( self, form_layout: QFormLayout, gloss_lang: str ) -> None: @@ -326,6 +336,14 @@ def change_difficulty_limit(self): limit = int(self.difficulty_limit_box.currentText()) prefs[f"{self.lemma_lang}_wiktionary_difficulty_limit"] = limit + def enable_or_disable_words(self, enable: bool): + for row in range(self.lemmas_model.rowCount()): + record = self.lemmas_model.record(row) + record.setValue("enabled", int(enable)) + self.lemmas_model.setRecord(row, record) + self.lemmas_model.submitAll() + self.lemmas_model.select() + class LemmasTableModel(QSqlRelationalTableModel): def __init__(self, db: QSqlDatabase, is_kindle: bool) -> None: @@ -427,6 +445,7 @@ def createEditor(self, parent, option, index): def commit_editor(self): editor = self.sender() self.commitData.emit(editor) + self.closeEditor.emit(editor) def setEditorData(self, editor, index): value = index.data(Qt.ItemDataRole.DisplayRole) diff --git a/custom_x_ray.py b/custom_x_ray.py index 9720eec..579cc0d 100644 --- a/custom_x_ray.py +++ b/custom_x_ray.py @@ -49,7 +49,7 @@ def __init__(self, book_path: str, title: str, parent: Any = None) -> None: vl = QVBoxLayout() self.setLayout(vl) - self.x_ray_table = QTableView() + self.x_ray_table = QTableView(self) self.x_ray_table.setAlternatingRowColors(True) self.x_ray_model = XRayTableModel(book_path) self.x_ray_table.setModel(self.x_ray_model) diff --git a/data/deps.json b/data/deps.json index b8076ab..6fdd41b 100644 --- a/data/deps.json +++ b/data/deps.json @@ -1,6 +1,6 @@ { "cupy": "12.3.0", - "lxml": "5.0.0", + "lxml": "5.1.0", "rapidfuzz": "3.6.1", "spacy_cpu_model": "3.7.0", "spacy_trf_model": "3.7.2",