Skip to content

Commit 2249fe3

Browse files
committed
Fixed window stuttering when moving around
1 parent 4c39aa7 commit 2249fe3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/gui.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import timedelta
66
from PIL import Image, ImageTk
77
from random import choice
8+
from threading import Thread
89

910
from wraplabel import WrapLabel
1011
from song import Song, NoSongFound
@@ -45,6 +46,9 @@ def __init__(self, *args, **kwargs):
4546

4647
self.after(1, self.song_changed)
4748

49+
#Start the update_current_song loop in a separate thread
50+
Thread(target=self.update_current_song, daemon=True).start()
51+
4852
self.after(10, self.loop)
4953

5054

@@ -66,17 +70,19 @@ def song_changed(self):
6670

6771
self.lyrics_menu.update_lyric_labels(lyrics=self.lyrics)
6872

73+
def update_current_song(self):
74+
while True:
75+
try:
76+
previous_song_id = self.current_song.id
77+
self.current_song = Song(raw_data=self.spotify.currently_playing())
6978

70-
def loop(self):
71-
previous_song_id = self.current_song.id
79+
if not self.current_song.id == previous_song_id:
80+
self.song_changed()
7281

73-
try:
74-
self.current_song = Song(raw_data=self.spotify.currently_playing())
75-
except Exception as exc:
76-
print(exc)
82+
except Exception as exc:
83+
print(exc)
7784

78-
if not self.current_song.id == previous_song_id:
79-
self.song_changed()
85+
def loop(self):
8086

8187
#Update progress bar
8288
self.bottom_menu.song_progess_bar.update_progress(self.current_song.progress, self.current_song.length)

0 commit comments

Comments
 (0)