Skip to content

Commit

Permalink
Add buttons to enable or disable all displayed lemma rows
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Jan 17, 2024
1 parent f9216ac commit 56d7093
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions custom_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import base64
import sqlite3
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -81,15 +82,15 @@ 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()
self.db_connection_name = "lemmas_connection"
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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion custom_x_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion data/deps.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 56d7093

Please sign in to comment.