Skip to content

Commit

Permalink
changed names of thread functions, fixed blank window bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Jul 20, 2024
1 parent 991cb9e commit e02fba8
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/lib/player_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ def play_pause(self):
self.play()

def play_track(self, track):
th = threading.Thread(target=self._play_track, args=(track,))
th = threading.Thread(target=self._th_play_track, args=(track,))
th.deamon = True
th.start()

def _play_track(self, track):
def _th_play_track(self, track):
print(f"play track: {track.name} by {track.artist.name}, {track.media_metadata_tags}, {track.audio_quality}, {track.id}")
music_url = track.get_url()
self._player.set_state(Gst.State.NULL)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def is_favourited(item):

return False

def add_to_my_collection(btn, item):
def th_add_to_my_collection(btn, item):
if isinstance(item, Track):
result = session.user.favorites.add_track(item.id)
elif isinstance(item, Mix):
Expand Down Expand Up @@ -121,7 +121,7 @@ def remove_from_my_collection(btn, item):

def on_in_to_my_collection_button_clicked(btn, item):
if btn.get_icon_name() == "heart-outline-thick-symbolic":
threading.Thread(target=add_to_my_collection, args=(btn, item,)).start()
threading.Thread(target=th_add_to_my_collection, args=(btn, item,)).start()
else:
threading.Thread(target=remove_from_my_collection, args=(btn, item,)).start()

Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self):
variables.init()

def on_download(self, *args):
th = threading.Thread(target=self.win.download_song)
th = threading.Thread(target=self.win.th_download_song)
th.deamon = True
th.start()

Expand Down
2 changes: 1 addition & 1 deletion src/pages/album_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class albumPage(Page):

"""It is used to display an album"""

def _load_page(self):
def _th_load_page(self):
builder = Gtk.Builder.new_from_resource("/io/github/nokse22/HighTide/ui/pages_ui/tracks_list_template.ui")

page_content = builder.get_object("_main")
Expand Down
2 changes: 1 addition & 1 deletion src/pages/artist_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, _artist, _name):
self.top_tracks = []
self.artist = _artist

def _load_page(self):
def _th_load_page(self):

print(f"artist: {self.artist.name}, id: {self.artist.id}, {self.artist.picture}")

Expand Down
2 changes: 1 addition & 1 deletion src/pages/explore_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class explorePage(Page):

"""It is used to display the explore page"""

def _load_page(self):
def _th_load_page(self):
explore = variables.session.explore()

# print(explore.categories)
Expand Down
8 changes: 4 additions & 4 deletions src/pages/from_function_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ def set_items(self, items):

def on_edge_overshot(self, scrolled_window, pos):
if pos == Gtk.PositionType.BOTTOM:
th = threading.Thread(target=self.load_items)
th = threading.Thread(target=self.th_load_items)
th.deamon = True
th.start()

def _load_page(self):
self.load_items()
def _th_load_page(self):
self.th_load_items()

self._page_loaded()

def load_items(self):
def th_load_items(self):
new_items = []
if self.function:
new_items = self.function(limit=self.items_limit, offset=(self.items_n))
Expand Down
2 changes: 1 addition & 1 deletion src/pages/generic_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class genericPage(Page):

"""It is used for explore page categories page"""

def _load_page(self):
def _th_load_page(self):
generic_content = self.item.get()

for index, category in enumerate(generic_content.categories):
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
class homePage(Page):
__gtype_name__ = 'homePage'

def _load_page(self):
def _th_load_page(self):
self.set_tag("home")

self.set_title("Home")
Expand Down
6 changes: 3 additions & 3 deletions src/pages/mix_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class mixPage(Page):
__gtype_name__ = 'mixPage'

def _load_page(self):
def _th_load_page(self):
builder = Gtk.Builder.new_from_resource("/io/github/nokse22/HighTide/ui/pages_ui/tracks_list_template.ui")

page_content = builder.get_object("_main")
Expand All @@ -68,7 +68,7 @@ def _load_page(self):

in_my_collection_btn = builder.get_object("_in_my_collection_button")
self.signals.append(
(in_my_collection_btn, in_my_collection_btn.connect("clicked", self.add_to_my_collection))
(in_my_collection_btn, in_my_collection_btn.connect("clicked", self.th_add_to_my_collection))
)

if (variables.is_favourited(self.item)):
Expand All @@ -95,5 +95,5 @@ def on_row_selected(self, list_box, row):

variables.player_object.play_this(self.item, index)

