Skip to content

Commit

Permalink
Add new classes from #1388 and some small cleanups too (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j authored Mar 1, 2025
1 parent 76709e9 commit cb11f47
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 61 deletions.
49 changes: 27 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
2 changes: 1 addition & 1 deletion src/tauon/t_modules/t_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/tauon/t_modules/t_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

if TYPE_CHECKING:
from tauon.t_modules.t_main import Tauon

from io import BytesIO

try:
from jxlpy import JXLImagePlugin
Expand Down Expand Up @@ -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())))
Expand Down Expand Up @@ -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)

Expand All @@ -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])
Expand Down
7 changes: 0 additions & 7 deletions src/tauon/t_modules/t_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
131 changes: 113 additions & 18 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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 = ""
Expand Down
9 changes: 5 additions & 4 deletions src/tauon/t_modules/t_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/tauon/t_modules/t_spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/tauon/t_modules/t_themeload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/tauon/theme/Ash.ttheme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cb11f47

Please sign in to comment.