feat: community icons!
This commit is contained in:
29
src/main.py
29
src/main.py
@@ -2,11 +2,12 @@ import sys
|
|||||||
import gi
|
import gi
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
gi.require_version("Gtk", "4.0")
|
gi.require_version("Gtk", "4.0")
|
||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
|
|
||||||
from gi.repository import Gtk, Adw
|
from gi.repository import Gtk, Adw, Gdk, Gio
|
||||||
|
|
||||||
class LemonadeWindow(Gtk.ApplicationWindow):
|
class LemonadeWindow(Gtk.ApplicationWindow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -66,8 +67,8 @@ class LemonadeWindow(Gtk.ApplicationWindow):
|
|||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def refresh(self, *args):
|
def refresh(self, *args):
|
||||||
self.list = requests.get("https://lemmy.ml/api/v3/community/list?sort=Hot").json()
|
self.communities = requests.get("https://lemmy.ml/api/v3/community/list?sort=Hot").json()
|
||||||
for post in self.list["communities"]:
|
for community in self.communities["communities"]:
|
||||||
box = Gtk.Box(
|
box = Gtk.Box(
|
||||||
orientation=Gtk.Orientation.HORIZONTAL,
|
orientation=Gtk.Orientation.HORIZONTAL,
|
||||||
margin_top = 20,
|
margin_top = 20,
|
||||||
@@ -78,13 +79,24 @@ class LemonadeWindow(Gtk.ApplicationWindow):
|
|||||||
self.listbox.append(box)
|
self.listbox.append(box)
|
||||||
|
|
||||||
label = Gtk.Label.new()
|
label = Gtk.Label.new()
|
||||||
|
avatar = Adw.Avatar.new(40, community["community"]["title"], True)
|
||||||
|
|
||||||
if not "description" in post["community"]:
|
if "icon" in community["community"]:
|
||||||
label.set_markup(f"""<big><b>{post["community"]["title"]}</b></big> <small>c/{post["community"]["name"]}</small>""")
|
try:
|
||||||
|
urllib.request.urlretrieve(community["community"]["icon"], ".comic.png")
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
avatar.set_custom_image(Gdk.Texture.new_from_file(Gio.File.new_for_path("./.comic.png")))
|
||||||
else:
|
else:
|
||||||
split = post["community"]["description"].split("\n")[0]
|
pass
|
||||||
label.set_markup(f"""<big><b>{post["community"]["title"]}</b></big> <small>c/{post["community"]["name"]}</small>
|
|
||||||
<small>{split}</small>""")
|
if not "description" in community["community"]:
|
||||||
|
label.set_markup(f"""<big><b>{community["community"]["title"]}</b></big> <small>c/{community["community"]["name"]}</small>""")
|
||||||
|
else:
|
||||||
|
split = community["community"]["description"].split("\n")[0]
|
||||||
|
label.set_markup(f"""<big><b>{community["community"]["title"]}</b></big> <small>c/{community["community"]["name"]}</small>
|
||||||
|
{split}""")
|
||||||
|
|
||||||
label.props.margin_start = 5
|
label.props.margin_start = 5
|
||||||
label.props.hexpand = True
|
label.props.hexpand = True
|
||||||
@@ -96,6 +108,7 @@ class LemonadeWindow(Gtk.ApplicationWindow):
|
|||||||
# refresh_button.connect("clicked", self.refresh)
|
# refresh_button.connect("clicked", self.refresh)
|
||||||
# refresh_button.set_tooltip_text("Refresh")
|
# refresh_button.set_tooltip_text("Refresh")
|
||||||
# box.append(refresh_button)
|
# box.append(refresh_button)
|
||||||
|
box.append(avatar)
|
||||||
box.append(label)
|
box.append(label)
|
||||||
|
|
||||||
class Lemonade(Adw.Application):
|
class Lemonade(Adw.Application):
|
||||||
|
Reference in New Issue
Block a user