Začetna verzija (avtor U. Urbanija)

This commit is contained in:
2026-03-04 20:18:24 +01:00
commit 79fa50fae4
4 changed files with 1231 additions and 0 deletions

377
nastavitve.py Normal file
View File

@@ -0,0 +1,377 @@
import tkinter as tk
import json
import os
import subprocess
import sys
DEFAULT_SETTINGS = {
"font_name": "Times New Roman",
"bg_color": "#000000",
"fg_color": "#FFFFFF",
"font_size": 32,
"screen_width_percent": 60,
"font_bold": True,
"show_song_info": True,
"split_by_stanza": True
}
SETTINGS_FILE = "settings.json"
if not os.path.exists(SETTINGS_FILE):
with open(SETTINGS_FILE, "w") as f:
json.dump(DEFAULT_SETTINGS, f, indent=4)
def load_settings():
with open(SETTINGS_FILE, "r") as f:
return json.load(f)
def save_settings(settings):
with open(SETTINGS_FILE, "w") as f:
json.dump(settings, f, indent=4)
def run_menu():
root = tk.Tk()
root.attributes("-fullscreen", True)
root.update_idletasks()
settings = load_settings()
def calculate_max_font_size():
screen_height = root.winfo_screenheight()
screen_width = root.winfo_screenwidth()
max_lines = 12
max_height_per_line = screen_height / max_lines
max_font_size = int(max_height_per_line * 0.8)
return min(max_font_size, settings["font_size"])
FONT_SIZE = calculate_max_font_size()
FONT = (settings["font_name"], FONT_SIZE, "bold" if settings.get("font_bold") else "normal")
root.lift()
root.attributes("-topmost", True)
root.after(100, lambda: root.attributes("-topmost", False))
root.configure(bg=settings["bg_color"])
screen_width = root.winfo_screenwidth()
left_right_width = int((100 - settings["screen_width_percent"]) / 2 * screen_width / 100)
left_block = tk.Frame(root, bg="black", width=left_right_width)
left_block.pack(side="left", fill="y")
right_block = tk.Frame(root, bg="black", width=left_right_width)
right_block.pack(side="right", fill="y")
frame = tk.Frame(root, bg=settings["bg_color"])
frame.pack(expand=True)
def restart_program():
python = sys.executable
subprocess.Popen([python] + sys.argv)
sys.exit()
def update_menu(options, title, callback):
for widget in frame.winfo_children():
widget.destroy()
title_label = tk.Label(frame, text=title, font=FONT, fg=settings["fg_color"], bg=settings["bg_color"])
title_label.pack(pady=(0, 20))
button_frame = tk.Frame(frame, bg=settings["bg_color"])
button_frame.pack()
wrap_length = screen_width * settings["screen_width_percent"] // 100
for key, text in options.items():
label = tk.Label(
button_frame,
text=f"{key}. {text}",
anchor="w",
font=FONT,
fg=settings["fg_color"],
bg=settings["bg_color"],
wraplength=wrap_length
)
label.pack(fill='x', anchor="w")
entry = tk.Entry(frame, font=FONT, justify='center', fg=settings["fg_color"], bg=settings["bg_color"],
insertbackground=settings["fg_color"])
entry.pack(pady=20)
def on_enter(event=None):
choice = entry.get()
callback(choice)
entry.bind("<Return>", on_enter)
root.after(100, entry.focus_set)
def keep_focus(entry_widget):
def refocus():
entry_widget.focus_set()
entry_widget.after(1000, refocus)
refocus()
keep_focus(entry)
def manual_input(prompt, setting_key):
for widget in frame.winfo_children():
widget.destroy()
label = tk.Label(frame, text=prompt, font=FONT, fg=settings["fg_color"], bg=settings["bg_color"])
label.pack(pady=10)
entry = tk.Entry(frame, font=FONT, justify='center', fg=settings["fg_color"], bg=settings["bg_color"],
insertbackground=settings["fg_color"])
entry.pack(pady=20)
def on_enter(event=None):
value = entry.get()
if setting_key in ["font_size", "screen_width_percent"]:
if value.isdigit():
settings[setting_key] = int(value)
else:
settings[setting_key] = value
save_settings(settings)
restart_program()
entry.bind("<Return>", on_enter)
root.after(100, entry.focus_set)
def keep_focus(entry_widget):
def refocus():
entry_widget.focus_set()
entry_widget.after(1000, refocus)
refocus()
keep_focus(entry)
def show_main_menu():
options = {
"1": "Spremeni pisavo",
"2": "Spremeni barvo ozadja",
"3": "Spremeni barvo črk",
"4": "Spremeni barvo ozadja in črk",
"5": "Spremeni velikost črk",
"6": "Spremeni odebeljenost pisave",
"7": "Prikaz številke in kitice",
"8": "Prikaz samostojne kitice",
"9": "Spremeni širino platna",
"10": "Zaženi projekcijo",
"11": "Zapri"
}
def handle_main_choice(choice):
if choice == "1":
show_font_menu()
elif choice == "2":
show_bg_menu()
elif choice == "3":
show_fg_menu()
elif choice == "4":
show_bg_fg_combo_menu()
elif choice == "5":
manual_input("Vnesi velikost pisave (številka):", "font_size")
elif choice == "6":
toggle_bold_choice()
elif choice == "7":
toggle_show_song_info()
elif choice == "8":
toggle_split_by_stanza()
elif choice == "9":
manual_input("Vnesi širino platna (v %):", "screen_width_percent")
elif choice == "10":
root.destroy()
subprocess.run(["python", "projector.py"])
elif choice == "11":
root.destroy()
update_menu(options, "Izberi možnost:", handle_main_choice)
def toggle_bold_choice():
options = {
"1": "Odebeljena pisava (Da)",
"2": "Odebeljena pisava (Ne)"
}
def handle_choice(choice):
if choice == "1":
settings["font_bold"] = True
elif choice == "2":
settings["font_bold"] = False
save_settings(settings)
restart_program()
update_menu(options, "Izberi možnost:", handle_choice)
def toggle_show_song_info():
options = {
"1": "Prikaz številke in kitice (Da)",
"2": "Prikaz številke in kitice (Ne)"
}
def handle_choice(choice):
if choice == "1":
settings["show_song_info"] = True
elif choice == "2":
settings["show_song_info"] = False
save_settings(settings)
restart_program()
update_menu(options, "Izberi možnost:", handle_choice)
def toggle_split_by_stanza():
options = {
"1": "Prelom po kiticah",
"2": "Prelom ob polnem platnu"
}
def handle_choice(choice):
if choice == "1":
settings["split_by_stanza"] = True
elif choice == "2":
settings["split_by_stanza"] = False
save_settings(settings)
restart_program()
update_menu(options, "Izberi način prikaza kitic:", handle_choice)
def show_font_menu():
fonts = {
"1": "Arial",
"2": "Calibri",
"3": "Times New Roman",
"4": "Verdana",
"5": "Georgia",
"6": "Helvetica",
"7": "Tahoma",
"8": "Trebuchet MS",
"9": "Courier New",
"10": "Comic Sans MS"
}
def set_font(choice):
if choice in fonts:
settings["font_name"] = fonts[choice]
save_settings(settings)
restart_program()
update_menu(fonts, "Izberi pisavo:", set_font)
def show_bg_menu():
current_fg = settings["fg_color"]
colors = {
"1": "črna",
"2": "bela",
"3": "rdeča",
"4": "zelena",
"5": "modra",
"6": "rumena",
"7": "cian",
"8": "magenta",
"9": "siva",
"10": "temno rdeča"
}
color_values = {
"črna": "#000000",
"bela": "#FFFFFF",
"rdeča": "#FF0000",
"zelena": "#00FF00",
"modra": "#0000FF",
"rumena": "#FFFF00",
"cian": "#00FFFF",
"magenta": "#FF00FF",
"siva": "#808080",
"temno rdeča": "#800000"
}
filtered_colors = {k: v for k, v in colors.items() if color_values.get(v, "") != current_fg}
def set_bg(choice):
if choice in filtered_colors:
settings["bg_color"] = color_values[filtered_colors[choice]]
save_settings(settings)
restart_program()
update_menu(filtered_colors, "Izberi barvo ozadja:", set_bg)
def show_fg_menu():
current_bg = settings["bg_color"]
colors = {
"1": "bela",
"2": "črna",
"3": "rdeča",
"4": "zelena",
"5": "modra",
"6": "rumena",
"7": "cian",
"8": "magenta",
"9": "siva",
"10": "temno rdeča"
}
color_values = {
"črna": "#000000",
"bela": "#FFFFFF",
"rdeča": "#FF0000",
"zelena": "#00FF00",
"modra": "#0000FF",
"rumena": "#FFFF00",
"cian": "#00FFFF",
"magenta": "#FF00FF",
"siva": "#808080",
"temno rdeča": "#800000"
}
filtered_colors = {k: v for k, v in colors.items() if color_values.get(v, "") != current_bg}
def set_fg(choice):
if choice in filtered_colors:
settings["fg_color"] = color_values[filtered_colors[choice]]
save_settings(settings)
restart_program()
update_menu(filtered_colors, "Izberi barvo črk:", set_fg)
def show_bg_fg_combo_menu():
combinations = {
"1": ("črna", "bela"),
"2": ("bela", "črna"),
"3": ("modra", "rumena"),
"4": ("temno rdeča", "bela"),
"5": ("zelena", "črna"),
"6": ("rdeča", "črna"),
"7": ("rumena", "črna"),
"8": ("črna", "rumena"),
"9": ("modra", "bela"),
"10": ("siva", "črna"),
}
color_values = {
"črna": "#000000",
"bela": "#FFFFFF",
"rdeča": "#FF0000",
"zelena": "#00FF00",
"modra": "#0000FF",
"rumena": "#FFFF00",
"cian": "#00FFFF",
"magenta": "#FF00FF",
"siva": "#808080",
"temno rdeča": "#800000"
}
def handle_combo_choice(choice):
if choice in combinations:
bg_name, fg_name = combinations[choice]
settings["bg_color"] = color_values[bg_name]
settings["fg_color"] = color_values[fg_name]
save_settings(settings)
restart_program()
options = {key: f"{bg} ozadje / {fg} črke" for key, (bg, fg) in combinations.items()}
update_menu(options, "Izberi kombinacijo barv:", handle_combo_choice)
show_main_menu()
root.mainloop()
if __name__ == "__main__":
run_menu()