Fix Char limit
This commit is contained in:
1 parent
88e6f641c2
commit
700eea586e
1 file changed
+31
-46
@@ -5,7 +5,6 @@ import urllib.parse
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from typing import List
|
from typing import List
|
||||||
import threading
|
import threading
|
||||||
import weakref
|
|
||||||
|
|
||||||
from fabric.utils import (
|
from fabric.utils import (
|
||||||
bulk_connect,
|
bulk_connect,
|
||||||
@@ -122,7 +121,7 @@ class PlayerBoxStack(Box):
|
|||||||
|
|
||||||
# Clean up player boxes
|
# Clean up player boxes
|
||||||
for child in self.player_stack.get_children():
|
for child in self.player_stack.get_children():
|
||||||
if hasattr(child, 'destroy') and child != self.no_media_box:
|
if hasattr(child, "destroy") and child != self.no_media_box:
|
||||||
try:
|
try:
|
||||||
child.destroy()
|
child.destroy()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -146,7 +145,7 @@ class PlayerBoxStack(Box):
|
|||||||
label="No media playing",
|
label="No media playing",
|
||||||
name="player-title-c",
|
name="player-title-c",
|
||||||
justification="left",
|
justification="left",
|
||||||
max_chars_width=15,
|
max_chars_width=25,
|
||||||
ellipsization="end",
|
ellipsization="end",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
)
|
)
|
||||||
@@ -161,23 +160,13 @@ class PlayerBoxStack(Box):
|
|||||||
visible=False, # Hide artist and album when no media
|
visible=False, # Hide artist and album when no media
|
||||||
)
|
)
|
||||||
|
|
||||||
track_album = Label(
|
|
||||||
label="",
|
|
||||||
name="player-album",
|
|
||||||
justification="left",
|
|
||||||
max_chars_width=15,
|
|
||||||
ellipsization="end",
|
|
||||||
h_align="start",
|
|
||||||
visible=False, # Hide artist and album when no media
|
|
||||||
)
|
|
||||||
|
|
||||||
track_info = Box(
|
track_info = Box(
|
||||||
name="track-info",
|
name="track-info",
|
||||||
# spacing=5,
|
# spacing=5,
|
||||||
orientation="v",
|
orientation="v",
|
||||||
v_align="start",
|
v_align="start",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
children=[track_title, track_artist, track_album],
|
children=[track_title, track_artist],
|
||||||
)
|
)
|
||||||
|
|
||||||
# No control buttons for no media state - just an empty box
|
# No control buttons for no media state - just an empty box
|
||||||
@@ -277,7 +266,9 @@ class PlayerBoxStack(Box):
|
|||||||
|
|
||||||
# set new active button
|
# set new active button
|
||||||
if self.player_buttons and self.current_stack_pos < len(self.player_buttons):
|
if self.player_buttons and self.current_stack_pos < len(self.player_buttons):
|
||||||
print(f"[PlayerBoxStack] Switching to player at index {self.current_stack_pos}")
|
print(
|
||||||
|
f"[PlayerBoxStack] Switching to player at index {self.current_stack_pos}"
|
||||||
|
)
|
||||||
self.player_buttons[self.current_stack_pos].add_style_class("active")
|
self.player_buttons[self.current_stack_pos].add_style_class("active")
|
||||||
self.player_stack.set_visible_child(
|
self.player_stack.set_visible_child(
|
||||||
self.player_stack.get_children()[self.current_stack_pos],
|
self.player_stack.get_children()[self.current_stack_pos],
|
||||||
@@ -287,12 +278,16 @@ class PlayerBoxStack(Box):
|
|||||||
"""Switch to player at given index"""
|
"""Switch to player at given index"""
|
||||||
if 0 <= index < len(self.player_buttons):
|
if 0 <= index < len(self.player_buttons):
|
||||||
# unset active from prev active button
|
# unset active from prev active button
|
||||||
if self.player_buttons and self.current_stack_pos < len(self.player_buttons):
|
if self.player_buttons and self.current_stack_pos < len(
|
||||||
|
self.player_buttons
|
||||||
|
):
|
||||||
self.player_buttons[self.current_stack_pos].remove_style_class("active")
|
self.player_buttons[self.current_stack_pos].remove_style_class("active")
|
||||||
# set new position
|
# set new position
|
||||||
self.current_stack_pos = index
|
self.current_stack_pos = index
|
||||||
# set new active button
|
# set new active button
|
||||||
if self.player_buttons and self.current_stack_pos < len(self.player_buttons):
|
if self.player_buttons and self.current_stack_pos < len(
|
||||||
|
self.player_buttons
|
||||||
|
):
|
||||||
self.player_buttons[self.current_stack_pos].add_style_class("active")
|
self.player_buttons[self.current_stack_pos].add_style_class("active")
|
||||||
self.player_stack.set_visible_child(
|
self.player_stack.set_visible_child(
|
||||||
self.player_stack.get_children()[self.current_stack_pos],
|
self.player_stack.get_children()[self.current_stack_pos],
|
||||||
@@ -347,7 +342,10 @@ class PlayerBoxStack(Box):
|
|||||||
# Find and properly destroy the player box
|
# Find and properly destroy the player box
|
||||||
player_box_to_remove = None
|
player_box_to_remove = None
|
||||||
for player_box in players:
|
for player_box in players:
|
||||||
if hasattr(player_box, 'player') and player_box.player.player_name == player_name:
|
if (
|
||||||
|
hasattr(player_box, "player")
|
||||||
|
and player_box.player.player_name == player_name
|
||||||
|
):
|
||||||
player_box_to_remove = player_box
|
player_box_to_remove = player_box
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -358,7 +356,9 @@ class PlayerBoxStack(Box):
|
|||||||
logger.warning(f"Failed to destroy player box: {e}")
|
logger.warning(f"Failed to destroy player box: {e}")
|
||||||
|
|
||||||
# Check if this was the last player
|
# Check if this was the last player
|
||||||
remaining_players = [p for p in self.player_stack.get_children() if p != player_box_to_remove]
|
remaining_players = [
|
||||||
|
p for p in self.player_stack.get_children() if p != player_box_to_remove
|
||||||
|
]
|
||||||
if len(remaining_players) == 0:
|
if len(remaining_players) == 0:
|
||||||
# Show the no media box instead of hiding
|
# Show the no media box instead of hiding
|
||||||
self.player_stack.children = [self.no_media_box]
|
self.player_stack.children = [self.no_media_box]
|
||||||
@@ -388,7 +388,9 @@ class PlayerBoxStack(Box):
|
|||||||
new_button = Button(name="player-stack-button")
|
new_button = Button(name="player-stack-button")
|
||||||
|
|
||||||
def on_player_button_click(button: Button):
|
def on_player_button_click(button: Button):
|
||||||
if self.player_buttons and self.current_stack_pos < len(self.player_buttons):
|
if self.player_buttons and self.current_stack_pos < len(
|
||||||
|
self.player_buttons
|
||||||
|
):
|
||||||
self.player_buttons[self.current_stack_pos].remove_style_class("active")
|
self.player_buttons[self.current_stack_pos].remove_style_class("active")
|
||||||
if button in self.player_buttons:
|
if button in self.player_buttons:
|
||||||
self.current_stack_pos = self.player_buttons.index(button)
|
self.current_stack_pos = self.player_buttons.index(button)
|
||||||
@@ -497,7 +499,7 @@ class PlayerBox(Box):
|
|||||||
label="No Title",
|
label="No Title",
|
||||||
name="player-title-c",
|
name="player-title-c",
|
||||||
justification="left",
|
justification="left",
|
||||||
max_chars_width=15,
|
max_chars_width=25,
|
||||||
ellipsization="end",
|
ellipsization="end",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
)
|
)
|
||||||
@@ -506,17 +508,7 @@ class PlayerBox(Box):
|
|||||||
label="No Artist",
|
label="No Artist",
|
||||||
name="player-artist-c",
|
name="player-artist-c",
|
||||||
justification="left",
|
justification="left",
|
||||||
max_chars_width=15,
|
max_chars_width=23,
|
||||||
ellipsization="end",
|
|
||||||
h_align="start",
|
|
||||||
visible=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.track_album = Label(
|
|
||||||
label="No Album",
|
|
||||||
name="player-album",
|
|
||||||
justification="left",
|
|
||||||
max_chars_width=15,
|
|
||||||
ellipsization="end",
|
ellipsization="end",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
visible=True,
|
visible=True,
|
||||||
@@ -541,16 +533,6 @@ class PlayerBox(Box):
|
|||||||
), # type: ignore
|
), # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
self.player.bind_property(
|
|
||||||
"album",
|
|
||||||
self.track_album,
|
|
||||||
"label",
|
|
||||||
GObject.BindingFlags.DEFAULT,
|
|
||||||
lambda _, x: (
|
|
||||||
re.sub(r"\r?\n", " ", x) if x != "" and x is not None else "No Album"
|
|
||||||
), # type: ignore
|
|
||||||
)
|
|
||||||
|
|
||||||
self.track_info = Box(
|
self.track_info = Box(
|
||||||
name="track-info",
|
name="track-info",
|
||||||
spacing=5,
|
spacing=5,
|
||||||
@@ -560,7 +542,6 @@ class PlayerBox(Box):
|
|||||||
children=[
|
children=[
|
||||||
self.track_title,
|
self.track_title,
|
||||||
self.track_artist,
|
self.track_artist,
|
||||||
# self.track_album,
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -693,7 +674,9 @@ class PlayerBox(Box):
|
|||||||
"""Handle outer box click with proper error handling."""
|
"""Handle outer box click with proper error handling."""
|
||||||
try:
|
try:
|
||||||
# Close control center if it exists
|
# Close control center if it exists
|
||||||
if self.control_center and hasattr(self.control_center, "hide_controlcenter"):
|
if self.control_center and hasattr(
|
||||||
|
self.control_center, "hide_controlcenter"
|
||||||
|
):
|
||||||
self.control_center.hide_controlcenter()
|
self.control_center.hide_controlcenter()
|
||||||
|
|
||||||
# Open expanded player if available
|
# Open expanded player if available
|
||||||
@@ -743,7 +726,9 @@ class PlayerBox(Box):
|
|||||||
"""Handle prev button click: close control center then open expanded player"""
|
"""Handle prev button click: close control center then open expanded player"""
|
||||||
try:
|
try:
|
||||||
# Close control center first
|
# Close control center first
|
||||||
if self.control_center and hasattr(self.control_center, "hide_controlcenter"):
|
if self.control_center and hasattr(
|
||||||
|
self.control_center, "hide_controlcenter"
|
||||||
|
):
|
||||||
self.control_center.hide_controlcenter()
|
self.control_center.hide_controlcenter()
|
||||||
|
|
||||||
# Then open expanded player
|
# Then open expanded player
|
||||||
@@ -847,7 +832,7 @@ class PlayerBox(Box):
|
|||||||
self.current_download_thread = threading.Thread(
|
self.current_download_thread = threading.Thread(
|
||||||
target=self._download_and_set_artwork,
|
target=self._download_and_set_artwork,
|
||||||
args=(art_url,),
|
args=(art_url,),
|
||||||
daemon=True # Dies with main thread
|
daemon=True, # Dies with main thread
|
||||||
)
|
)
|
||||||
self.current_download_thread.start()
|
self.current_download_thread.start()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user