-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
150 lines (119 loc) · 4.33 KB
/
Copy pathmain.py
File metadata and controls
150 lines (119 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# ================== BIBLIOTEKI ==================
import tkinter as tk
from tkinter import ttk, messagebox
import os
import sys
from paths import *
from config import *
from frames import WelcomeFrame, ConfigFrame, IntermediateFrame, EditorFrame, FinishFrame
# ================== APP ==================
class App(tk.Tk):
def __init__(self):
super().__init__()
# === ŁADOWANIE USTAWIEŃ I JĘZYKA ===
self.L = L
self.rarity = RARITY
self.types = TYPES
self.properties = PROPERTIES
self.theme = theme
self.settings = settings
self.theme = "light"
self.bg_light = "#ececec"
self.bg_dark = "#1b1b1b"
self.fg_btn_light = "#2C2C2C"
self.fg_btn_dark = "#E9E9E9"
self.bg_btn_light = "#C0C0C0"
self.bg_btn_dark = "#9B9B9B"
self.title(L["app.title"])
self.resizable(False, False)
# === CENTROWANIE OKNA ===
self.withdraw()
self.geometry(f"{WIN_W}x{WIN_H}")
self.update_idletasks()
w = self.winfo_width()
h = self.winfo_height()
sw = self.winfo_screenwidth()
sh = self.winfo_screenheight()
x = (sw - w) // 2
y = (sh - h) // 2
self.geometry(f"+{x}+{y}")
self.deiconify()
# === MENU ===
menubar = tk.Menu(self)
lang_menu = tk.Menu(menubar, tearoff=0)
self.available_langs = get_available_languages()
for lc in self.available_langs:
lang_menu.add_command(
label=lc.upper(),
command=lambda code=lc: self.change_language(code)
)
menubar.add_cascade(
label=L.get("menu.language", "Language"),
menu=lang_menu
)
menubar.add_command(
label=L["menu.advanced"],
command=self.advanced_action
)
menubar.add_command(
label=L["menu.info"],
command=self.show_info
)
self.config(menu=menubar)
# === INICJALIZACJA ZMIENNYCH ===
self.cards_total = 0
self.current_id = 1
self.current_frame_name = None
# === KONTENER NA FRAME'Y ===
container = ttk.Frame(self)
container.pack(fill="both", expand=True)
self.frames = {}
for F in (WelcomeFrame, IntermediateFrame, EditorFrame, FinishFrame, ConfigFrame):
frame = F(container, self)
self.frames[F.__name__] = frame
frame.place(relwidth=1, relheight=1)
self.show("WelcomeFrame")
# ====== IKONA APLIKACJI ======
try:
self.icon_image = tk.PhotoImage(file=ICON)
self.iconphoto(True, self.icon_image)
except Exception as e:
print(f"Nie udało się wczytać ikony: {e}")
# ================== ZARZĄDZANIE FRAME'AMI ==================
def show(self, frame_name):
frame = self.frames[frame_name]
frame.tkraise()
self.current_frame_name = frame_name
print_info(frame_name)
if hasattr(frame, "on_show"):
frame.on_show()
print(f"Funckja on_show() w {frame_name} została wywołana.")
# ================== AKCJE MENU ==================
def advanced_action(self):
current_frame = self.frames.get(self.current_frame_name)
print(f"Aktualny frame: {self.current_frame_name}")
if isinstance(current_frame, EditorFrame):
current_frame.show_advanced_window()
else:
messagebox.showinfo(
self.L["menu.advanced"],
self.L["advanced.unavailable"]
)
def show_info(self):
messagebox.showinfo(
self.L["menu.info"],
self.L["info.text"]
)
def change_language(self, lang_code):
"""Zapisuje język i restartuje aplikację"""
settings["lang"] = lang_code
save_settings(settings)
messagebox.showinfo(
self.L["lang.info"],
self.L["lang.restart"]
)
self.destroy()
os.execl(sys.executable, sys.executable, *sys.argv)
# ================== START ==================
if __name__ == "__main__":
App().mainloop()