Skip to content

Commit

Permalink
renamed ArtistLabel to LinkLabel and moved the opening of the uri in …
Browse files Browse the repository at this point in the history
…the variables file
  • Loading branch information
Nokse22 committed Apr 23, 2024
1 parent 65dd947 commit 948d2a4
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 113 deletions.
1 change: 0 additions & 1 deletion data/ui/pages_ui/page_template.ui
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
</object>
</child>
</object>

</property>
<property name="name">content</property>
</object>
Expand Down
3 changes: 1 addition & 2 deletions data/ui/widgets/card_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@
</object>
</child>
<child>
<object class="ArtistLabelWidget" id="track_artist_label">
<signal name="activate-link" handler="on_artist_link_clicked"/>
<object class="LinkLabelWidget" id="track_artist_label">
<property name="ellipsize">end</property>
<property name="max-width-chars">17</property>
<property name="xalign">0</property>
Expand Down
68 changes: 14 additions & 54 deletions data/ui/widgets/generic_track_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,16 @@
<property name="hexpand">true</property>

<child>
<object class="GtkButton" id="track_album_button">
<signal name="clicked" handler="on_album_button_clicked"/>
<object class="LinkLabelWidget" id="track_album_label">
<property name="xalign">0</property>
<property name="ellipsize">3</property>
<layout>
<property name="column">5</property>
<property name="column-span">1</property>
<property name="row">0</property>
</layout>
<style>
<class name="link-text"/>
<class name="artist-button"/>
</style>
<child>
<object class="GtkLabel" id="track_album_label">
<property name="xalign">0</property>
<property name="ellipsize">3</property>
<style>
<class name="link-text"/>
<class name="artist-button"/>
</style>
</object>
</child>
</object>
</child>



<child>
<object class="GtkBox">
<layout>
Expand Down Expand Up @@ -96,35 +80,22 @@
</child>

<child>
<object class="GtkButton">
<signal name="clicked" handler="on_artist_button_clicked"/>
<object class="LinkLabelWidget" id="artist_label">
<property name="xalign">0</property>
<property name="ellipsize">3</property>
<layout>
<property name="column">3</property>
<property name="column-span">1</property>
<property name="row">0</property>
</layout>
<style>
<class name="link-text"/>
<class name="artist-button"/>
</style>
<child>
<object class="GtkLabel" id="artist_label">
<property name="xalign">0</property>
<property name="ellipsize">3</property>
<style>
<class name="link-text"/>
<class name="artist-button"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="_narrow_box">
<property name="orientation">vertical</property>
<property name="visible">False</property>
<property name="visible">False</property>variables.favourite_tracks
<property name="hexpand">true</property>
<child>
<object class="GtkBox">
Expand All @@ -149,24 +120,13 @@
</child>
</object>
</child>

<child>
<object class="GtkButton">
<signal name="clicked" handler="on_artist_button_clicked"/>
<style>
<class name="link-text"/>
<class name="artist-button"/>
</style>
<child>
<object class="GtkLabel">
<property name="label" bind-source="artist_label" bind-property="label"></property>
<property name="xalign">0</property>
<property name="ellipsize">3</property>
<style>
<class name="link-text"/>
<class name="artist-button"/>
</style>
</object>
</child>
<object class="LinkLabelWidget" id="artist_label_2">
<property name="xalign">0</property>
<property name="use-markup">true</property>
<property name="ellipsize">3</property>
<property name="label" bind-source="artist_label" bind-property="label"></property>
</object>
</child>
</object>
Expand All @@ -177,7 +137,7 @@
<property name="margin-end">12</property>
<property name="vexpand">True</property>
</object>
</child>
</child>variables.favourite_tracks
<child>
<object class="GtkMenuButton">
<property name="icon-name">view-more-symbolic</property>
Expand Down
3 changes: 2 additions & 1 deletion data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@
</object>
</child>
<child>
<object class="ArtistLabelWidget" id="artist_label">
<object class="LinkLabelWidget" id="artist_label">
<property name="xalign">0</property>
<property name="ellipsize">end</property>
</object>
</child>
</object>
Expand Down
43 changes: 43 additions & 0 deletions src/lib/variables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import os

