Skip to content

Commit

Permalink
used fromFunctionPage instead of singleTypePage and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Apr 23, 2024
1 parent c8fb6c4 commit b640e89
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
49 changes: 22 additions & 27 deletions src/pages/from_function_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class fromFunctionPage(Page):

"""Used to display lists of albums/artists/mixes/playlists and tracks from a request function"""

def __init__(self, _type):
def __init__(self, _type, _title=""):
super().__init__()

self.function = None
self.type = _type

self.set_title("More")
self.set_title(_title)

self.parent = None

Expand All @@ -63,14 +63,13 @@ def __init__(self, _type):
self.items_limit = 50
self.items_n = 0

self.handler_id = self.scrolled_window.connect("edge-overshot", self.on_edge_overshot)

def set_function(self, function):
self.function = function

self.scrolled_window.connect("edge-overshot", self.on_edge_overshot)

def set_items(self, items):
self.items = items
print(len(items))

def on_edge_overshot(self, scrolled_window, pos):
if pos == Gtk.PositionType.BOTTOM:
Expand All @@ -84,45 +83,41 @@ def _load_page(self):
self._page_loaded()

def load_items(self):
new_items = []
if self.function:
new_items = self.function(limit=self.items_limit, offset=(self.items_n))
self.items.extend(new_items)
self.items_n += self.items_limit
if new_items == []:
self.scrolled_window.handler_disconnect(self.handler_id)
return
else:
new_items = self.items
self.scrolled_window.handler_disconnect(self.handler_id)

print(f"loading {self.items_n} of type {self.type}")

if self.type == "track":
self.add_tracks()
self.add_tracks(new_items)
else:
self.add_cards()
self.add_cards(new_items)

def add_tracks(self):
def add_tracks(self, new_items):
if self.parent == None:
self.parent = Gtk.ListBox(css_classes=["boxed-list"], margin_bottom=12, margin_start=12, margin_end=12, margin_top=12)
GLib.idle_add(self.page_content.append,self.parent)

new_items = []
if self.function:
new_items = self.function(limit=self.items_limit, offset=(self.items_n))
self.items.extend(new_items)
else:
new_items = self.items
self.items_n += self.items_limit
self.parent.connect("row-activated", self.on_tracks_row_selected)
self.parent.connect("row-activated", self.on_tracks_row_selected)

for index, track in enumerate(new_items):
listing = self.get_track_listing(track)
listing.set_name(str(index))
self.parent.append(listing)
GLib.idle_add(self.parent.append, listing)

def add_cards(self):
def add_cards(self, new_items):
if self.parent == None:
self.parent = Gtk.FlowBox(selection_mode=0)
self.page_content.append(self.parent)

new_items = []
if self.function:
new_items = self.function(limit=self.items_limit, offset=(self.items_n))
self.items.extend(new_items)
else:
new_items = self.items
self.items_n += self.items_limit

for index, item in enumerate(new_items):
card = CardWidget(item)
GLib.idle_add(self.parent.append, card)
Expand Down
12 changes: 5 additions & 7 deletions src/widgets/carousel_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ class CarouselWidget(Gtk.Box):
carousel = Gtk.Template.Child()
more_button = Gtk.Template.Child()

def __init__(self, title=""):
def __init__(self, _title=""):
super().__init__()

self.n_pages = 0

self.title_label.set_label(title)
self.title = _title
self.title_label.set_label(self.title)

self.more_function = None
self.type = None
Expand Down Expand Up @@ -78,16 +79,13 @@ def set_items(self, items_list, items_type):

@Gtk.Template.Callback("on_more_clicked")
def on_more_clicked(self, *args):
if not self.window:
return

from ..pages import fromFunctionPage

if self.more_function == None:
page = fromFunctionPage(self, self.type)
page = fromFunctionPage(self.type, self.title)
page.set_items(self.items)
else:
page = fromFunctionPage(self, self.type)
page = fromFunctionPage(self.type, self.title)
page.set_function(self.more_function)

print(f"clicked more, items len:{len(self.items)}")
Expand Down
23 changes: 16 additions & 7 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
from .login import LoginWindow
from .new_playlist import NewPlaylistWindow

from .pages import homePage, singleTypePage, explorePage, artistPage, notLoggedInPage
from .pages import searchPage, trackRadioPage, playlistPage, startUpPage
from .pages import homePage, explorePage, artistPage, notLoggedInPage
from .pages import searchPage, trackRadioPage, playlistPage, startUpPage, fromFunctionPage

import threading
import requests
Expand Down Expand Up @@ -504,23 +504,32 @@ def on_sidebar_row_selected_clicked_func(self, list_box, row):
page.load()
self.navigation_view.push(page)
elif row.get_child().get_name() == "F-TRACK":
page = singleTypePage("track", "Favourite Tracks")
page = fromFunctionPage("track", _("Favorite Tracks"))
page.set_function(self.session.user.favorites.tracks)
page.load()
self.navigation_view.push(page)

elif row.get_child().get_name() == "F-MIX": # Not supported by tidalapi
page = singleTypePage("mix", "Favourite Mixes")
page = fromFunctionPage("mix", _("Favorite Mixes"))
page.set_function(self.session.user.favorites.mixes)
page.load()
self.navigation_view.push(page)

elif row.get_child().get_name() == "F-ARTIST":
page = singleTypePage("artist", "Favourite Artists")
page = fromFunctionPage("artist", _("Favorite Artists"))
page.set_function(self.session.user.favorites.artists)
page.load()
self.navigation_view.push(page)

elif row.get_child().get_name() == "F-PLAYLIST":
page = singleTypePage("playlist", "Favourite Playlists")
page = fromFunctionPage("playlist", _("Favorite Playlists"))
page.set_function(self.session.user.favorites.playlists)
page.load()
self.navigation_view.push(page)

elif row.get_child().get_name() == "F-ALBUM":
page = singleTypePage("album", "Favourite Albums")
page = fromFunctionPage("album", _("Favorite Albums"))
page.set_function(self.session.user.favorites.albums)
page.load()
self.navigation_view.push(page)

Expand Down

0 comments on commit b640e89

Please sign in to comment.