from datetime import datetime from nicegui import ui, app from lib.users import * from lib.definitions import * from lib.web_ui import * from calendar import monthrange import hashlib import calendar import locale @ui.page('/touchscreen') def page_touchscreen(): if load_adminsettings()["touchscreen"]: def button_click(name): #nonlocal buttons current_user = user(name) current_user.timestamp() #if current_user.stamp_status() == status_in: # buttons[name].props('color=green') # ui.notify(status_in) #else: # buttons[name].props('color=red') # ui.notify(status_out) user_buttons.refresh() pageheader("Stempeluhr") ui.page_title("Stempeluhr") admin_settings = load_adminsettings() userlist = list_users() number_of_users = len(userlist) buttons = { } number_of_columns = 5 def set_columns(width): nonlocal number_of_columns if width > 1400: number_of_columns = 6 elif width > 1200: number_of_columns = 5 elif width > 900: number_of_columns = 4 elif width > 750: number_of_columns = 3 else: number_of_columns = 2 user_buttons.refresh() ui.on('resize', lambda e: set_columns(e.args['width'])) @ui.refreshable def user_buttons(): # Fenstergröße bestimmen und dann Spalten anpassen ui.add_head_html(''' ''') with ui.grid(columns=number_of_columns).classes('w-full center'): for name in userlist: current_user = user(name) current_button = ui.button(on_click=lambda name=name: button_click(name)).classes(f'w-md h-full min-h-[{admin_settings["button_height"]}px]') with current_button: with ui.grid(columns='1fr 1fr').classes('w-full h-full py-5 items-start'): if admin_settings["photos_on_touchscreen"]: image_size = int(admin_settings["picture_height"]) try: with open(current_user.photofile, 'r') as file: pass ui.image(current_user.photofile).classes(f'max-h-[{image_size}px]').props('fit=scale-down') except: no_photo_svg = f''' ''' ui.html(no_photo_svg) with ui.column().classes('' if admin_settings["photos_on_touchscreen"] else 'col-span-2'): ui.label(current_user.fullname).classes('text-left text-xl text.bold') if admin_settings["times_on_touchscreen"]: todays_timestamps = current_user.get_day_timestamps() # Wenn wir Einträge haben if len(todays_timestamps) > 0 and admin_settings["times_on_touchscreen"]: table_string = "" for i in range(0, len(todays_timestamps), 2): try: table_string += f"{datetime.datetime.fromtimestamp(todays_timestamps[i]).strftime('%H:%M')} - {datetime.datetime.fromtimestamp(todays_timestamps[i+1]).strftime('%H:%M')}" except IndexError: table_string += f"{datetime.datetime.fromtimestamp(todays_timestamps[i]).strftime('%H:%M')} -" if i < len(todays_timestamps) - 2: table_string += "\n" ui.label(table_string).style('white-space: pre-wrap').classes('text-left') if current_user.stamp_status() == status_in: current_button.props('color=green') else: current_button.props('color=red') buttons[name] = current_button user_buttons() else: pageheader("Interface deaktiviert")