init
This commit is contained in:
commit
4af3e17d69
5 changed files with 95 additions and 0 deletions
BIN
__pycache__/xmlhandler.cpython-311.pyc
Normal file
BIN
__pycache__/xmlhandler.cpython-311.pyc
Normal file
Binary file not shown.
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
86
main.py
Normal file
86
main.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
import flet as ft
|
||||
import xmlhandler
|
||||
|
||||
|
||||
def main(page: ft.Page):
|
||||
## Funkktionen
|
||||
def open_url(url):
|
||||
page.launch_url(url)
|
||||
|
||||
def create_overview(category):
|
||||
magazine.clear()
|
||||
for item in bookshelf_dict["PUBS"][category]["ITEM"]:
|
||||
if type(item["TITLE"]) == list: # überspringe beginnerguide 4th edition
|
||||
continue
|
||||
magazine.append(
|
||||
ft.Container(
|
||||
content=ft.Row(
|
||||
controls=[
|
||||
ft.Column(
|
||||
controls=[
|
||||
ft.Image(src=item["COVER"], width=100),
|
||||
ft.FloatingActionButton(
|
||||
"PDF",
|
||||
width=100,
|
||||
on_click=lambda _: open_url(page, item["PDF"]),
|
||||
),
|
||||
],
|
||||
),
|
||||
ft.Column(
|
||||
controls=[
|
||||
ft.Text(item["TITLE"], max_lines=2),
|
||||
ft.Text(item["DESC"], size=12, max_lines=-1),
|
||||
],
|
||||
expand=True,
|
||||
),
|
||||
],
|
||||
),
|
||||
bgcolor=ft.colors.INDIGO_600,
|
||||
border_radius=8,
|
||||
padding=6,
|
||||
)
|
||||
)
|
||||
|
||||
def navigationbar_change(e):
|
||||
category = categorys[e.control.selected_index]
|
||||
create_overview(category)
|
||||
page.update()
|
||||
|
||||
## Variablen
|
||||
magazine = []
|
||||
category = "MAGPI"
|
||||
categorys = ["MAGPI", "HACKSPACE", "BOOKS"]
|
||||
|
||||
def reload(e=None):
|
||||
global bookshelf_dict
|
||||
bookshelf_dict = xmlhandler.reload()
|
||||
create_overview(category)
|
||||
|
||||
print("reloaded")
|
||||
|
||||
reload()
|
||||
|
||||
page.scroll = True
|
||||
page.theme_mode = ft.ThemeMode.DARK
|
||||
page.navigation_bar = ft.NavigationBar(
|
||||
destinations=[
|
||||
ft.NavigationBarDestination(icon=ft.icons.BOOK, label="MagPi"),
|
||||
ft.NavigationBarDestination(icon=ft.icons.BOOK, label="Hackspace"),
|
||||
ft.NavigationBarDestination(icon=ft.icons.BOOK, label="Books"),
|
||||
],
|
||||
on_change=navigationbar_change,
|
||||
)
|
||||
page.appbar = ft.AppBar(
|
||||
# leading_width=40,
|
||||
title=ft.Text("RBookshelf"),
|
||||
center_title=True,
|
||||
bgcolor=ft.colors.SURFACE_VARIANT,
|
||||
actions=[
|
||||
ft.IconButton(ft.icons.DOWNLOAD, on_click=reload),
|
||||
],
|
||||
)
|
||||
page.add(ft.Column(controls=magazine, spacing=10))
|
||||
page.add(page.navigation_bar)
|
||||
|
||||
|
||||
ft.app(main)
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
flet==0.22.*
|
8
xmlhandler.py
Normal file
8
xmlhandler.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import requests
|
||||
import xmltodict
|
||||
import json
|
||||
|
||||
def reload():
|
||||
bookshelf_xml = requests.get("https://magpi.raspberrypi.com/bookshelf.xml")
|
||||
return xmltodict.parse(bookshelf_xml.content)
|
||||
|
Loading…
Reference in a new issue