Skip to content

Commit 41057c0

Browse files
authored
Update main.py
1 parent b0e0f52 commit 41057c0

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

main.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,19 @@ class SecureAIPolicyGuardApp:
2020
def __init__(self, root: tk.Tk):
2121
self.root = root
2222

23-
# Sprache
2423
self.current_lang = "de"
2524
self.trans = LANG[self.current_lang]
2625

27-
# API-Mode
2826
self.api_mode_var = tk.BooleanVar(value=True)
2927
self.api_url_var = tk.StringVar(value="http://127.0.0.1:8000")
3028

31-
# AI-Animation
3229
self.scanning = False
3330
self.ai_after_id = None
3431
self.ai_rotation_angle = 0
3532
self.ai_spin_index = 0
36-
# werden aus localization geladen
3733
self.ai_labels = {"idle": "SECUREAI CORE", "active": "SECUREAI CORE – ACTIVE"}
3834
self.ai_spin = ["Analyzing …"]
3935

40-
# Detaildaten für jede Zeile: item_id -> {...}
4136
self.row_meta = {}
4237

4338
self.root.title(APP_TITLE)
@@ -50,7 +45,6 @@ def __init__(self, root: tk.Tk):
5045
self._apply_ai_language()
5146
self._draw_ai_core_idle()
5247

53-
# ----------------- THEME / STYLE -----------------
5448
def _setup_style(self):
5549
style = ttk.Style(self.root)
5650
try:
@@ -107,9 +101,7 @@ def _setup_style(self):
107101
"risk_crit": "#ff1744",
108102
}
109103

110-
# ----------------- UI Layout -----------------
111104
def _build_ui(self):
112-
# Top: Titel + AI-Core rechts
113105
top = ttk.Frame(self.root)
114106
top.pack(fill=tk.X, padx=10, pady=8)
115107

@@ -142,14 +134,12 @@ def _build_ui(self):
142134
)
143135
self.ai_status_label.pack(anchor="e", pady=(2, 0))
144136

145-
# Controls (Verzeichnis, API, Sprache, Links)
146137
ctrls = ttk.Frame(self.root)
147138
ctrls.pack(fill=tk.X, padx=10)
148139

149140
left_ctrls = ttk.Frame(ctrls)
150141
left_ctrls.pack(side=tk.LEFT, fill=tk.X, expand=True)
151142

152-
# Verzeichnis-Zeile
153143
dir_frame = ttk.Frame(left_ctrls)
154144
dir_frame.pack(fill=tk.X, pady=(0, 2))
155145

@@ -162,7 +152,6 @@ def _build_ui(self):
162152
self.btn_browse = ttk.Button(dir_frame, command=self.browse_directory)
163153
self.btn_browse.pack(side=tk.LEFT, padx=4)
164154

165-
# API-Zeile
166155
api_frame = ttk.Frame(left_ctrls)
167156
api_frame.pack(fill=tk.X, pady=(2, 0))
168157

@@ -178,7 +167,6 @@ def _build_ui(self):
178167
self.entry_api_url = ttk.Entry(api_frame, textvariable=self.api_url_var, width=40)
179168
self.entry_api_url.pack(side=tk.LEFT, padx=4)
180169

181-
# Rechts: Sprache + GitHub/Info
182170
right_ctrls = ttk.Frame(ctrls)
183171
right_ctrls.pack(side=tk.RIGHT)
184172

@@ -194,7 +182,6 @@ def _build_ui(self):
194182
self.btn_info = ttk.Button(right_ctrls, command=self.show_info)
195183
self.btn_info.pack(side=tk.RIGHT, padx=4)
196184

197-
# Scan-Button
198185
scan_frame = ttk.Frame(self.root)
199186
scan_frame.pack(fill=tk.X, padx=10, pady=(5, 5))
200187

@@ -205,7 +192,6 @@ def _build_ui(self):
205192
)
206193
self.btn_scan.pack(anchor="w")
207194

208-
# Panel mit Tabelle
209195
panel = ttk.Frame(self.root, style="Panel.TFrame")
210196
panel.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
211197

@@ -237,22 +223,19 @@ def _build_ui(self):
237223
self.tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
238224
vsb.pack(side=tk.RIGHT, fill=tk.Y)
239225

240-
# Risk-Farben
241226
self.tree.tag_configure("risk_low", foreground=self.colors["risk_low"])
242227
self.tree.tag_configure("risk_mid", foreground=self.colors["risk_mid"])
243228
self.tree.tag_configure("risk_high", foreground=self.colors["risk_high"])
244229
self.tree.tag_configure("risk_crit", foreground=self.colors["risk_crit"])
245230

246231
self.tree.bind("<Double-1>", self.show_details)
247232

