-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
102 lines (79 loc) · 3.06 KB
/
app.py
File metadata and controls
102 lines (79 loc) · 3.06 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
import customtkinter as ctk
from tkinterdnd2 import TkinterDnD
import tkinter as tk
import os
import tempfile
from interface.LeftFrame import LeftFrame
from interface.RightFrame import RightFrame
from interface.utils import resource_path
# Configuration générale
ctk.set_appearance_mode("Light")
ctk.set_default_color_theme(resource_path("interface/themes/yellow.json"))
class App(TkinterDnD.Tk):
"""Fenêtre principale."""
def __init__(self):
super().__init__()
self.title("PixelToPath")
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
app_width = int(screen_width * 0.8)
app_height = int(screen_height * 0.8)
self.geometry(f"{app_width}x{app_height}+30+30")
# Création d'un répertoire temporaire pour l'application
self.app_temp_dir = os.path.join(tempfile.gettempdir(), "PixelToPath")
os.makedirs(self.app_temp_dir, exist_ok=True)
self.build_interface()
self.protocol("WM_DELETE_WINDOW", self.on_close)
def build_interface(self):
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
frame_principal = ctk.CTkFrame(self, fg_color="#ebebeb")
frame_principal.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)
frame_principal.columnconfigure(0, weight=0)
frame_principal.columnconfigure(1, weight=1)
frame_principal.rowconfigure(0, weight=1)
self.doc_frame = LeftFrame(frame_principal)
self.doc_frame.grid(row=0, column=0, sticky="ns", padx=(0, 10))
self.right_frame = RightFrame(
frame_principal,
app_temp_dir=self.app_temp_dir,
on_focus_toggle=self.toggle_focus_mode,
)
self.right_frame.grid(row=0, column=1, sticky="nsew")
self.right_frame.configure(fg_color="#ebebeb")
self._focus_mode = False
def toggle_focus_mode(self):
self._focus_mode = not self._focus_mode
if self._focus_mode:
self.doc_frame.grid_remove()
else:
self.doc_frame.grid()
def on_close(self):
# Nettoyer les fichiers temporaires
if os.path.exists(self.app_temp_dir):
for file in os.listdir(self.app_temp_dir):
path = os.path.join(self.app_temp_dir, file)
try:
os.remove(path)
except Exception as e:
print(f"Erreur suppression {path} : {e}")
try:
os.rmdir(self.app_temp_dir)
except OSError:
pass # Dossier non vide ou autre erreur
self.destroy() # Fermer la fenêtre
def get_scale():
root = tk.Tk()
dpi = root.winfo_fpixels('1i')
root.destroy()
return dpi / 96
if __name__ == "__main__":
scale = get_scale()
ctk.set_widget_scaling(scale)
ctk.set_window_scaling(scale)
app = App()
icon_path = resource_path("interface/assets/app_icon.png")
icon = tk.PhotoImage(file=icon_path)
app.iconphoto(True, icon)
app._icon = icon
app.mainloop()