mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
wip: details & backend
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
*.zip
|
||||
*.swp
|
||||
__pycache__/
|
||||
|
||||
76
client.py
76
client.py
@@ -2,35 +2,79 @@ import tkinter
|
||||
import customtkinter
|
||||
import PIL
|
||||
import data_backend
|
||||
import client_details
|
||||
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
customtkinter.set_default_color_theme("blue")
|
||||
|
||||
app = customtkinter.CTk()
|
||||
|
||||
app.geometry("720x780")
|
||||
last_geometry = app.winfo_geometry()
|
||||
app.title("Test")
|
||||
app.update()
|
||||
|
||||
img = PIL.Image.open("test.jpg")
|
||||
img = img.resize((200, 300))
|
||||
img = PIL.ImageTk.PhotoImage(img)
|
||||
#img = PIL.ImageTk.PhotoImage(file="test.jpg")
|
||||
|
||||
buttons = []
|
||||
|
||||
def create_navbar():
|
||||
'''Create basic navigation bar'''
|
||||
|
||||
# spawn frame at very top #
|
||||
# add "Home" button
|
||||
|
||||
def switch_to_main():
|
||||
'''Switch back to main view from details'''
|
||||
|
||||
# destroy details elements #
|
||||
for el in details_elements:
|
||||
el.destory()
|
||||
|
||||
load_main()
|
||||
|
||||
def switch_to_game_details(software):
|
||||
'''Switch to the details of the clicked tile'''
|
||||
pass
|
||||
|
||||
destroy_main()
|
||||
load_details(app, software)
|
||||
|
||||
def load_main():
|
||||
'''Load the main page overview'''
|
||||
|
||||
# create tiles from meta files #
|
||||
for software in db.find_all_metadata():
|
||||
print(software.title)
|
||||
create_main_window_tile(software)
|
||||
|
||||
# set update listener & update positions #
|
||||
app.bind("<Configure>", update_button_positions)
|
||||
update_button_positions()
|
||||
|
||||
def destroy_main():
|
||||
'''Destroy all elements in the main view'''
|
||||
|
||||
app.unbind("<Configure>")
|
||||
for b in buttons:
|
||||
b.destroy()
|
||||
|
||||
def load_details(app, software):
|
||||
'''Load the details page for a software'''
|
||||
|
||||
details_elements = client_details.create_details_page(app, software)
|
||||
|
||||
def create_main_window_tile(software):
|
||||
'''Create the main window tile'''
|
||||
|
||||
button = customtkinter.CTkButton(app, image=img, width=200, height=300,
|
||||
command=lambda: switch_to_game_details(game),
|
||||
border_width=0, corner_radius=0, border_spacing=0,
|
||||
text="Test Title LOLOLOL",
|
||||
fg_color="transparent", compound="top", anchor="s")
|
||||
img = PIL.Image.open(software.get_thumbnail())
|
||||
img = img.resize((200, 300))
|
||||
img = PIL.ImageTk.PhotoImage(img)
|
||||
|
||||
button = customtkinter.CTkButton(app, image=img,
|
||||
width=200, height=300,
|
||||
command=lambda: switch_to_game_details(software),
|
||||
border_width=0, corner_radius=0, border_spacing=0,
|
||||
text=software.title,
|
||||
fg_color="transparent", compound="top", anchor="s")
|
||||
buttons.append(button)
|
||||
return button
|
||||
|
||||
def update_button_positions(event=None):
|
||||
@@ -66,18 +110,12 @@ def update_button_positions(event=None):
|
||||
button.grid(row=i // num_columns, column=i % num_columns, sticky="we")
|
||||
|
||||
|
||||
if __init__ == "__main__":
|
||||
if __name__ == "__main__":
|
||||
|
||||
# define data backend #
|
||||
db = data_backend.LocalFS(None, None, "./cache", remote_root_dir="example_software_root")
|
||||
|
||||
# create tiles from meta files #
|
||||
for software in db.find_all_metadata():
|
||||
create_main_window_tile(software)
|
||||
|
||||
# set update listener & update positions #
|
||||
app.bind("<Configure>", update_button_positions)
|
||||
update_button_positions()
|
||||
load_main()
|
||||
|
||||
# run app #
|
||||
app.mainloop()
|
||||
|
||||
67
client_details.py
Normal file
67
client_details.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import PIL
|
||||
import tkinter
|
||||
import customtkinter
|
||||
|
||||
def show_large_picture(app, path):
|
||||
'''Show a full-window version of the clicked picture'''
|
||||
pass
|
||||
|
||||
def create_details_page(app, software):
|
||||
'''Create the details page for a software and return its elements for later destruction'''
|
||||
|
||||
elements = []
|
||||
|
||||
img = PIL.Image.open(software.get_thumbnail())
|
||||
img = img.resize((200, 300))
|
||||
img = PIL.ImageTk.PhotoImage(img)
|
||||
|
||||
# thumbnail image #
|
||||
thumbnail_image = customtkinter.CTkButton(app, text="", image=img, width=200, height=300,
|
||||
command=lambda: show_large_picture(app, path))
|
||||
thumbnail_image.pack()
|
||||
elements.append(thumbnail_image)
|
||||
|
||||
# title #
|
||||
title = customtkinter.CTkLabel(app, textvariable=software.title)
|
||||
title.pack()
|
||||
elements.append(title)
|
||||
|
||||
# genre #
|
||||
genre = customtkinter.CTkLabel(app, textvariable=software.genre)
|
||||
genre.pack()
|
||||
elements.append(genre)
|
||||
|
||||
# description #
|
||||
description = customtkinter.CTkTextbox(app)
|
||||
description.insert("0.0", software.description)
|
||||
description.pack()
|
||||
elements.append(description)
|
||||
|
||||
# dependencies #
|
||||
dependencies = customtkinter.CTkTextbox(app)
|
||||
dependencies.insert("0.0", str(software.dependencies))
|
||||
description.pack()
|
||||
elements.append(description)
|
||||
|
||||
# buttons #
|
||||
install_button = customtkinter.CTkButton(app, text="Install",
|
||||
command=lambda: software.install(software))
|
||||
remove_button = customtkinter.CTkButton(app, text="Remove",
|
||||
command=lambda: software.remove(software))
|
||||
|
||||
install_button.pack()
|
||||
remove_button.pack()
|
||||
elements.append(install_button)
|
||||
elements.append(remove_button)
|
||||
|
||||
# add other pictures #
|
||||
for path in software.pictures[1:]:
|
||||
img = PIL.Image.open(software.get_thumbnail())
|
||||
img = img.resize((200, 300))
|
||||
img = PIL.ImageTk.PhotoImage(img)
|
||||
extra_pic_button = customtkinter.CTkButton(app, text="", image=img, width=200, height=300,
|
||||
command=lambda: show_large_picture(app, path))
|
||||
extra_pic_button.pack()
|
||||
elements.append(extra_pic_button)
|
||||
|
||||
return elements
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import glob
|
||||
import yaml
|
||||
import software
|
||||
|
||||
class DataBackend:
|
||||
|
||||
@@ -47,7 +48,6 @@ class LocalFS(DataBackend):
|
||||
if not os.path.isfile(meta_file):
|
||||
continue
|
||||
else:
|
||||
with open(meta_file) as f:
|
||||
meta_info_list.append(yaml.safe_load(f))
|
||||
meta_info_list.append(software.Software(meta_file))
|
||||
|
||||
return meta_info_list
|
||||
return meta_info_list
|
||||
|
||||
39
software.py
39
software.py
@@ -1,13 +1,36 @@
|
||||
import yaml
|
||||
import os
|
||||
|
||||
class Software:
|
||||
|
||||
def __init__(self, directory):
|
||||
|
||||
self.directory = directory
|
||||
self.info_file =
|
||||
if os.path.isfile(directory) and directory.endswith("meta.yaml"):
|
||||
directory = os.path.dirname(directory)
|
||||
|
||||
self.directory = directory
|
||||
self._load_from_yaml()
|
||||
|
||||
def _load_from_yaml(self):
|
||||
|
||||
fullpath = os.path.join(self.directory, "meta.yaml")
|
||||
self.info_file = fullpath
|
||||
with open(fullpath) as f:
|
||||
meta = yaml.load(f)
|
||||
|
||||
self.title = meta.get("title")
|
||||
self.genre = meta.get("genre")
|
||||
self.description = meta.get("description")
|
||||
self.dependencies = meta.get("dependencies")
|
||||
self.link_only = meta.get("link_only")
|
||||
self.link = meta.get("link")
|
||||
self.extra_files = meta.get("extra_files")
|
||||
|
||||
self.pictures = [os.path.join(self.directory, "pictures", p) for p in
|
||||
os.listdir(os.path.join(self.directory, "pictures"))]
|
||||
|
||||
def get_thumbnail(self):
|
||||
|
||||
return self.pictures[0]
|
||||
|
||||
|
||||
self.genre =
|
||||
self.title =
|
||||
self.description =
|
||||
self.dependencies =
|
||||
self.link_only =
|
||||
self.extra_files =
|
||||
|
||||
Reference in New Issue
Block a user