248-
# Statusbar
249233
status_frame = ttk.Frame(self.root)
250234
status_frame.pack(fill=tk.X, padx=10, pady=5)
251235

252236
self.status_label = ttk.Label(status_frame, anchor="w")
253237
self.status_label.pack(fill=tk.X, expand=True)
254238

255-
# ----------------- Sprache -----------------
256239
def _apply_language(self):
257240
tr = self.trans
258241

@@ -299,7 +282,6 @@ def set_language(self, lang_code: str):
299282
self._apply_ai_language()
300283
self._draw_ai_core_idle()
301284

302-
# ----------------- AI-Animation -----------------
303285
def _draw_ai_core_idle(self):
304286
c = self.ai_canvas
305287
c.delete("all")
@@ -363,7 +345,6 @@ def _ai_animation_step(self):
363345
c.delete("all")
364346
cx, cy = 190, 45
365347

366-
# Label
367348
c.create_text(
368349
20,
369350
20,
@@ -373,7 +354,6 @@ def _ai_animation_step(self):
373354
font=("Consolas", 9, "bold"),
374355
)
375356

376-
# Rotierende Punkte
377357
radius = 38
378358
for i in range(10):
379359
angle = math.radians(self.ai_rotation_angle + i * 36)
@@ -388,7 +368,6 @@ def _ai_animation_step(self):
388368
outline="",
389369
)
390370

391-
# Innerer Kern
392371
c.create_oval(
393372
cx - 12,
394373
cy - 12,
@@ -399,7 +378,6 @@ def _ai_animation_step(self):
399378
width=1,
400379
)
401380

402-
# AI-Status (Spinner-Text)
403381
if self.ai_spin:
404382
spin_text = self.ai_spin[self.ai_spin_index % len(self.ai_spin)]
405383
self.ai_status_label.config(text=spin_text)
@@ -408,7 +386,6 @@ def _ai_animation_step(self):
408386
self.ai_rotation_angle = (self.ai_rotation_angle + 8) % 360
409387
self.ai_after_id = self.root.after(80, self._ai_animation_step)
410388

411-
# ----------------- Scan & Analyse -----------------
412389
def browse_directory(self):
413390
directory = filedialog.askdirectory()
414391
if directory:
@@ -428,7 +405,6 @@ def run_scan(self):
428405
messagebox.showwarning(tr["msg_no_dir_title"], tr["msg_no_dir_body"])
429406
return
430407

431-
# Reset
432408
for item in self.tree.get_children():
433409
self.tree.delete(item)
434410
self.row_meta.clear()
@@ -455,7 +431,6 @@ def run_scan(self):
455431
print(f"[WARN] Could not read file {full_path}: {e}")
456432
continue
457433

458-
# Analyse via API oder lokal
459434
use_api = self.api_mode_var.get()
460435
classification = None
461436
risk_score = 0
@@ -482,7 +457,6 @@ def run_scan(self):
482457

483458
policy = get_policy_for_decision(classification, risk_score, entities)
484459

485-
# Encryption / Aktion
486460
action = "NONE"
487461
if policy.get("encrypt"):
488462
target_dir = base_dir / policy["target_dir"]
@@ -497,7 +471,6 @@ def run_scan(self):
497471
elif policy.get("log_only"):
498472
action = "LOG_ONLY"
499473

500-
# Logging
501474
log_action(
502475
conn,
503476
str(full_path),
@@ -508,7 +481,6 @@ def run_scan(self):
508481
"",
509482
)
510483

511-
# Darstellung
512484
tag = self._tag_for_risk(risk_score)
513485
class_label = tr.get(f"classification_{classification}", classification)
514486
action_label = tr.get(f"action_{action}", action)
@@ -552,7 +524,6 @@ def _tag_for_risk(self, score: int) -> str:
552524
return "risk_high"
553525
return "risk_crit"
554526

555-
# ----------------- Detail-Dialog -----------------
556527
def show_details(self, event):
557528
tr = self.trans
558529
item_id = self.tree.identify_row(event.y)
@@ -601,20 +572,17 @@ def show_details(self, event):
601572

602573
messagebox.showinfo(tr["detail_title"], detail_text)
603574

604-
# ----------------- Info & Links -----------------
605575
def show_info(self):
606576
tr = self.trans
607577
messagebox.showinfo(tr["info_title"], tr["info_body"])
608578

609579
def open_github(self):
610580
webbrowser.open(GITHUB_URL)
611581

612-
613582
def main():
614583
root = tk.Tk()
615584
app = SecureAIPolicyGuardApp(root)
616585
root.mainloop()
617586

618-
619587
if __name__ == "__main__":
620-
main()
588+
main()

0 commit comments

Comments
 (0)