87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
|
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)
|