Skip to content

Commit

Permalink
picture fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Apr 23, 2024
1 parent b112ced commit da5bfae
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
78 changes: 65 additions & 13 deletions data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ flat</property>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<property name="overflow">hidden</property>
<child>
<object class="GtkBox">
<property name="spacing">12</property>
Expand All @@ -677,18 +678,68 @@ flat</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="css-classes">card</property>
<property name="halign">center</property>
<property name="height-request">330</property>
<property name="pixel-size">200</property>
<property name="valign">center</property>
<property name="vexpand">true</property>
<property name="width-request">330</property>
<property name="overflow">hidden</property>
<property name="file" bind-source="playing_track_image" bind-property="file"/>
</object>
</child>
<!-- <object class="GtkOverlay"> -->
<!-- <property name="css-classes">slide-carousel</property> -->
<!-- <property name="child"> -->
<!-- <object class="AdwCarousel"> -->
<!-- <property name="halign">center</property> -->
<!-- <property name="spacing">20</property> -->
<!-- <property name="valign">center</property> -->
<!-- <property name="overflow">visible</property> -->
<!-- <child> -->
<object class="GtkPicture" id="mobile_picture">
<!-- <property name="halign">center</property> -->
<!-- <property name="height-request">330</property> -->
<!-- <property name="hexpand">True</property> -->
<!-- <property name="icon-name">user-trash-full</property> -->
<!-- <property name="pixel-size">200</property> -->
<!-- <property name="valign">center</property> -->
<!-- <property name="vexpand">True</property> -->
<property name="height-request">335</property>
<!-- <property name="file" bind-source="playing_track_image" bind-property="file"/> -->
</object>
<!-- </child> -->
<!-- <child> -->
<!-- <object class="GtkImage"> -->
<!-- <property name="halign">center</property> -->
<!-- <property name="height-request">330</property> -->
<!-- <property name="hexpand">True</property> -->
<!-- <property name="icon-name">drive-optical</property> -->
<!-- <property name="pixel-size">200</property> -->
<!-- <property name="valign">center</property> -->
<!-- <property name="vexpand">True</property> -->
<!-- <property name="width-request">330</property> -->
<!-- <property name="file" bind-source="playing_track_image" bind-property="file"/> -->
<!-- </object> -->
<!-- </child> -->
<!-- </object> -->
<!-- </property> -->
<!-- <child type="overlay"> -->
<!-- <object class="GtkBox"> -->
<!-- <property name="orientation">horizontal</property> -->
<!-- <child> -->
<!-- <object class="GtkBox"> -->
<!-- <property name="css-classes">left-shadow</property> -->
<!-- <property name="vexpand">True</property> -->
<!-- <property name="hexpand">True</property> -->
<!-- </object> -->
<!-- </child> -->
<!-- <child> -->
<!-- <object class="GtkBox"> -->
<!-- <property name="width-request">330</property> -->
<!-- </object> -->
<!-- </child> -->
<!-- <child> -->
<!-- <object class="GtkBox"> -->
<!-- <property name="css-classes">right-shadow</property> -->
<!-- <property name="vexpand">True</property> -->
<!-- <property name="hexpand">True</property> -->
<!-- </object> -->
<!-- </child> -->
<!-- </object> -->
<!-- </child> -->
<!-- </object> -->
</child>
<child>
<object class="GtkBox">
<property name="spacing">6</property>
Expand All @@ -708,11 +759,12 @@ flat</property>
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="mobile_artist_label">
<property name="css-classes">dim-label</property>
<property name="label" bind-source="artist_label" bind-property="label">Song Title</property>
<property name="xalign">0.0</property>
<property name="ellipsize">3</property>
<property name="use-markup">true</property>
</object>
</child>
</object>
Expand Down
26 changes: 26 additions & 0 deletions src/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ def pretty_duration(secs):

return "00:00"

def add_picture(picture_widget, item):

"""Retrieves and adds an picture"""

file_path = Path(f"{variables.IMG_DIR}/{item.id}.jpg")

if file_path.is_file():
GLib.idle_add(_add_picture, picture_widget, str(file_path))

try:
picture_url = item.image()
response = requests.get(picture_url)
except Exception as e:
print(str(e))
return
if response.status_code == 200:
picture_data = response.content

with open(file_path, "wb") as file:
file.write(picture_data)

GLib.idle_add(_add_picture, picture_widget, str(file_path))

def _add_picture(picture_widget, file_path):
picture_widget.set_filename(file_path)

def add_image(image_widget, item):

"""Retrieves and adds an image"""
Expand Down
6 changes: 3 additions & 3 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class HighTideWindow(Adw.ApplicationWindow):
queue_list = Gtk.Template.Child()
main_view_stack = Gtk.Template.Child()
playbar_main_box = Gtk.Template.Child()
mobile_picture = Gtk.Template.Child()

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -221,9 +222,8 @@ def on_song_changed(self, *args):

self.settings.set_int("last-playing-song-id", track.id)

th = threading.Thread(target=utils.add_image, args=(self.playing_track_image, album))
th.deamon = True
th.start()
threading.Thread(target=utils.add_image, args=(self.playing_track_image, album)).start()
threading.Thread(target=utils.add_picture, args=(self.mobile_picture, album)).start()

if self.player_object.is_playing:
self.play_button.set_icon_name("media-playback-pause-symbolic")
Expand Down

0 comments on commit da5bfae

Please sign in to comment.