import tidalapi
from tidalapi.artist import Artist
from tidalapi.album import Album
from tidalapi.media import Track
from tidalapi.playlist import Playlist

from ..pages import artistPage
from ..pages import albumPage

import threading

def init():
global DATA_DIR
DATA_DIR = os.environ.get('XDG_DATA_HOME')
Expand All @@ -19,3 +30,35 @@ def init():
global player_object

global sidebar_list

global favourite_tracks

def open_uri(label, uri):
print(uri)
th= threading.Thread(target=_load_object, args=(uri,))
th.start()
return True

def _open_uri(uri, loaded_object):
uri_parts = uri.split(":")

match uri_parts[0]:
case "artist":
page = artistPage(loaded_object, loaded_object.name)
page.load()
navigation_view.push(page)
case "album":
page = albumPage(loaded_object, loaded_object.name)
page.load()
navigation_view.push(page)

def _load_object(uri):
uri_parts = uri.split(":")

match uri_parts[0]:
case "artist":
loaded_object = Artist(session, uri_parts[1])
case "album":
loaded_object = Album(session, uri_parts[1])

_open_uri(uri, loaded_object)
10 changes: 9 additions & 1 deletion src/pages/mix_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ def _load_page(self):

builder.get_object("_play_button").connect("clicked", self.on_play_button_clicked)
builder.get_object("_shuffle_button").connect("clicked", self.on_shuffle_button_clicked)
builder.get_object("_add_to_my_collection_button").connect("clicked", self.on_add_to_my_collection_button_clicked)
self.in_my_collection_button = builder.get_object("_add_to_my_collection_button")
self.in_my_collection_button.connect("clicked", self.on_add_to_my_collection_button_clicked)

image = builder.get_object("_image")
th = threading.Thread(target=utils.add_image, args=(image, self.item))
th.deamon = True
th.start()

for favourite_track in variables.favourite_tracks:
if favourite_track.isrc == track.isrc:
self.in_my_collection_button.set_icon_name("heart-filled-symbolic")
break
else:
self.in_my_collection_button.set_icon_name("heart-outline-thick-symbolic")

for index, track in enumerate(self.item.items()):
listing = self.get_track_listing(track)
listing.set_name(str(index))
Expand Down
9 changes: 0 additions & 9 deletions src/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ def remove_from_my_collection(self, btn, item):
result = variables.session.user.favorites.remove_mix(item.id)
elif isinstance(item, Album):
result = variables.session.user.favorites.remove_album(item.id)
print("adding album")
elif isinstance(item, Artist):
result = variables.session.user.favorites.remove_artist(item.id)
elif isinstance(item, Playlist):
Expand All @@ -277,11 +276,3 @@ def on_add_to_my_collection_button_clicked(self, btn):
th = threading.Thread(target=self.remove_from_my_collection, args=(btn, self.item,))
th.deamon = True
th.start()

def on_link_clicked(self, label, uri):
from .pages import artistPage

artist = Artist(self.session, uri)
page = artistPage(artist, artist.name)
page.load()
self.navigation_view.push(page)
2 changes: 1 addition & 1 deletion src/pages/track_radio_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _load_page(self):

builder.get_object("_play_button").connect("clicked", self.on_play_button_clicked)
builder.get_object("_shuffle_button").connect("clicked", self.on_shuffle_button_clicked)
builder.get_object("_add_to_my_collection_button").connect("clicked", self.on_add_to_my_collection_button_clicked)
builder.get_object("_add_to_my_collection_button").set_visible(False)

image = builder.get_object("_image")
if isinstance(self.item, Track):
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .generic_track_widget import GenericTrackWidget
from .top_hit_widget import TopHitWidget
from .tracks_list_widget import TracksListWidget
from .artist_label_widget import ArtistLabelWidget
from .link_label_widget import LinkLabelWidget
12 changes: 3 additions & 9 deletions src/widgets/card_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ class CardWidget(Adw.BreakpointBin):
button = Gtk.Template.Child()
title_label = Gtk.Template.Child()
detail_label = Gtk.Template.Child()

