From cb11f4732ccef49bcc479055f0568ec0cc2fc7a6 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 1 Mar 2025 21:04:46 +0100 Subject: [PATCH] Add new classes from #1388 and some small cleanups too (#1460) --- pyproject.toml | 49 ++++++----- src/tauon/t_modules/t_bootstrap.py | 2 +- src/tauon/t_modules/t_draw.py | 7 +- src/tauon/t_modules/t_extra.py | 7 -- src/tauon/t_modules/t_main.py | 131 +++++++++++++++++++++++++---- src/tauon/t_modules/t_prefs.py | 9 +- src/tauon/t_modules/t_spot.py | 2 - src/tauon/t_modules/t_themeload.py | 1 - src/tauon/theme/Ash.ttheme | 2 +- 9 files changed, 149 insertions(+), 61 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8c85dc693..f10ca3ed2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -186,26 +186,31 @@ [tool.ruff.lint] select = ['ALL'] ignore = [ - 'Q003', # avoidable-escaped-quote - It's not that important, we just use escapes, keeping the quotes consistent - 'W191', # tab-indentation - We use tabs for indents, disabling this PEP 8 recommendation - 'D206', # indent-with-spaces - ^ - 'D100', # undocumented-public-module - TODO(Martin): We currently don't even have typing fully implemented, let's maybe care about undocumented functions/classes later - 'D101', # undocumented-public-class - ^ - 'D102', # public-method - ^ - 'D103', # undocumented-public-function - ^ - 'D104', # undocumented-public-package - ^ -# 'D105', # undocumented-magic-method - ^ < This one is a bit more severe though - 'D106', # undocumented-public-nested-class - ^ - 'D107', # undocumented-public-init - ^ - 'D400', # ends-in-period - We do not care if docstrings end with a period - 'D415', # ends-in-punctuation - ^ - 'D401', # non-imperative-mood - Wants docstrings in imperative language but it's really not foolproof, disable - 'EM101', # raw-string-in-exception - We do not care about .format in exceptions, readability is not *our* problem, traceback should be colorized to avoid this instead - 'EM102', # f-string-in-exception - ^ - 'EM103', # dot-format-in-exception - ^ - 'ERA001', # commented-out-code - Tests for commented out code, but it has way too many false positives, so disable - 'FBT001', # boolean-type-hint-positional-argument - Allow positional booleans in functions, it's not really that much of an issue - 'FBT002', # boolean-default-value-positional-argument - ^ - 'FBT003', # boolean-positional-value-in-call - ^ - 'TD003', # missing-todo-link - We're fine not linking existing issues in TODOs, it's fine to have them noted in code only + 'Q003', # avoidable-escaped-quote - It's not that important, we just use escapes, keeping the quotes consistent + 'W191', # tab-indentation - We use tabs for indents, disabling this PEP 8 recommendation + 'D206', # indent-with-spaces - ^ + 'D100', # undocumented-public-module - TODO(Martin): We currently don't even have typing fully implemented, let's maybe care about undocumented functions/classes later + 'D101', # undocumented-public-class - ^ + 'D102', # public-method - ^ + 'D103', # undocumented-public-function - ^ + 'D104', # undocumented-public-package - ^ +# 'D105', # undocumented-magic-method - ^ < This one is a bit more severe though + 'D106', # undocumented-public-nested-class - ^ + 'D107', # undocumented-public-init - ^ + 'D400', # ends-in-period - We do not care if docstrings end with a period + 'D415', # ends-in-punctuation - ^ + 'D401', # non-imperative-mood - Wants docstrings in imperative language but it's really not foolproof, disable + 'EM101', # raw-string-in-exception - We do not care about .format in exceptions, readability is not *our* problem, traceback should be colorized to avoid this instead + 'EM102', # f-string-in-exception - ^ + 'EM103', # dot-format-in-exception - ^ + 'ERA001', # commented-out-code - Tests for commented out code, but it has way too many false positives, so disable + 'FBT001', # boolean-type-hint-positional-argument - Allow positional booleans in functions, it's not really that much of an issue + 'FBT002', # boolean-default-value-positional-argument - ^ + 'FBT003', # boolean-positional-value-in-call - ^ + 'TD003', # missing-todo-link - We're fine not linking existing issues in TODOs, it's fine to have them noted in code only + 'C901', # complex-structure - We'll ignore functions being too complex for now + 'PLR0911', # too-many-return-statements - We'll ignore functions having too many return statements + 'PLR0912', # too-many-branches - We'll ignore functions having too many branches for now + 'PLR0913', # too-many-arguments - We'll ignore functions taking too many arguments + 'PLR0915', # too-many-statements - We'll ignore functions having too many statements ] diff --git a/src/tauon/t_modules/t_bootstrap.py b/src/tauon/t_modules/t_bootstrap.py index c4892c886..994be5ac9 100644 --- a/src/tauon/t_modules/t_bootstrap.py +++ b/src/tauon/t_modules/t_bootstrap.py @@ -24,7 +24,7 @@ class Holder: window_opacity: float draw_border: bool transfer_args_and_exit: Callable[[]] # transfer_args_and_exit() - TODO(Martin): This should probably be moved to extra module - old_window_position: tuple [int, int] | None # X Y res + old_window_position: tuple[int, int] | None # X Y res install_directory: Path user_directory: Path pyinstaller_mode: bool diff --git a/src/tauon/t_modules/t_draw.py b/src/tauon/t_modules/t_draw.py index cfff4ada8..e64996560 100644 --- a/src/tauon/t_modules/t_draw.py +++ b/src/tauon/t_modules/t_draw.py @@ -33,7 +33,7 @@ if TYPE_CHECKING: from tauon.t_modules.t_main import Tauon - + from io import BytesIO try: from jxlpy import JXLImagePlugin @@ -340,7 +340,7 @@ def __init__(self, renderer: sdl3.SDL_Renderer | None = None) -> None: self.was_truncated = False - def load_image(self, g: io.BinaryIO) -> sdl3.SDL_Surface: + def load_image(self, g: BytesIO) -> sdl3.LP_SDL_Surface: size = g.getbuffer().nbytes pointer = ctypes.c_void_p(ctypes.addressof(ctypes.c_char.from_buffer(g.getbuffer()))) @@ -401,9 +401,7 @@ def rect_si(self, rectangle: tuple[int, int, int, int], colour: tuple[int, int, def rect_a(self, location_xy: list[int], size_wh: list[int], colour: tuple[int, int, int, int]) -> None: self.rect((location_xy[0], location_xy[1], size_wh[0], size_wh[1]), colour) - def clear_rect(self, rectangle: tuple[int, int, int, int]) -> None: - sdl3.SDL_SetRenderDrawBlendMode(self.renderer, sdl3.SDL_BLENDMODE_NONE) sdl3.SDL_SetRenderDrawColor(self.renderer, 0, 0, 0, 0) @@ -416,7 +414,6 @@ def clear_rect(self, rectangle: tuple[int, int, int, int]) -> None: sdl3.SDL_SetRenderDrawBlendMode(self.renderer, sdl3.SDL_BLENDMODE_BLEND) def rect(self, rectangle: tuple[int, int, int, int], colour: tuple[int, int, int, int]) -> None: - sdl3.SDL_SetRenderDrawColor(self.renderer, colour[0], colour[1], colour[2], colour[3]) self.sdlrect.x = float(rectangle[0]) diff --git a/src/tauon/t_modules/t_extra.py b/src/tauon/t_modules/t_extra.py index 3b4037cf5..caf3ca14c 100644 --- a/src/tauon/t_modules/t_extra.py +++ b/src/tauon/t_modules/t_extra.py @@ -921,26 +921,20 @@ def fader_timer(time_point: float, start: float, duration: float, off: bool = Tr 192: "Unknown", } - class FunctionStore: """Stores functions and arguments for calling later""" def __init__(self) -> None: - self.items = [] def store(self, function: Callable[..., None], args: tuple = ()) -> None: - self.items.append((function, args)) def recall_all(self) -> None: - while self.items: item = self.items.pop() item[0](*item[1]) - - def grow_rect(rect: tuple[int, int, int, int], px: int) -> tuple[int, int, int, int]: return rect[0] - px, rect[1] - px, rect[2] + px * 2, rect[3] + px * 2 @@ -981,7 +975,6 @@ def subtract_rect( genre_corrections2 = [x.lower().replace("-", "").replace(" ", "") for x in genre_corrections] def genre_correct(text: str) -> str: - parsed = text.lower().replace("-", "").replace(" ", "").strip() if parsed.startswith("post"): return ("Post-" + parsed[4:]).title() diff --git a/src/tauon/t_modules/t_main.py b/src/tauon/t_modules/t_main.py index 8db67cd39..14328ed10 100644 --- a/src/tauon/t_modules/t_main.py +++ b/src/tauon/t_modules/t_main.py @@ -23196,6 +23196,107 @@ class XcursorImage(ctypes.Structure): ("pixels", c_void_p), ] +@dataclass +class Directories: + """Hold directories""" + install_directory: Path + svg_directory: Path + asset_directory: Path + scaled_asset_directory: Path + locale_directory: Path + user_directory: Path + config_directory: Path + cache_directory: Path + home_directory: Path + music_directory: Path + download_directory: Path + n_cache_directory: Path + e_cache_directory: Path + g_cache_directory: Path + a_cache_directory: Path + r_cache_directory: Path + b_cache_directory: Path + +@dataclass +class Bag: + """Holder object for all configs""" + mpt: CDLL | None + gme: CDLL | None + cf: Config + colours: ColoursClass + console: DConsole + dirs: Directories + prefs: Prefs + formats: Formats + renderer: sdl3.LP_SDL_Renderer + overlay_texture_texture: sdl3.LP_SDL_Texture + fonts: Fonts + tls_context: ssl.SSLContext + macos: bool + msys: bool + phone: bool + pump: bool + snap_mode: bool + flatpak_mode: bool + smtc: bool + draw_min_button: bool + draw_max_button: bool + last_fm_enable: bool + de_notify_support: bool + wayland: bool + use_natsort: bool + should_save_state: bool + desktop: str | None + system: str + launch_prefix: str + platform_system: str + album_mode_art_size: int + xdpi: int + master_count: int + playing_in_queue: int + playlist_active: int + playlist_playing: int + playlist_view_position: int + radio_playlist_viewing: int + selected_in_playlist: int + latest_db_version: int + volume: float + mac_close: tuple[int, int, int, int] + mac_maximize: tuple[int, int, int, int] + mac_minimize: tuple[int, int, int, int] + track_queue: list[int] + logical_size: list[int] # X Y + window_size: list[int] # X Y + old_window_position: tuple[int, int] # X Y res + cue_list: list[str] + download_directories: list[str] + load_orders: list[LoadClass] + multi_playlist: list[TauonPlaylist] + radio_playlists: list[RadioPlaylist] + primary_stations: list[RadioStation] + p_force_queue: list[TauonQueueItem] + folder_image_offsets: dict[str, int] + gen_codes: dict[int, str] + master_library: dict[int, TrackClass] + loaded_asset_dc: dict[str, WhiteModImageAsset | LoadImageAsset] + sm: CDLL | None = None + song_notification: None = None + +@dataclass +class Formats: + """Contains: + + * Colours used for the label icon in UI 'track info box' + * Extensions of files to be added when importing + """ + + colours: dict[str, tuple[int, int, int, int]] + VID: set[str] + MOD: set[str] + GME: set[str] + DA: set[str] + Archive: set[str] + def get_cert_path() -> str: if pyinstaller_mode: return os.path.join(sys._MEIPASS, "certifi", "cacert.pem") @@ -39359,22 +39460,28 @@ def drop_file(target: str): if macos or phone: power_save = True +# This is legacy. New settings are added straight to the save list (need to overhaul) +view_prefs = { + "split-line": True, + "update-title": False, + "star-lines": False, + "side-panel": True, + "dim-art": False, + "pl-follow": False, + "scroll-enable": True, +} + prefs = Prefs( + view_prefs=view_prefs, power_save=power_save, encoder_output=encoder_output, -# user_directory=user_directory, -# music_directory=music_directory, -# cache_directory=cache_directory, force_subpixel_text=force_subpixel_text, dc_device=dc_device, macos=macos, -# detect_macstyle=detect_macstyle, macstyle=macos or detect_macstyle, left_window_control=macos or left_window_control, phone=phone, -# gtk_settings=gtk_settings, discord_allow=discord_allow, - flatpak_mode=flatpak_mode, desktop=desktop, window_opacity=window_opacity, ui_scale=scale, @@ -39391,18 +39498,6 @@ def drop_file(target: str): colours = ColoursClass() colours.post_config() - -# This is legacy. New settings are added straight to the save list (need to overhaul) -view_prefs = { - "split-line": True, - "update-title": False, - "star-lines": False, - "side-panel": True, - "dim-art": False, - "pl-follow": False, - "scroll-enable": True, -} - # url_saves = [] rename_files_previous = "" rename_folder_previous = "" diff --git a/src/tauon/t_modules/t_prefs.py b/src/tauon/t_modules/t_prefs.py index 5f4c2d92a..fc00c4307 100644 --- a/src/tauon/t_modules/t_prefs.py +++ b/src/tauon/t_modules/t_prefs.py @@ -10,14 +10,11 @@ class Prefs: """Used to hold any kind of settings""" -# music_directory: Path | None + view_prefs: dict[str, bool] encoder_output: Path -# user_directory: Path -# cache_directory: Path window_opacity: float ui_scale: float power_save: bool - flatpak_mode: bool discord_allow: bool left_window_control: bool macstyle: bool @@ -50,6 +47,10 @@ class Prefs: prefer_bottom_title: bool = True append_date: bool = True + update_title: bool = False + scroll_enable: bool = True + break_enable: bool = True + transcode_codec: str = "opus" transcode_mode: str = "single" transcode_bitrate: int = 64 diff --git a/src/tauon/t_modules/t_spot.py b/src/tauon/t_modules/t_spot.py index c345473b7..0c1f7f336 100644 --- a/src/tauon/t_modules/t_spot.py +++ b/src/tauon/t_modules/t_spot.py @@ -367,9 +367,7 @@ def search(self, text: str) -> list[TrackClass] | None: self.tauon.quickthumbnail.queue.clear() if results[0]: - for i, album in enumerate(results[0].items[1:]): - img = QuickThumbnail(self.tauon) img.url = album.images[-1].url img.size = round(50 * self.tauon.gui.scale) diff --git a/src/tauon/t_modules/t_themeload.py b/src/tauon/t_modules/t_themeload.py index b47098120..0030b54e0 100644 --- a/src/tauon/t_modules/t_themeload.py +++ b/src/tauon/t_modules/t_themeload.py @@ -27,7 +27,6 @@ from typing import TYPE_CHECKING from PIL import Image -from sdl3 import SDL_RenderTexture from tauon.t_modules.t_extra import rgb_add_hls, test_lumi diff --git a/src/tauon/theme/Ash.ttheme b/src/tauon/theme/Ash.ttheme index 582dfeea1..a6ec2d58f 100644 --- a/src/tauon/theme/Ash.ttheme +++ b/src/tauon/theme/Ash.ttheme @@ -35,7 +35,7 @@ 100,100,100 fav line 40,40,41 folder line -158,158,159 folder title +158,158,159 folder title 255,255,255,9 playing highlight 255,255,255,11 select highlight