Add language to ComicTagger

This commit is contained in:
Timmy Welch 2024-12-06 22:02:32 -08:00
parent bf0a46055a
commit 38932f0782
6 changed files with 144 additions and 136 deletions

View File

@ -17,10 +17,13 @@
from __future__ import annotations
import logging
from typing import Any
import operator
import natsort
from PyQt5 import QtWidgets, uic
from comicapi import utils
from comicapi.genericmetadata import Credit
from comictaggerlib.ui import ui_path
logger = logging.getLogger(__name__)
@ -30,7 +33,7 @@ class CreditEditorWindow(QtWidgets.QDialog):
ModeEdit = 0
ModeNew = 1
def __init__(self, parent: QtWidgets.QWidget, mode: int, role: str, name: str, primary: bool) -> None:
def __init__(self, parent: QtWidgets.QWidget, mode: int, credit: Credit) -> None:
super().__init__(parent)
with (ui_path / "crediteditorwindow.ui").open(encoding="utf-8") as uifile:
@ -45,54 +48,47 @@ class CreditEditorWindow(QtWidgets.QDialog):
# Add the entries to the role combobox
self.cbRole.addItem("")
self.cbRole.addItem("Writer")
self.cbRole.addItem("Artist")
self.cbRole.addItem("Penciller")
self.cbRole.addItem("Inker")
self.cbRole.addItem("Colorist")
self.cbRole.addItem("Letterer")
self.cbRole.addItem("Cover Artist")
self.cbRole.addItem("Editor")
self.cbRole.addItem("Other")
self.cbRole.addItem("Inker")
self.cbRole.addItem("Letterer")
self.cbRole.addItem("Penciller")
self.cbRole.addItem("Plotter")
self.cbRole.addItem("Scripter")
self.cbRole.addItem("Translator")
self.cbRole.addItem("Writer")
self.cbRole.addItem("Other")
self.leName.setText(name)
self.cbLanguage.addItem("", "")
for f in natsort.humansorted(utils.languages().items(), operator.itemgetter(1)):
self.cbLanguage.addItem(f[1], f[0])
if role is not None and role != "":
i = self.cbRole.findText(role)
self.leName.setText(credit.person)
if credit.role is not None and credit.role != "":
i = self.cbRole.findText(credit.role)
if i == -1:
self.cbRole.setEditText(role)
self.cbRole.setEditText(credit.role)
else:
self.cbRole.setCurrentIndex(i)
self.cbPrimary.setChecked(primary)
if credit.language != "":
i = self.cbLanguage.findText(credit.language)
if i == -1:
self.cbLanguage.setEditText(credit.language)
else:
self.cbLanguage.setCurrentIndex(i)
self.cbRole.currentIndexChanged.connect(self.role_changed)
self.cbRole.editTextChanged.connect(self.role_changed)
self.cbPrimary.setChecked(credit.primary)
self.update_primary_button()
def update_primary_button(self) -> None:
enabled = self.current_role_can_be_primary()
self.cbPrimary.setEnabled(enabled)
def current_role_can_be_primary(self) -> bool:
role = self.cbRole.currentText()
if role.casefold() in ("artist", "writer"):
return True
return False
def role_changed(self, s: Any) -> None:
self.update_primary_button()
def get_credits(self) -> tuple[str, str, bool]:
def get_credit(self) -> Credit:
primary = self.current_role_can_be_primary() and self.cbPrimary.isChecked()
return self.cbRole.currentText(), self.leName.text(), primary
return Credit(self.leName.text(), self.cbRole.currentText(), primary, self.cbLanguage.currentText())
def accept(self) -> None:
if self.cbRole.currentText() == "" or self.leName.text() == "":
QtWidgets.QMessageBox.warning(self, "Whoops", "You need to enter both role and name for a credit.")
if self.leName.text() == "":
QtWidgets.QMessageBox.warning(self, "Whoops", "You need to enter a name for a credit.")
else:
QtWidgets.QDialog.accept(self)

View File

