-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson2gtk
More file actions
executable file
·40 lines (34 loc) · 1.26 KB
/
json2gtk
File metadata and controls
executable file
·40 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
import sys
import gi
import json
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw
class JSONML:
def __init__(self, data):
self.data = data
def __getitem__(self, tag):
if type(tag) is int: return self.data[tag]
if type(tag) is str: return JSONML(
[item[2] for d in self.data for item in d if type(item) is list and item[0] == tag and len(item)>=2]
)
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
obj = JSONML([[json.load(sys.stdin)]])
rootbox = Gtk.Box()
listbox = Gtk.ListBox(hexpand=True,valign=Gtk.Align.START)
items = obj["rss"]["channel"]["item"]
for item in items:
listbox.append(Adw.ActionRow(title=[tag[2][0] for tag in item if tag[0] == 'title'][0]))
rootbox.append(listbox)
self.set_child(rootbox)
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
MainWindow(application=app).present()
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)