track_artist_label = Gtk.Template.Child()

def __init__(self, _item):
super().__init__()

self.track_artist_label.connect("activate-link", variables.open_uri)

self.item = _item

if isinstance(_item, Mix):
Expand Down Expand Up @@ -131,15 +134,6 @@ def make_page_item_card(self):
th.deamon = True
th.start()

@Gtk.Template.Callback("on_artist_link_clicked")
def on_artist_link_clicked(self, label, uri):
from ..pages import artistPage

artist = Artist(variables.session, uri)
page = artistPage(artist, artist.name)
page.load()
variables.navigation_view.push(page)

@Gtk.Template.Callback("on_image_button_clicked")
def _on_image_button_clicked(self, *args):
if isinstance(self.item, Mix):
Expand Down
32 changes: 12 additions & 20 deletions src/widgets/generic_track_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ..lib import utils

from tidalapi.user import Favorites
from tidalapi.artist import Artist

from ..lib import variables

Expand All @@ -39,28 +40,33 @@ class GenericTrackWidget(Gtk.ListBoxRow):
"""It is used to display a single track"""

image = Gtk.Template.Child()
track_album_label = Gtk.Template.Child()
track_title_label = Gtk.Template.Child()
track_duration_label = Gtk.Template.Child()
artist_label = Gtk.Template.Child()
playlists_submenu = Gtk.Template.Child()
track_album_button = Gtk.Template.Child()
_grid = Gtk.Template.Child()
explicit_label = Gtk.Template.Child()

artist_label = Gtk.Template.Child()
artist_label_2 = Gtk.Template.Child()
track_album_label = Gtk.Template.Child()

def __init__(self, _track, is_album):
super().__init__()

self.artist_label.connect("activate-link", variables.open_uri)
self.artist_label_2.connect("activate-link", variables.open_uri)
self.track_album_label.connect("activate-link", variables.open_uri)

if is_album:
self._grid.remove(self.track_album_button)
self._grid.remove(self.track_album_label)
self.image.set_visible(False)
self.track_title_label.set_margin_start(12)

self.track = _track

self.track_album_label.set_label(self.track.album.name)
self.track_album_label.set_album(self.track.album)
self.track_title_label.set_label(self.track.name)
self.artist_label.set_label(self.track.artist.name)
self.artist_label.set_artists(self.track.artists)

self.explicit_label.set_visible(self.track.explicit)

Expand Down Expand Up @@ -134,17 +140,3 @@ def _add_to_playlist(self, action, parameter, playlist_index):
selected_playlist = self.win.favourite_playlists[playlist_index]

print(f"Added to playlist: {selected_playlist.name}, ID: {playlist_id}")

@Gtk.Template.Callback("on_artist_button_clicked")
def _on_artist_button_clicked(self, *args):
from ..pages.artist_page import artistPage
page = artistPage(self.track.artist, f"{self.track.artist.name}")
page.load()
variables.navigation_view.push(page)

@Gtk.Template.Callback("on_album_button_clicked")
def _on_album_button_clicked(self, *args):
from ..pages.album_page import albumPage
page = albumPage(self.track.album, f"{self.track.album.name}")
page.load()
variables.navigation_view.push(page)
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

from ..lib import variables

class ArtistLabelWidget(Gtk.Label):
__gtype_name__ = 'ArtistLabelWidget'
class LinkLabelWidget(Gtk.Label):
__gtype_name__ = 'LinkLabelWidget'

"""It is used to display multiple artist with a link"""

Expand All @@ -42,6 +42,10 @@ def set_artists(self, artists):
for index, artist in enumerate(artists):
if index >= 1:
label += ", "
label += f"""<a href="{artist.id}">{html.escape(artist.name)}</a>"""
label += f"""<a href="artist:{artist.id}">{html.escape(artist.name)}</a>"""

self.set_markup(label)

def set_album(self, album):
label = f"""<a href="album:{album.id}">{html.escape(album.name)}</a>"""
self.set_markup(label)
Loading

0 comments on commit 948d2a4

Please sign in to comment.