def add_to_my_collection(btn):
def th_add_to_my_collection(btn):
variables.on_in_to_my_collection_button_clicked(btn, self.item)
2 changes: 1 addition & 1 deletion src/pages/not_logged_in_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
class notLoggedInPage(Page):
__gtype_name__ = 'notLoggedInPage'

def _load_page(self):
def _th_load_page(self):
self.set_title("Not Logged In")

descr = '''To be able to use this app you need to login with your TIDAL account.'''
Expand Down
4 changes: 2 additions & 2 deletions src/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def load(self):

"""Called when the page is created, it just starts a thread running the actual function to load the page UI"""

th = threading.Thread(target=self._load_page)
th = threading.Thread(target=self._th_load_page)
th.deamon = True
th.start()

def _load_page(self):
def _th_load_page(self):

"""Overwritten by each different page"""

Expand Down
2 changes: 1 addition & 1 deletion src/pages/playlist_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class playlistPage(Page):
# FIXME Fix the favourite hearth
# FIXME After playing shuffle the next track is not found

def _load_page(self):
def _th_load_page(self):
builder = Gtk.Builder.new_from_resource("/io/github/nokse22/HighTide/ui/pages_ui/tracks_list_template.ui")

page_content = builder.get_object("_main")
Expand Down
2 changes: 1 addition & 1 deletion src/pages/search_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class searchPage(Page):
# TODO Implement filters
# TODO Custom search page with filters (no builder with search_filters.ui)

def _load_page(self):
def _th_load_page(self):
# filter_builder = Gtk.Builder.new_from_resource("/io/github/nokse22/HighTide/ui/search_filter.ui")
# filters_scrolled_window = filter_builder.get_object("filters_scrolled_window")

Expand Down
2 changes: 1 addition & 1 deletion src/pages/start_up_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
class startUpPage(Page):
__gtype_name__ = 'startUpPage'

def _load_page(self):
def _th_load_page(self):
self.set_tag("loading-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 @@ -53,7 +53,7 @@ def __init__(self, _item, _name):

self.radio_tracks = []

def _load_page(self):
def _th_load_page(self):
builder = Gtk.Builder.new_from_resource("/io/github/nokse22/HighTide/ui/pages_ui/tracks_list_template.ui")

page_content = builder.get_object("_main")
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/generic_track_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def set_track(self, _track, is_album=False):
("radio", self._get_radio),
("play-next", self._play_next),
("add-to-queue", self._add_to_queue),
("add-to-my-collection", self._add_to_my_collection)
("add-to-my-collection", self._th_add_to_my_collection)
]

# action = Gio.SimpleAction.new("add-to-playlist", GLib.Variant("s"))
Expand Down Expand Up @@ -149,12 +149,12 @@ def _play_next(self, *args):
def _add_to_queue(self, *args):
variables.player_object.add_to_queue(self.track)

def _add_to_my_collection(self, *args):
th = threading.Thread(target=self.th_add_to_my_collection, args=())
def _th_add_to_my_collection(self, *args):
th = threading.Thread(target=self.th_th_add_to_my_collection, args=())
th.deamon = True
th.start()

def th_add_to_my_collection(self):
def th_th_add_to_my_collection(self):
variables.session.user.favorites.add_track(self.track.id)

def _add_to_playlist(self, action, parameter, playlist_index):
Expand Down
12 changes: 5 additions & 7 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def on_song_changed(self, *args):
else:
self.play_button.set_icon_name("media-playback-start-symbolic")

th = threading.Thread(target=self.add_lyrics_to_page, args=())
th = threading.Thread(target=self.th_add_lyrics_to_page, args=())
th.deamon = True
th.start()

Expand Down Expand Up @@ -351,18 +351,16 @@ def on_lyrics_button_clicked_func(self, widget):
self.main_view_stack.set_visible_child_name("mobile_view")
self.mobile_stack.set_visible_child_name("lyrics_page")

th = threading.Thread(target=self.add_lyrics_to_page, args=())
th.deamon = True
th.start()
threading.Thread(target=self.th_add_lyrics_to_page, deamon=True).start()

def add_lyrics_to_page(self):
def th_add_lyrics_to_page(self):
try:
lyrics = self.player_object.playing_track.lyrics()
self.lyrics_label.set_label(lyrics.text)
GLib.idle_add(self.lyrics_label.set_label, lyrics.text)
except:
return

def download_song(self):
def th_download_song(self):
"""Added to check the streamed song quality, triggered with ctrl+d"""

song = self.player_object.playing_track
Expand Down

0 comments on commit e02fba8

Please sign in to comment.