mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-01-28 22:01:24 +00:00
fix: apply unwrap where necessary (#1113)
* fix: apply unwrap where necessary * fix: revert change that caused tests to fail * fix: revert removal of pyright ignore commet * fix: add missing ignore comments
This commit is contained in:
@@ -1854,9 +1854,13 @@ class Library:
|
||||
# load given item from Preferences table
|
||||
with Session(self.engine) as session:
|
||||
if isinstance(key, LibraryPrefs):
|
||||
return session.scalar(select(Preferences).where(Preferences.key == key.name)).value # pyright: ignore
|
||||
return unwrap(
|
||||
session.scalar(select(Preferences).where(Preferences.key == key.name))
|
||||
).value # pyright: ignore[reportUnknownVariableType]
|
||||
else:
|
||||
return session.scalar(select(Preferences).where(Preferences.key == key)).value # pyright: ignore
|
||||
return unwrap(
|
||||
session.scalar(select(Preferences).where(Preferences.key == key))
|
||||
).value # pyright: ignore[reportUnknownVariableType]
|
||||
|
||||
# TODO: Remove this once the 'preferences' table is removed.
|
||||
@deprecated("Use `get_version() for version and `ts_ignore` system for extension exclusion.")
|
||||
|
||||
@@ -5,16 +5,18 @@
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
|
||||
|
||||
def four_corner_gradient(
|
||||
image: Image.Image, size: tuple[int, int], mask: Image.Image | None = None
|
||||
) -> Image.Image:
|
||||
if image.size != size:
|
||||
# Four-Corner Gradient Background.
|
||||
tl = image.getpixel((0, 0))
|
||||
tr = image.getpixel(((image.size[0] - 1), 0))
|
||||
bl = image.getpixel((0, (image.size[1] - 1)))
|
||||
br = image.getpixel(((image.size[0] - 1), (image.size[1] - 1)))
|
||||
tl = unwrap(image.getpixel((0, 0)))
|
||||
tr = unwrap(image.getpixel(((image.size[0] - 1), 0)))
|
||||
bl = unwrap(image.getpixel((0, (image.size[1] - 1))))
|
||||
br = unwrap(image.getpixel(((image.size[0] - 1), (image.size[1] - 1))))
|
||||
bg = Image.new(mode="RGB", size=(2, 2))
|
||||
bg.paste(tl, (0, 0, 2, 2))
|
||||
bg.paste(tr, (1, 0, 2, 2))
|
||||
|
||||
@@ -23,6 +23,7 @@ from PySide6.QtWidgets import (
|
||||
from tagstudio.core.library.alchemy.enums import TagColorEnum
|
||||
from tagstudio.core.library.alchemy.library import Library, slugify
|
||||
from tagstudio.core.library.alchemy.models import TagColorGroup
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.mixed.tag_color_preview import TagColorPreview
|
||||
from tagstudio.qt.mixed.tag_widget import (
|
||||
get_border_color,
|
||||
@@ -126,8 +127,8 @@ class BuildColorPanel(PanelWidget):
|
||||
self.border_checkbox.setFixedSize(22, 22)
|
||||
self.border_checkbox.clicked.connect(
|
||||
lambda checked: self.update_secondary(
|
||||
color=QColor(self.preview_button.tag_color_group.secondary)
|
||||
if self.preview_button.tag_color_group.secondary
|
||||
color=QColor(unwrap(self.preview_button.tag_color_group).secondary)
|
||||
if unwrap(self.preview_button.tag_color_group).secondary
|
||||
else None,
|
||||
color_border=checked,
|
||||
)
|
||||
|
||||
@@ -28,6 +28,7 @@ from PySide6.QtWidgets import (
|
||||
from tagstudio.core.library.alchemy.enums import TagColorEnum
|
||||
from tagstudio.core.library.alchemy.library import Library
|
||||
from tagstudio.core.library.alchemy.models import Tag, TagColorGroup
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.mixed.tag_color_preview import TagColorPreview
|
||||
from tagstudio.qt.mixed.tag_color_selection import TagColorSelection
|
||||
from tagstudio.qt.mixed.tag_search import TagSearchModal, TagSearchPanel
|
||||
@@ -181,6 +182,7 @@ class BuildTagPanel(PanelWidget):
|
||||
self.color_layout.addWidget(self.color_title)
|
||||
self.color_button: TagColorPreview
|
||||
try:
|
||||
assert tag is not None
|
||||
self.color_button = TagColorPreview(self.lib, tag.color)
|
||||
except Exception as e:
|
||||
# TODO: Investigate why this happens during tests
|
||||
@@ -316,7 +318,7 @@ class BuildTagPanel(PanelWidget):
|
||||
item = self.aliases_table.cellWidget(row, 1)
|
||||
item.setFocus()
|
||||
|
||||
def remove_alias_callback(self, alias_name: str, alias_id: int | None = None):
|
||||
def remove_alias_callback(self, alias_name: str, alias_id: int):
|
||||
logger.info("remove_alias_callback")
|
||||
|
||||
self.alias_ids.remove(alias_id)
|
||||
@@ -468,7 +470,7 @@ class BuildTagPanel(PanelWidget):
|
||||
|
||||
def _update_new_alias_name_dict(self):
|
||||
for i in range(0, self.aliases_table.rowCount()):
|
||||
widget = self.aliases_table.cellWidget(i, 1)
|
||||
widget = cast(CustomTableItem, self.aliases_table.cellWidget(i, 1))
|
||||
self.new_alias_names[widget.id] = widget.text()
|
||||
|
||||
def _set_aliases(self):
|
||||
@@ -574,8 +576,8 @@ class BuildTagPanel(PanelWidget):
|
||||
self.setTabOrder(self.shorthand_field, self.aliases_add_button)
|
||||
self.setTabOrder(self.aliases_add_button, self.parent_tags_add_button)
|
||||
self.setTabOrder(self.parent_tags_add_button, self.color_button)
|
||||
self.setTabOrder(self.color_button, self.panel_cancel_button)
|
||||
self.setTabOrder(self.panel_cancel_button, self.panel_save_button)
|
||||
self.setTabOrder(self.panel_save_button, self.aliases_table.cellWidget(0, 1))
|
||||
self.setTabOrder(self.color_button, unwrap(self.panel_cancel_button))
|
||||
self.setTabOrder(unwrap(self.panel_cancel_button), unwrap(self.panel_save_button))
|
||||
self.setTabOrder(unwrap(self.panel_save_button), self.aliases_table.cellWidget(0, 1))
|
||||
self.name_field.selectAll()
|
||||
self.name_field.setFocus()
|
||||
|
||||
@@ -13,6 +13,7 @@ from PySide6.QtWidgets import QMessageBox, QPushButton
|
||||
from tagstudio.core.constants import RESERVED_NAMESPACE_PREFIX
|
||||
from tagstudio.core.library.alchemy.enums import TagColorEnum
|
||||
from tagstudio.core.library.alchemy.models import TagColorGroup
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.mixed.build_color import BuildColorPanel
|
||||
from tagstudio.qt.mixed.field_widget import FieldWidget
|
||||
from tagstudio.qt.mixed.tag_color_label import TagColorLabel
|
||||
@@ -88,7 +89,7 @@ class ColorBoxWidget(FieldWidget):
|
||||
color_widgets: list[TagColorLabel] = []
|
||||
|
||||
while self.base_layout.itemAt(0):
|
||||
self.base_layout.takeAt(0).widget().deleteLater()
|
||||
unwrap(self.base_layout.takeAt(0)).widget().deleteLater()
|
||||
|
||||
for color in colors_:
|
||||
color_widget = TagColorLabel(
|
||||
|
||||
@@ -21,6 +21,7 @@ from PySide6.QtWidgets import (
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.mixed.progress_bar import ProgressWidget
|
||||
from tagstudio.qt.translations import Translations
|
||||
|
||||
@@ -120,7 +121,9 @@ class DropImportModal(QWidget):
|
||||
continue
|
||||
|
||||
self.files.append(f)
|
||||
if (self.driver.lib.library_dir / self._get_relative_path(file)).exists():
|
||||
if (
|
||||
unwrap(self.driver.lib.library_dir) / self._get_relative_path(file)
|
||||
).exists():
|
||||
self.duplicate_files.append(f)
|
||||
|
||||
self.dirs_in_root.append(file.parent)
|
||||
@@ -132,7 +135,7 @@ class DropImportModal(QWidget):
|
||||
file.parent
|
||||
) # to create relative path of files not in folder
|
||||
|
||||
if (Path(self.driver.lib.library_dir) / file.name).exists():
|
||||
if (Path(unwrap(self.driver.lib.library_dir)) / file.name).exists():
|
||||
self.duplicate_files.append(file)
|
||||
|
||||
def ask_duplicates_choice(self):
|
||||
@@ -205,8 +208,10 @@ class DropImportModal(QWidget):
|
||||
new_name = self._get_renamed_duplicate_filename(dest_file)
|
||||
dest_file = dest_file.with_name(new_name)
|
||||
|
||||
(self.driver.lib.library_dir / dest_file).parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(file, self.driver.lib.library_dir / dest_file)
|
||||
(unwrap(self.driver.lib.library_dir) / dest_file).parent.mkdir(
|
||||
parents=True, exist_ok=True
|
||||
)
|
||||
shutil.copyfile(file, unwrap(self.driver.lib.library_dir) / dest_file)
|
||||
|
||||
file_count += 1
|
||||
yield [file_count, duplicated_files_progress]
|
||||
@@ -226,7 +231,7 @@ class DropImportModal(QWidget):
|
||||
except ValueError:
|
||||
dot_idx = len(o_filename)
|
||||
|
||||
while (self.driver.lib.library_dir / filepath).exists():
|
||||
while (unwrap(self.driver.lib.library_dir) / filepath).exists():
|
||||
filepath = filepath.with_name(
|
||||
o_filename[:dot_idx] + f" ({index})" + o_filename[dot_idx:]
|
||||
)
|
||||
|
||||
@@ -37,6 +37,7 @@ from tagstudio.core.library.alchemy.library import Library as SqliteLibrary
|
||||
from tagstudio.core.library.alchemy.models import Entry, TagAlias
|
||||
from tagstudio.core.library.json.library import Library as JsonLibrary
|
||||
from tagstudio.core.library.json.library import Tag as JsonTag
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.controllers.paged_panel_controller import PagedPanel
|
||||
from tagstudio.qt.controllers.paged_panel_state import PagedPanelState
|
||||
from tagstudio.qt.translations import Translations
|
||||
@@ -561,7 +562,7 @@ class JsonMigrationModal(QObject):
|
||||
sql_fields: list[tuple] = []
|
||||
json_fields: list[tuple] = []
|
||||
|
||||
sql_entry: Entry = self.sql_lib.get_entry_full(json_entry.id + 1)
|
||||
sql_entry: Entry = unwrap(self.sql_lib.get_entry_full(json_entry.id + 1))
|
||||
if not sql_entry:
|
||||
logger.info(
|
||||
"[Field Comparison]",
|
||||
@@ -595,7 +596,7 @@ class JsonMigrationModal(QObject):
|
||||
tags_count += 1
|
||||
json_tags = json_tags.union(value or [])
|
||||
else:
|
||||
key: str = self.sql_lib.get_field_name_from_id(int_key).name
|
||||
key: str = unwrap(self.sql_lib.get_field_name_from_id(int_key)).name
|
||||
json_fields.append((json_entry.id + 1, key, value))
|
||||
json_fields.sort()
|
||||
|
||||
@@ -710,8 +711,6 @@ class JsonMigrationModal(QObject):
|
||||
|
||||
def check_name_parity(self) -> bool:
|
||||
"""Check if all JSON tag names match the new SQL tag names."""
|
||||
sql_name: str = None
|
||||
json_name: str = None
|
||||
|
||||
def sanitize(value):
|
||||
"""Return value or convert a "not" value into None."""
|
||||
@@ -719,8 +718,8 @@ class JsonMigrationModal(QObject):
|
||||
|
||||
for tag in self.sql_lib.tags:
|
||||
tag_id = tag.id # Tag IDs start at 0
|
||||
sql_name = sanitize(tag.name)
|
||||
json_name = sanitize(self.json_lib.get_tag(tag_id).name)
|
||||
sql_name: str = unwrap(sanitize(tag.name))
|
||||
json_name: str = unwrap(sanitize(self.json_lib.get_tag(tag_id).name))
|
||||
|
||||
logger.info(
|
||||
"[Name Parity]",
|
||||
@@ -742,8 +741,6 @@ class JsonMigrationModal(QObject):
|
||||
|
||||
def check_shorthand_parity(self) -> bool:
|
||||
"""Check if all JSON shorthands match the new SQL shorthands."""
|
||||
sql_shorthand: str = None
|
||||
json_shorthand: str = None
|
||||
|
||||
def sanitize(value):
|
||||
"""Return value or convert a "not" value into None."""
|
||||
|
||||
@@ -664,7 +664,7 @@ class ThumbRenderer(QObject):
|
||||
artwork = Image.open(BytesIO(flac_covers[0].data))
|
||||
elif ext in [".mp4", ".m4a", ".aac"]:
|
||||
mp4_tags: mp4.MP4 = mp4.MP4(filepath)
|
||||
mp4_covers: list = mp4_tags.get("covr")
|
||||
mp4_covers: list = unwrap(mp4_tags.get("covr"))
|
||||
if mp4_covers:
|
||||
artwork = Image.open(BytesIO(mp4_covers[0]))
|
||||
if artwork:
|
||||
@@ -1126,7 +1126,7 @@ class ThumbRenderer(QObject):
|
||||
new_bg = Image.new("RGB", im.size, color="#1e1e1e")
|
||||
new_bg.paste(im, mask=im.getchannel(3))
|
||||
im = new_bg
|
||||
im = ImageOps.exif_transpose(im)
|
||||
im = unwrap(ImageOps.exif_transpose(im))
|
||||
except (
|
||||
FileNotFoundError,
|
||||
UnidentifiedImageError,
|
||||
|
||||
Reference in New Issue
Block a user