-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler_ui.py
More file actions
167 lines (133 loc) · 8.18 KB
/
Copy pathcompiler_ui.py
File metadata and controls
167 lines (133 loc) · 8.18 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# compiler_ui.py
import tkinter as tk
from tkinter import filedialog, messagebox
import os
import sys
from pathlib import Path
from compiler_scanner import DependencyScanner
from compiler_builder import CompilerBuilder
def get_ide_base_path():
if getattr(sys, 'frozen', False): return sys._MEIPASS
return os.path.dirname(os.path.abspath(__file__))
class CompilerUI(tk.Toplevel):
def __init__(self, parent, target_file, python_path):
super().__init__(parent)
self.title("Gelişmiş Derleme Yöneticisi")
self.geometry("550x680")
self.resizable(False, True)
icon_path = os.path.join(get_ide_base_path(), "ikon1.ico")
if os.path.exists(icon_path):
self.iconbitmap(icon_path)
self.transient(parent)
self.bind("<Unmap>", self._on_unmap)
self.bind("<Map>", self._on_map)
self.grab_set()
self.target_file = target_file
self.python_path = python_path
self.app_name_var = tk.StringVar()
self.icon_path = tk.StringVar()
self.added_files = []
self.no_console_var = tk.BooleanVar(value=False)
self.create_setup_var = tk.BooleanVar(value=False)
self.setup_ui()
def _on_unmap(self, event):
if event.widget == self: self.grab_release()
def _on_map(self, event):
if event.widget == self: self.grab_set()
def setup_ui(self):
bg_color = "#333333"
self.configure(bg=bg_color)
style = {"bg": bg_color, "fg": "white", "font": ("Consolas", 10)}
tk.Label(self, text="Derlenecek Ana Dosya:", **style).pack(anchor="w", padx=10, pady=(10, 0))
lbl_file = tk.Label(self, text=os.path.basename(self.target_file) if self.target_file else "Seçili Dosya Yok! Önce kaydedin.", bg="#1E1F1C", fg="#A6E22E", font=("Consolas", 10, "bold"))
lbl_file.pack(fill=tk.X, padx=10, pady=5)
name_frame = tk.Frame(self, bg=bg_color)
name_frame.pack(fill=tk.X, padx=10, pady=(5, 5))
tk.Label(name_frame, text="Uygulama Adı:", **style).pack(side=tk.LEFT)
tk.Entry(name_frame, textvariable=self.app_name_var, bg="#1E1F1C", fg="white", insertbackground="white").pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(5,0))
icon_frame = tk.Frame(self, bg=bg_color)
icon_frame.pack(fill=tk.X, padx=10, pady=(5, 10))
tk.Label(icon_frame, text="Uygulama İkonu:", **style).pack(side=tk.LEFT)
tk.Entry(icon_frame, textvariable=self.icon_path, bg="#1E1F1C", fg="white", insertbackground="white").pack(side=tk.LEFT, fill=tk.X, expand=True, padx=(5,5))
tk.Button(icon_frame, text="Gözat", command=self.browse_icon, bg="#555555", fg="white", relief=tk.FLAT).pack(side=tk.LEFT)
tk.Checkbutton(self, text="Konsol Penceresini Gizle (--windowed)", variable=self.no_console_var, bg=bg_color, fg="white", selectcolor="#444444", activebackground=bg_color, activeforeground="white").pack(anchor="w", padx=10)
tk.Label(self, text="Ek Dosyalar (Resim, Veritabanı vb.):", **style).pack(anchor="w", padx=10, pady=(15, 0))
list_frame = tk.Frame(self, bg=bg_color)
list_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)
self.files_listbox = tk.Listbox(list_frame, bg="#1E1F1C", fg="white", selectbackground="#007ACC", height=5)
self.files_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
btn_frame = tk.Frame(list_frame, bg=bg_color)
btn_frame.pack(side=tk.RIGHT, fill=tk.Y, padx=(5,0))
tk.Button(btn_frame, text="Ekle", command=self.add_file, bg="#007ACC", fg="white", relief=tk.FLAT, width=8).pack(pady=(0,5))
tk.Button(btn_frame, text="Sil", command=self.remove_file, bg="#CC4444", fg="white", relief=tk.FLAT, width=8).pack()
tk.Checkbutton(self, text="📦 Setup Oluştur", variable=self.create_setup_var, command=self.toggle_setup_options, bg=bg_color, fg="#A6E22E", font=("Consolas", 12, "bold"), selectcolor="#444444", activebackground=bg_color, activeforeground="#A6E22E").pack(anchor="w", padx=10, pady=10)
self.setup_options_frame = tk.Frame(self, bg=bg_color)
tk.Label(self.setup_options_frame, text="Setup İçin Açıklama:", **style).pack(anchor="w")
self.setup_desc = tk.Text(self.setup_options_frame, height=4, bg="#1E1F1C", fg="white", insertbackground="white", font=("Consolas", 10))
self.setup_desc.pack(fill=tk.X, pady=5)
self.build_btn = tk.Button(self, text="⚙ OLUŞTUR", command=self.build, bg="#FD971F", fg="black", font=("Consolas", 14, "bold"), relief=tk.FLAT, pady=5)
self.build_btn.pack(fill=tk.X, side=tk.BOTTOM, padx=10, pady=10)
def toggle_setup_options(self):
if self.create_setup_var.get():
self.setup_options_frame.pack(fill=tk.X, padx=10, pady=5, before=self.build_btn)
else:
self.setup_options_frame.pack_forget()
def browse_icon(self):
path = filedialog.askopenfilename(filetypes=[("Görsel Dosyalar", "*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.ico"), ("Tüm Dosyalar", "*.*")])
if path: self.icon_path.set(path)
def add_file(self):
paths = filedialog.askopenfilenames(filetypes=[("Tüm Dosyalar", "*.*")])
for p in paths:
if p not in self.added_files:
self.added_files.append(p)
self.files_listbox.insert(tk.END, os.path.basename(p))
def remove_file(self):
selection = self.files_listbox.curselection()
if selection:
idx = selection[0]
self.files_listbox.delete(idx)
self.added_files.pop(idx)
def build(self):
if not self.target_file:
messagebox.showwarning("Uyarı", "Derlenecek dosya bulunamadı! Lütfen önce dosyanızı diske kaydedin.", parent=self)
return
final_icon_path = None
setup_icon_path = None
if self.icon_path.get():
try:
from PIL import Image
img_path = Path(self.icon_path.get())
target_dir = Path(self.target_file).parent
if img_path.suffix.lower() != '.ico':
ico_path = target_dir / (img_path.stem + "_converted.ico")
Image.open(img_path).convert("RGBA").save(ico_path, format="ICO", sizes=[(64, 64)])
final_icon_path = str(ico_path)
else:
final_icon_path = str(img_path)
png_path = target_dir / (img_path.stem + "_setup.png")
img_setup = Image.open(img_path).convert("RGBA")
img_setup.thumbnail((128, 128), Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS)
img_setup.save(png_path, format="PNG")
setup_icon_path = str(png_path)
except ImportError:
messagebox.showerror("Hata", "Görsel dönüştürme işlemi için 'Pillow' kütüphanesi eksik!\nLütfen kurun: pip install Pillow", parent=self)
return
except Exception as e:
messagebox.showerror("Hata", f"İkon dönüştürme sırasında hata oluştu:\n{e}", parent=self)
return
work_dir = os.path.dirname(self.target_file)
scanned_imports = DependencyScanner.scan(work_dir)
custom_app_name = self.app_name_var.get().strip()
setup_desc_text = self.setup_desc.get("1.0", tk.END).strip()
builder = CompilerBuilder(self.python_path, self)
builder.start_build(
target_file=self.target_file,
final_icon_path=final_icon_path,
setup_icon_path=setup_icon_path,
custom_app_name=custom_app_name,
no_console=self.no_console_var.get(),
added_files=self.added_files,
scanned_imports=scanned_imports,
create_setup=self.create_setup_var.get(),
setup_desc_text=setup_desc_text
)