-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploygui.py
More file actions
689 lines (549 loc) · 22.5 KB
/
deploygui.py
File metadata and controls
689 lines (549 loc) · 22.5 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
"""
CLS Software Installer (Unattended Setup)
----------------------------------------
GUI: customtkinter (Fluent-ish Windows 11 style)
Backend: PowerShell script (software_installer.ps1)
Build: PyInstaller --onefile
Features:
- 4 Profile (Presets)
- Keyboard navigation (1-4, Numpad 1-4, Up/Down, Enter)
- Status list + progress bar
- Readme button opens URL
- Clicking logo opens CLS website
- Footer: "Built by SD-ITLab" (klickbar)
- Auto-close 2s after completion
"""
from __future__ import annotations
import subprocess
import sys
import threading
import webbrowser
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import Dict, List, Set, Tuple
import tkinter as tk
from tkinter import messagebox
import customtkinter as ctk
try:
from PIL import Image
except ImportError:
Image = None
# =============================================================================
# Configuration (URLs, Colors, Static Text)
# =============================================================================
README_URL = "https://github.com/SD-ITLab/Silent-Software-Installer-Unattended-Script"
LOGO_URL = "https://sd-itlab.de"
BRAND_TEXT = "© 2026 SD-ITLab – MIT licensed"
BRAND_URL = "https://sd-itlab.de"
APP_TITLE = "SD-AppDeploy"
WINDOW_SIZE = "860x460"
AUTO_CLOSE_MS = 2000 # close 2s after finish
# --- Fluent-ish (Windows 11) Light Palette ---
BG_WINDOW = "#F3F4F6"
BG_CARD = "#FFFFFF"
BG_CARD_SELECTED = "#E7F1FF"
BORDER_CARD = "#E5E7EB"
BORDER_CARD_SELECTED = "#3B82F6"
BG_RIGHT_PANEL = "#EFF4FF"
TEXT_MUTED = "#6B7280"
ACCENT = "#3B82F6"
# =============================================================================
# Paths (PyInstaller-safe)
# =============================================================================
def exe_dir() -> Path:
"""Directory of the EXE (or script directory during debug)."""
if getattr(sys, "frozen", False):
return Path(sys.executable).resolve().parent
return Path(__file__).resolve().parent
def meipass_dir() -> Path:
"""PyInstaller temp dir (where --add-data files are extracted)."""
return Path(getattr(sys, "_MEIPASS", exe_dir())).resolve()
EXE_DIR: Path = exe_dir()
MEI_DIR: Path = meipass_dir()
def resource_path(filename: str) -> Path:
"""Return a file path for embedded resources (works in onefile EXE and debug)."""
return (MEI_DIR / filename).resolve()
# External, updateable folder next to EXE
FILES_DIR: Path = (EXE_DIR / "Files").resolve()
# Embedded assets/scripts
PS_INSTALLER: Path = resource_path("software_installer.ps1")
LOGO_PATH: Path = resource_path("logo.png")
ICON_PATH: Path = resource_path("icon.ico")
# =============================================================================
# Domain Model (Packages, Profiles, Status)
# =============================================================================
class UiState(Enum):
PENDING = "pending"
RUNNING = "running"
OK = "ok"
FAIL = "fail"
SKIP = "skip"
UI_STATUS_STYLE: Dict[UiState, Tuple[str, str]] = {
UiState.PENDING: ("•", TEXT_MUTED),
UiState.RUNNING: ("⏳", "#2563EB"),
UiState.OK: ("✔", "#16A34A"),
UiState.FAIL: ("✖", "#DC2626"),
UiState.SKIP: ("⏭", "#6B7280"),
}
class PsResult(Enum):
INSTALLED = "installed"
ALREADY = "already"
MISSING = "missing"
ERROR = "error"
PS_RESULT_TEXT: Dict[PsResult, str] = {
PsResult.INSTALLED: "Installiert",
PsResult.ALREADY: "Bereits installiert (übersprungen)",
PsResult.MISSING: "Übersprungen (Datei fehlt)",
PsResult.ERROR: "Fehler",
}
@dataclass(frozen=True)
class Package:
key: str
display_name: str
PACKAGE_ORDER: List[str] = ["firefox", "thunderbird", "chrome", "vlc", "adobe", "java"]
PACKAGES: Dict[str, Package] = {
"firefox": Package("firefox", "Mozilla Firefox"),
"thunderbird": Package("thunderbird", "Mozilla Thunderbird"),
"chrome": Package("chrome", "Google Chrome"),
"vlc": Package("vlc", "VLC Media Player"),
"adobe": Package("adobe", "Adobe Reader DC"),
"java": Package("java", "Java Environment 8"),
}
PROFILE_PACKAGES: Dict[int, Set[str]] = {
1: {"firefox", "thunderbird", "chrome", "vlc", "adobe"},
2: {"firefox", "chrome", "vlc", "adobe"},
3: {"firefox", "thunderbird", "chrome", "vlc", "adobe", "java"},
4: {"firefox", "chrome", "vlc", "adobe", "java"},
}
PROFILE_UI: List[Tuple[int, str, str]] = [
(1, "1: Unattended Installation – ohne Java",
"Installiert die Standard-Komponenten im Hintergrund. Java wird nicht installiert."),
(2, "2: Unattended Installation – ohne Java & Thunderbird",
"Minimal-Profil: ohne Java und ohne Mail-Client. Schnell & schlank."),
(3, "3: Unattended Installation – mit Java",
"Standard-Komponenten + Java Runtime (für Tools/Programme, die Java benötigen)."),
(4, "4: Unattended Installation – mit Java, aber ohne Thunderbird",
"Java ist dabei, Thunderbird wird übersprungen (z.B. wenn Outlook genutzt wird)."),
]
# =============================================================================
# PowerShell Runner
# =============================================================================
def run_powershell_installer(app_key: str) -> PsResult:
"""
Run the embedded PowerShell installer for a single package.
Returns a normalized status for UI.
"""
cmd = [
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy", "Bypass",
"-File", str(PS_INSTALLER),
"-App", app_key,
"-FilesDir", str(FILES_DIR),
]
# Hide PowerShell window
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
result = subprocess.run(
cmd,
cwd=str(EXE_DIR),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
startupinfo=si,
creationflags=subprocess.CREATE_NO_WINDOW,
)
out_lower = (result.stdout or "").lower()
err_lower = (result.stderr or "").lower()
if result.returncode == 0:
return PsResult.ALREADY if "bereits installiert" in out_lower else PsResult.INSTALLED
if "nicht gefunden" in out_lower or "nicht gefunden" in err_lower:
return PsResult.MISSING
return PsResult.ERROR
# =============================================================================
# UI Widgets
# =============================================================================
class RadioCard(ctk.CTkFrame):
"""Clickable card containing a radio button + title + subtitle."""
def __init__(
self,
master,
variable: tk.IntVar,
value: int,
title: str,
subtitle: str,
on_select=None,
corner_radius: int = 16,
):
super().__init__(master, fg_color=BG_CARD, corner_radius=corner_radius)
self.variable = variable
self.value = value
self.on_select = on_select
self.grid_columnconfigure(1, weight=1)
self.radio = ctk.CTkRadioButton(
self,
text="",
variable=self.variable,
value=self.value,
command=self._select,
width=18,
)
self.radio.grid(row=0, column=0, rowspan=2, padx=(12, 10), pady=8, sticky="n")
self.title_lbl = ctk.CTkLabel(
self,
text=title,
font=ctk.CTkFont(size=13, weight="bold"),
anchor="w",
)
self.title_lbl.grid(row=0, column=1, sticky="ew", padx=(0, 12), pady=(6, 0))
self.sub_lbl = ctk.CTkLabel(
self,
text=subtitle,
font=ctk.CTkFont(size=11),
text_color=TEXT_MUTED,
anchor="w",
justify="left",
wraplength=540,
)
self.sub_lbl.grid(row=1, column=1, sticky="ew", padx=(0, 12), pady=(0, 6))
# Entire card clickable
for w in (self, self.title_lbl, self.sub_lbl):
w.bind("<Button-1>", self._on_click)
# Update visuals on change
self._update_style(selected=(self.variable.get() == self.value))
self.variable.trace_add("write", lambda *_: self._update_style(self.variable.get() == self.value))
def _on_click(self, _event=None):
self.variable.set(self.value)
self._select()
def _select(self):
if callable(self.on_select):
self.on_select()
def _update_style(self, selected: bool):
# Border only when selected → weniger Artefakte an den Ecken
if selected:
self.configure(
fg_color=BG_CARD_SELECTED,
border_width=2,
border_color=BORDER_CARD_SELECTED,
)
else:
self.configure(
fg_color=BG_CARD,
border_width=0,
)
# =============================================================================
# Main App
# =============================================================================
class OnboardingInstallerApp(ctk.CTk):
def __init__(self):
super().__init__()
ctk.set_appearance_mode("light")
ctk.set_default_color_theme("blue")
self.title(APP_TITLE)
self.geometry(WINDOW_SIZE)
self.minsize(860, 460)
self.resizable(False, False)
self.configure(fg_color=BG_WINDOW)
self._installing = False
self._tk_icon_ref = None
self._set_window_icon()
self._build_layout()
self._bind_hotkeys()
self._render_package_list() # initial
# -------------------------------------------------------------------------
# Window / Icons / Links
# -------------------------------------------------------------------------
def _open_url(self, url: str):
try:
webbrowser.open(url, new=2)
except Exception as exc:
messagebox.showinfo("Info", f"Link konnte nicht geöffnet werden:\n{exc}")
def _set_window_icon(self):
"""Try to set window icon (top-left). EXE icon is handled by PyInstaller --icon."""
if not ICON_PATH.exists():
return
# iconbitmap ist der Standardweg unter Windows
try:
self.iconbitmap(str(ICON_PATH))
return
except Exception:
pass
# Fallback
try:
img = tk.PhotoImage(file=str(ICON_PATH))
self.iconphoto(True, img)
self._tk_icon_ref = img
except Exception:
pass
# -------------------------------------------------------------------------
# Layout
# -------------------------------------------------------------------------
def _build_layout(self):
self.grid_rowconfigure(0, weight=1)
self.grid_rowconfigure(1, weight=0)
self.grid_columnconfigure(0, weight=1)
# Main content
content = ctk.CTkFrame(self, corner_radius=0, fg_color=BG_WINDOW)
content.grid(row=0, column=0, sticky="nsew")
content.grid_rowconfigure(0, weight=1)
content.grid_columnconfigure(0, weight=1)
content.grid_columnconfigure(1, weight=0, minsize=320)
# Left
left = ctk.CTkFrame(content, fg_color=BG_WINDOW)
left.grid(row=0, column=0, sticky="nsew", padx=(16, 8), pady=10)
left.grid_columnconfigure(0, weight=1)
left.grid_rowconfigure(2, weight=1)
ctk.CTkLabel(
left,
text="Unattended Installation auswählen",
font=ctk.CTkFont(size=17, weight="bold"),
).grid(row=0, column=0, sticky="w", padx=4, pady=(4, 0))
ctk.CTkLabel(
left,
text="Wähle ein Profil, das festlegt, welche Programme automatisch installiert werden.",
font=ctk.CTkFont(size=11),
text_color=TEXT_MUTED,
justify="left",
).grid(row=1, column=0, sticky="w", padx=4, pady=(0, 8))
# Cards container
self.cards = ctk.CTkFrame(left, fg_color=BG_WINDOW)
self.cards.grid(row=2, column=0, sticky="nsew", padx=4, pady=(0, 6))
self.cards.grid_columnconfigure(0, weight=1)
self.profile_var = tk.IntVar(value=1)
for idx, title, sub in PROFILE_UI:
card = RadioCard(
self.cards,
variable=self.profile_var,
value=idx,
title=title,
subtitle=sub,
on_select=self._on_profile_change,
corner_radius=16,
)
card.grid(row=idx - 1, column=0, sticky="ew", pady=5)
# Right
right = ctk.CTkFrame(content, fg_color=BG_WINDOW)
right.grid(row=0, column=1, sticky="n", padx=(4, 16), pady=10)
logo_box = ctk.CTkFrame(
right,
fg_color=BG_RIGHT_PANEL,
corner_radius=18,
width=300,
height=160,
border_width=1,
border_color=BORDER_CARD,
)
logo_box.grid(row=0, column=0, sticky="n", padx=4, pady=(4, 6))
logo_box.grid_propagate(False)
self.logo_label = ctk.CTkLabel(logo_box, text="")
self.logo_label.place(relx=0.5, rely=0.5, anchor="center")
self.logo_label.configure(cursor="hand2")
self.logo_label.bind("<Button-1>", lambda e: self._open_url(LOGO_URL))
self._load_logo()
ctk.CTkLabel(
right,
text="Dieses Profil installiert:",
font=ctk.CTkFont(size=13, weight="bold"),
).grid(row=1, column=0, sticky="w", padx=6, pady=(4, 2))
self.package_frame = ctk.CTkFrame(right, fg_color="transparent")
self.package_frame.grid(row=2, column=0, sticky="w", padx=6, pady=(0, 6))
self.package_labels: Dict[str, ctk.CTkLabel] = {}
# Bottom
bottom = ctk.CTkFrame(self, corner_radius=0, fg_color=BG_WINDOW)
bottom.grid(row=1, column=0, sticky="ew")
bottom.grid_columnconfigure(0, weight=1)
bottom.grid_columnconfigure(1, weight=0)
bottom.grid_columnconfigure(2, weight=0)
bottom.grid_columnconfigure(3, weight=0)
bottom.grid_columnconfigure(4, weight=0)
self.progress = ctk.CTkProgressBar(
bottom, progress_color=ACCENT, fg_color="#E5E7EB", height=10, corner_radius=999
)
self.progress.grid(row=0, column=0, columnspan=5, sticky="ew", padx=16, pady=(8, 4))
self.progress.set(0.0)
self.status_lbl = ctk.CTkLabel(bottom, text="Bereit.", text_color=TEXT_MUTED)
self.status_lbl.grid(row=1, column=0, sticky="w", padx=16, pady=(0, 8))
# Branding links neben Readme
self.footer_brand = ctk.CTkLabel(
bottom,
text=BRAND_TEXT,
font=ctk.CTkFont(size=10),
text_color=TEXT_MUTED,
cursor="hand2",
)
self.footer_brand.grid(row=1, column=1, sticky="e", padx=(0, 12), pady=(0, 8))
self.footer_brand.bind("<Button-1>", lambda e: self._open_url(BRAND_URL))
self.footer_brand.bind("<Enter>", lambda e: self.footer_brand.configure(text_color=ACCENT))
self.footer_brand.bind("<Leave>", lambda e: self.footer_brand.configure(text_color=TEXT_MUTED))
self.btn_readme = ctk.CTkButton(bottom, text="Readme", width=100,
command=lambda: self._open_url(README_URL))
self.btn_readme.grid(row=1, column=2, padx=(0, 6), pady=(0, 8))
self.btn_install = ctk.CTkButton(bottom, text="Installieren", width=110,
command=self._on_install_clicked)
self.btn_install.grid(row=1, column=3, padx=6, pady=(0, 8))
self.btn_cancel = ctk.CTkButton(
bottom,
text="Abbrechen",
width=110,
fg_color=BG_CARD,
text_color="#111827",
hover_color="#E5E7EB",
border_width=1,
border_color="#D1D5DB",
command=self.destroy,
)
self.btn_cancel.grid(row=1, column=4, padx=(6, 16), pady=(0, 8))
def _load_logo(self):
if Image is None:
self.logo_label.configure(
text="(Pillow fehlt)\n`pip install pillow`",
text_color=TEXT_MUTED,
justify="center",
)
return
if not LOGO_PATH.exists():
self.logo_label.configure(
text="CLS-Logo\n(logo.png nicht gefunden)",
text_color=TEXT_MUTED,
justify="center",
)
return
img = Image.open(LOGO_PATH)
max_width, max_height = 260, 120
img_ratio = img.width / img.height
box_ratio = max_width / max_height
if img_ratio > box_ratio:
new_w = max_width
new_h = int(max_width / img_ratio)
else:
new_h = max_height
new_w = int(max_height * img_ratio)
img = img.resize((new_w, new_h), Image.LANCZOS)
self._logo_img = ctk.CTkImage(light_image=img, dark_image=img, size=(new_w, new_h))
self.logo_label.configure(image=self._logo_img, text="")
# -------------------------------------------------------------------------
# Profile / Packages
# -------------------------------------------------------------------------
def _on_profile_change(self):
if self._installing:
return
self._render_package_list()
def _render_package_list(self):
"""Render right-side package list based on selected profile."""
profile = self.profile_var.get()
pkg_set = PROFILE_PACKAGES.get(profile, set())
shown = [k for k in PACKAGE_ORDER if k in pkg_set]
for child in self.package_frame.winfo_children():
child.destroy()
self.package_labels.clear()
for row, key in enumerate(shown):
icon, color = UI_STATUS_STYLE[UiState.PENDING]
lbl = ctk.CTkLabel(
self.package_frame,
text=f"{icon} {PACKAGES[key].display_name}",
font=ctk.CTkFont(size=11),
text_color=color,
justify="left",
)
lbl.grid(row=row, column=0, sticky="w", pady=1)
self.package_labels[key] = lbl
self.status_lbl.configure(text="Bereit.")
self.progress.set(0.0)
self.btn_install.configure(text="Installieren", state="normal")
def _set_pkg_state(self, key: str, state: UiState):
if key not in self.package_labels:
return
icon, color = UI_STATUS_STYLE[state]
self.package_labels[key].configure(text=f"{icon} {PACKAGES[key].display_name}", text_color=color)
# -------------------------------------------------------------------------
# Install Flow
# -------------------------------------------------------------------------
def _on_install_clicked(self):
if self._installing:
return
self._start_install()
def _start_install(self):
if not PS_INSTALLER.exists():
messagebox.showerror("Fehler", f"PowerShell-Installer nicht gefunden:\n{PS_INSTALLER}")
return
self._installing = True
self.btn_install.configure(state="disabled")
self.btn_readme.configure(state="disabled")
self.status_lbl.configure(text="Installation läuft …")
self.progress.set(0.0)
threading.Thread(target=self._install_worker, daemon=True).start()
def _install_worker(self):
try:
profile = self.profile_var.get()
pkg_set = PROFILE_PACKAGES.get(profile, set())
queue = [k for k in PACKAGE_ORDER if k in pkg_set]
total = max(len(queue), 1)
# Set all pending
self.after(0, lambda: [self._set_pkg_state(k, UiState.PENDING) for k in queue])
for i, key in enumerate(queue, start=1):
name = PACKAGES[key].display_name
self.after(0, self._set_pkg_state, key, UiState.RUNNING)
self.after(0, self.status_lbl.configure, {"text": f"Installiere: {name} …"})
ps_result = run_powershell_installer(key)
if ps_result in (PsResult.INSTALLED, PsResult.ALREADY):
ui_state = UiState.OK
elif ps_result == PsResult.MISSING:
ui_state = UiState.SKIP
else:
ui_state = UiState.FAIL
self.after(0, self._set_pkg_state, key, ui_state)
self.after(
0,
self.status_lbl.configure,
{"text": f"{name}: {PS_RESULT_TEXT[ps_result]} ({i}/{total})"},
)
self.after(0, self.progress.set, i / total)
self.after(0, self._finish_success)
except Exception as exc:
self.after(0, self._finish_error, exc)
def _finish_success(self):
self.status_lbl.configure(text="Fertig ✅ (Unattended abgeschlossen)")
self._installing = False
self.after(AUTO_CLOSE_MS, self.destroy)
def _finish_error(self, exc: Exception):
self._installing = False
self.btn_install.configure(state="normal")
self.btn_readme.configure(state="normal")
self.status_lbl.configure(text="Fehler bei der Installation.")
messagebox.showerror("Fehler", f"Fehler bei der Installation:\n{exc}")
# -------------------------------------------------------------------------
# Hotkeys
# -------------------------------------------------------------------------
def _bind_hotkeys(self):
self.bind_all("<KeyPress>", self._on_key_press)
def _on_key_press(self, event: tk.Event):
keysym = event.keysym
# Numbers 1-4 (top row) + Numpad 1-4
map_num = {"1": 1, "2": 2, "3": 3, "4": 4, "KP_1": 1, "KP_2": 2, "KP_3": 3, "KP_4": 4}
if keysym in map_num:
self.profile_var.set(map_num[keysym])
self._on_profile_change()
return
# Up/Down navigation
if keysym in ("Up", "Down"):
profiles = [1, 2, 3, 4]
cur = self.profile_var.get()
idx = profiles.index(cur) if cur in profiles else 0
idx = max(0, idx - 1) if keysym == "Up" else min(len(profiles) - 1, idx + 1)
self.profile_var.set(profiles[idx])
self._on_profile_change()
return
# Enter => install
if keysym in ("Return", "KP_Enter"):
self._on_install_clicked()
return
# =============================================================================
# Entrypoint
# =============================================================================
def main():
app = OnboardingInstallerApp()
app.mainloop()
if __name__ == "__main__":
main()