Funktionen und UI Rewrites
This commit is contained in:
parent
af47d1857c
commit
40596dc0c6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,9 +2,20 @@
|
||||
#
|
||||
# statische Werte
|
||||
|
||||
userfolder = "users"
|
||||
settingsfolder = "settings"
|
||||
import os
|
||||
|
||||
# Quasi Konstanten:
|
||||
|
||||
scriptpath = os.path.dirname(os.path.abspath(__file__))
|
||||
suffix_userfolder = "users"
|
||||
suffix_settingsfolder = "settings"
|
||||
usersettingsfilename = "settings.json"
|
||||
photofilename = "photo.png"
|
||||
program_name = "Zeiterfassung"
|
||||
program_version = "Development"
|
||||
|
||||
status_in = "eingestempelt"
|
||||
status_out = "ausgestempelt"
|
||||
|
||||
userfolder = scriptpath + "/" + suffix_userfolder
|
||||
settingsfolder = scriptpath + "/" + suffix_settingsfolder
|
@ -42,9 +42,19 @@ def stempel_zustand(filename):
|
||||
if lines == 0:
|
||||
print(f"Keine Einträge")
|
||||
elif lines % 2 == 0:
|
||||
return("ausgestempelt")
|
||||
return(status_out)
|
||||
else:
|
||||
return("eingestempelt")
|
||||
return(status_in)
|
||||
|
||||
# Letzten Zeitstempel auswerten
|
||||
def get_last_2_timestmaps(filename):
|
||||
with open(filename, 'r') as file:
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
second_last_line = lines[-2]
|
||||
last_line = lines[-1]
|
||||
last_2_timestmaps = [second_last_line, last_line]
|
||||
return last_2_timestmaps
|
||||
|
||||
# Stempelübersicht zusammenstellen
|
||||
def overview(filename):
|
||||
|
72
ui.py
72
ui.py
@ -1,53 +1,85 @@
|
||||
# Zeiterfassung
|
||||
# UI
|
||||
from jeepney.low_level import padding
|
||||
|
||||
from definitions import *
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from tkinter import messagebox
|
||||
|
||||
from timestamping import append_timestamp, len_timestamps
|
||||
from time import strftime
|
||||
from timestamping import *
|
||||
from users import determine_filename
|
||||
import locale
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
def update_time():
|
||||
string_time = strftime('%A, der %d.%m.%Y - %H:%M:%S')
|
||||
global digital_clock
|
||||
digital_clock.config(text=string_time)
|
||||
digital_clock.after(1000, update_time)
|
||||
|
||||
def ui_stempeln(line_index, user):
|
||||
append_timestamp(determine_filename(user))
|
||||
|
||||
def ui_stempeln(button, label):
|
||||
append_timestamp(determine_filename(label))
|
||||
global buttons
|
||||
if len_timestamps(determine_filename(label)) % 2 == 0:
|
||||
buttons[button].configure(relief="raised", bg="red", text="ausgestempelt")
|
||||
global in_time_labels
|
||||
global out_time_labels
|
||||
|
||||
last_timestamps = get_last_2_timestmaps(determine_filename(user))
|
||||
|
||||
if stempel_zustand(determine_filename(user)) == status_out:
|
||||
buttons[line_index].configure(relief="raised", bg="red", text=user + "\n" + status_out)
|
||||
in_time_labels[line_index].configure(text=convert_timestamp(last_timestamps[0],"%H:%M"))
|
||||
out_time_labels[line_index].configure(text=convert_timestamp(last_timestamps[-1], "%H:%M"))
|
||||
elif stempel_zustand(determine_filename(user)) == status_in:
|
||||
buttons[line_index].configure(relief="sunken", bg="green", text=user + "\n" + status_in)
|
||||
in_time_labels[line_index].configure(text=convert_timestamp(last_timestamps[-1], "%H:%M"))
|
||||
out_time_labels[line_index].configure(text="")
|
||||
else:
|
||||
buttons[button].configure(relief="sunken", bg="green", text="eingestempelt")
|
||||
buttons[line_index].configure(bg="yellow", text="Fehler")
|
||||
|
||||
def win_stempeln(userlist):
|
||||
stempeln = tk.Tk()
|
||||
stempeln.title(program_name + " " + program_version)
|
||||
stempeln.geometry("600x400")
|
||||
#stempeln.geometry("600x400")
|
||||
stempeln.minsize(width=200, height=200)
|
||||
|
||||
global buttons
|
||||
global in_time_labels
|
||||
global out_time_labels
|
||||
global digital_clock
|
||||
|
||||
buttons = [ ]
|
||||
in_time_labels = [ ]
|
||||
out_time_labels = [ ]
|
||||
|
||||
button_index = 0
|
||||
|
||||
digital_clock = tk.Label(stempeln)
|
||||
digital_clock.grid(column=1, row=0)
|
||||
|
||||
update_time()
|
||||
|
||||
frame_stempeln = tk.Frame(stempeln, borderwidth=5, relief="ridge", padx=10, pady=10)
|
||||
frame_stempeln.grid(row=1, column=1)
|
||||
|
||||
tk.Label(frame_stempeln, text="Benutzer:", anchor="w", width=10).grid(row=0, column=1, sticky="w")
|
||||
tk.Label(frame_stempeln, text="Gekommen:").grid(row=0, column=2)
|
||||
tk.Label(frame_stempeln, text="Gegangen:").grid(row=0, column=3)
|
||||
|
||||
#Schleife zur Erzeugung von Stempelzeilen für User
|
||||
for i in userlist:
|
||||
label = tk.Label(frame_stempeln, text=i)
|
||||
button = tk.Button(frame_stempeln, command=lambda b=button_index, label=i: ui_stempeln(b, label))
|
||||
in_time = tk.Label(frame_stempeln, text="in", padx=10)
|
||||
button = tk.Button(frame_stempeln, height=3, compound="left", command=lambda b=button_index, user=i: ui_stempeln(b, user))
|
||||
in_time = tk.Label(frame_stempeln, padx=10)
|
||||
out_time = tk.Label(frame_stempeln, padx=10)
|
||||
if len_timestamps(determine_filename(i)) % 2 == 0:
|
||||
button.configure(relief="raised", bg ="red", text="ausgestempelt")
|
||||
button.configure(relief="raised", bg ="red", text=i + "\n" + status_out)
|
||||
else:
|
||||
button.configure(relief="sunken", bg="green", fg="white", text="eingestempelt")
|
||||
label.grid(row=button_index, column=0, sticky="w")
|
||||
button.grid(row=button_index, column=1, sticky="ew")
|
||||
in_time.grid(row=button_index, column=3, sticky="w")
|
||||
button.configure(relief="sunken", bg="green", text=i + "\n" + status_in)
|
||||
button.grid(row=button_index+1, column=1, sticky="ew")
|
||||
in_time.grid(row=button_index+1, column=2)
|
||||
out_time.grid(row=button_index+1, column=3)
|
||||
buttons.append(button)
|
||||
in_time_labels.append(in_time)
|
||||
out_time_labels.append(out_time)
|
||||
button_index+=1
|
||||
|
||||
stempeln.mainloop()
|
||||
|
23
users.py
23
users.py
@ -8,27 +8,20 @@ from definitions import *
|
||||
|
||||
# Benutzer anhand Verzeichnisse auflisten
|
||||
def list_users():
|
||||
directory = scriptpath() + "/" + userfolder
|
||||
users = [d for d in os.listdir(directory) if os.path.isdir(os.path.join(directory, d))]
|
||||
users = [d for d in os.listdir(userfolder) if os.path.isdir(os.path.join(userfolder, d))]
|
||||
return users
|
||||
|
||||
# Dateinamen bestimmen
|
||||
def determine_filename(user, type="stamping"):
|
||||
if type == "stamping":
|
||||
year = str(datetime.datetime.now().year)
|
||||
month = str(datetime.datetime.now().month)
|
||||
completepath = scriptpath() + "/" + userfolder +"/" + user + "/" + year + "-" + month + ".txt"
|
||||
completepath = userfolder + "/" + user + "/" + year + "-" + month + ".txt"
|
||||
return completepath
|
||||
|
||||
elif type == "settings":
|
||||
completepath = scriptpath() + "/" + userfolder +"/" + user + "/" + usersettingsfilename
|
||||
completepath = userfolder +"/" + user + "/" + usersettingsfilename
|
||||
return completepath
|
||||
elif type == "photo":
|
||||
completepath = userfolder + "/" + user + "/" + photofilename
|
||||
return completepath
|
||||
|
||||
# Benutzerliste anzeigen
|
||||
def printUserList():
|
||||
userlist = list_users()
|
||||
for i in range(0, len(userlist)):
|
||||
print(str(i + 1) + ": " + str(userlist[i]))
|
||||
return(userlist)
|
||||
|
||||
# Installationsverzeichnis bestimmen
|
||||
def scriptpath():
|
||||
return os.path.dirname(os.path.abspath(__file__))
|
||||
|
@ -80,3 +80,33 @@
|
||||
1744221947
|
||||
1744222133
|
||||
1744222135
|
||||
1744260500
|
||||
1744260507
|
||||
1744266057
|
||||
1744266059
|
||||
1744266162
|
||||
1744266164
|
||||
1744266742
|
||||
1744266745
|
||||
1744266778
|
||||
1744266779
|
||||
1744266990
|
||||
1744266993
|
||||
1744267045
|
||||
1744267050
|
||||
1744269810
|
||||
1744269812
|
||||
1744269823
|
||||
1744269829
|
||||
1744269915
|
||||
1744269919
|
||||
1744269921
|
||||
1744269922
|
||||
1744269957
|
||||
1744269959
|
||||
1744269961
|
||||
1744269971
|
||||
1744269973
|
||||
1744269974
|
||||
1744270075
|
||||
1744270081
|
||||
|
BIN
users/testuser/photo.jpg
Normal file
BIN
users/testuser/photo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 560 KiB |
BIN
users/testuser/photo.png
Normal file
BIN
users/testuser/photo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
@ -34,3 +34,35 @@
|
||||
1744222004
|
||||
1744222029
|
||||
1744222032
|
||||
1744259777
|
||||
1744259780
|
||||
1744260543
|
||||
1744260545
|
||||
1744266752
|
||||
1744266755
|
||||
1744266781
|
||||
1744266782
|
||||
1744268299
|
||||
1744268300
|
||||
1744269834
|
||||
1744269835
|
||||
1744269841
|
||||
1744269877
|
||||
1744269879
|
||||
1744269923
|
||||
1744269924
|
||||
1744269924
|
||||
1744269925
|
||||
1744269926
|
||||
1744269963
|
||||
1744269964
|
||||
1744269964
|
||||
1744269967
|
||||
1744269969
|
||||
1744269970
|
||||
1744269974
|
||||
1744269977
|
||||
1744269978
|
||||
1744269980
|
||||
1744270078
|
||||
1744270084
|
||||
|
BIN
users/testuser2/photo.jpg
Normal file
BIN
users/testuser2/photo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 550 KiB |
BIN
users/testuser2/photo.png
Normal file
BIN
users/testuser2/photo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
@ -14,36 +14,8 @@ from ui import *
|
||||
# Hauptfunktion
|
||||
def main():
|
||||
|
||||
userList = printUserList()
|
||||
userList = list_users()
|
||||
win_stempeln(userList)
|
||||
exit()
|
||||
|
||||
# Konsole
|
||||
while True:
|
||||
|
||||
print(program_name + " " + str(program_version))
|
||||
print("Welche Funktion soll ausgeführt werden?")
|
||||
print("1: Stempeln")
|
||||
print("2: Stempelübersicht anzeigen")
|
||||
print("0: Beenden")
|
||||
question = int(input("Geben Sie Ihre Antwort ein: "))
|
||||
|
||||
if question == 1:
|
||||
userlist = printUserList()
|
||||
which_user = input("Für welchen User soll gestempelt werden? ")
|
||||
append_timestamp(determine_filename(userlist[int(which_user) - 1]))
|
||||
print("Stempeleintrag vorgenommen")
|
||||
elif question == 2:
|
||||
userlist = printUserList()
|
||||
which_user = input("Für welchen User sollen die Stempelzeiten angezeigt werden? " )
|
||||
print("Zustand: " + stempel_zustand(determine_filename(userlist[int(which_user) -1])))
|
||||
overview(determine_filename(userlist[int(which_user) - 1]))
|
||||
|
||||
elif question == 0:
|
||||
exit()
|
||||
else:
|
||||
print("Keine Eingabe erkannt.")
|
||||
|
||||
|
||||
# Programmstart
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user