@ -105,7 +105,7 @@ Accepts the following variables:
{characters} (string)
{teams} (string)
{locations} (string)
{credits} (list of dict({'role': string, 'person': string, 'primary': boolean}))
{credits} (list of dict({'role': string, 'person': string, 'primary': boolean, 'language': str}))
{writer} (string)
{penciller} (string)
{inker} (string)

View File

@ -38,7 +38,7 @@ import comictaggerlib.ui
from comicapi import utils
from comicapi.comicarchive import ComicArchive, tags
from comicapi.filenameparser import FileNameParser
from comicapi.genericmetadata import GenericMetadata
from comicapi.genericmetadata import Credit, GenericMetadata
from comicapi.issuestring import IssueString
from comictaggerlib import ctsettings, ctversion
from comictaggerlib.applicationlogwindow import ApplicationLogWindow, QTextEditLogger
@ -126,7 +126,8 @@ class TaggerWindow(QtWidgets.QMainWindow):
"teams": self.teTeams,
"locations": self.teLocations,
"credits": (self.twCredits, self.btnAddCredit, self.btnEditCredit, self.btnRemoveCredit),
"credits.person": 2,
"credits.person": 3,
"credits.language": 2,
"credits.role": 1,
"credits.primary": 0,
"tags": self.teTags,
@ -874,30 +875,34 @@ class TaggerWindow(QtWidgets.QMainWindow):
if self.is_dupe_credit(credit.role.title(), credit.person):
continue
self.add_new_credit_entry(row, credit.role.title(), credit.person, credit.primary)
self.add_new_credit_entry(row, credit)
self.twCredits.setSortingEnabled(True)
self.update_credit_colors()
def add_new_credit_entry(self, row: int, role: str, name: str, primary_flag: bool = False) -> None:
def add_new_credit_entry(self, row: int, credit: Credit) -> None:
self.twCredits.insertRow(row)
item_text = role
item = QtWidgets.QTableWidgetItem(item_text)
item = QtWidgets.QTableWidgetItem(credit.role)
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled)
item.setData(QtCore.Qt.ItemDataRole.ToolTipRole, item_text)
item.setData(QtCore.Qt.ItemDataRole.ToolTipRole, credit.role)
self.twCredits.setItem(row, 1, item)
item_text = name
item = QtWidgets.QTableWidgetItem(item_text)
item.setData(QtCore.Qt.ItemDataRole.ToolTipRole, item_text)
language = utils.get_language_from_iso(credit.language) or credit.language
item = QtWidgets.QTableWidgetItem(language)
item.setData(QtCore.Qt.ItemDataRole.ToolTipRole, credit.language)
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled)
self.twCredits.setItem(row, 2, item)
item = QtWidgets.QTableWidgetItem(credit.person)
item.setData(QtCore.Qt.ItemDataRole.ToolTipRole, credit.person)
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled)
self.twCredits.setItem(row, 3, item)
item = QtWidgets.QTableWidgetItem("")
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled)
self.twCredits.setItem(row, 0, item)
self.update_credit_primary_flag(row, primary_flag)
self.update_credit_primary_flag(row, credit.primary)
def is_dupe_credit(self, role: str, name: str) -> bool:
for r in range(self.twCredits.rowCount()):
@ -958,10 +963,11 @@ class TaggerWindow(QtWidgets.QMainWindow):
md.credits = []
for row in range(self.twCredits.rowCount()):
role = self.twCredits.item(row, 1).text()
name = self.twCredits.item(row, 2).text()
lang = self.twCredits.item(row, 2).text()
name = self.twCredits.item(row, 3).text()
primary_flag = self.twCredits.item(row, 0).text() != ""
md.add_credit(name, role, bool(primary_flag))
md.add_credit(name, role, bool(primary_flag), lang)
md.pages = self.page_list_editor.get_page_list()
@ -1251,35 +1257,35 @@ class TaggerWindow(QtWidgets.QMainWindow):
self.twCredits.item(row, 0).setText("Yes")
def modify_credits(self, edit: bool) -> None:
row = self.twCredits.rowCount()
old = Credit()
if edit:
row = self.twCredits.currentRow()
role = self.twCredits.item(row, 1).text()
name = self.twCredits.item(row, 2).text()
primary = self.twCredits.item(row, 0).text() != ""
else:
row = self.twCredits.rowCount()
role = ""
name = ""
primary = False
old = Credit(
self.twCredits.item(row, 3).text(),
self.twCredits.item(row, 1).text(),
self.twCredits.item(row, 0).text() != "",
self.twCredits.item(row, 2).text(),
)
editor = CreditEditorWindow(self, CreditEditorWindow.ModeEdit, role, name, primary)
editor = CreditEditorWindow(self, CreditEditorWindow.ModeEdit, old)
editor.setModal(True)
editor.exec()
if editor.result():
new_role, new_name, new_primary = editor.get_credits()
new = editor.get_credit()
if new_name == name and new_role == role and new_primary == primary:
if new == old:
# nothing has changed, just quit
return
# name and role is the same, but primary flag changed
if new_name == name and new_role == role:
self.update_credit_primary_flag(row, new_primary)
if new.person == old.person and new.role == old.role:
self.update_credit_primary_flag(row, new.primary)
return
# check for dupes
ok_to_mod = True
if self.is_dupe_credit(new_role, new_name):
if self.is_dupe_credit(new.role, new.person):
# delete the dupe credit from list
qmsg = QtWidgets.QMessageBox()
qmsg.setText("Duplicate Credit!")
@ -1301,13 +1307,14 @@ class TaggerWindow(QtWidgets.QMainWindow):
if ok_to_mod:
# modify it
if edit:
self.twCredits.item(row, 1).setText(new_role)
self.twCredits.item(row, 2).setText(new_name)
self.update_credit_primary_flag(row, new_primary)
self.twCredits.item(row, 1).setText(new.role)
self.twCredits.item(row, 3).setText(new.person)
self.twCredits.item(row, 2).setText(new.language)
self.update_credit_primary_flag(row, new.primary)
else:
# add new entry
row = self.twCredits.rowCount()
self.add_new_credit_entry(row, new_role, new_name, new_primary)
self.add_new_credit_entry(row, new)
self.update_credit_colors()
self.set_dirty_flag()

View File

@ -97,7 +97,7 @@ tr:nth-child(even) {
<tr><td>{characters}</td><td>string</td></tr>
<tr><td>{teams}</td><td>string</td></tr>
<tr><td>{locations}</td><td>string</td></tr>
<tr><td>{credits}</td><td>list of dict({'role': string, 'person': string, 'primary': boolean})</td></tr>
<tr><td>{credits}</td><td>list of dict({'role': string, 'person': string, 'primary': boolean, 'language': str})</td></tr>
<tr><td>{writer}</td><td>(string)</td></tr>
<tr><td>{penciller}</td><td>(string)</td></tr>
<tr><td>{inker}</td><td>(string)</td></tr>

View File

@ -2,80 +2,80 @@
<ui version="4.0">
<class>dialogCreditEditor</class>
<widget class="QDialog" name="dialogCreditEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>196</height>
</rect>
</property>
<property name="windowTitle">
<string>Modify Credit</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>180</x>
<y>140</y>
<width>191</width>
<height>30</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>341</width>
<height>91</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Role</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbRole">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="cbPrimary">
<property name="text">
<string>Primary</string>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Role</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbRole">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="cbPrimary">
<property name="text">
<string>Primary</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="cbLanguage">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>cbRole</tabstop>
<tabstop>leName</tabstop>
<tabstop>cbLanguage</tabstop>
<tabstop>cbPrimary</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

View File

@ -919,7 +919,7 @@ Source</string>
<number>0</number>
</property>
<property name="columnCount">
<number>3</number>
<number>4</number>
</property>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>2</number>
@ -937,7 +937,12 @@ Source</string>
</column>
<column>
<property name="text">
<string>Credit</string>
<string>Role</string>
</property>
</column>
<column>
<property name="text">
<string>Language</string>
</property>
</column>
<column>