wer kann mir helfen, ich dachte ich habe ein schön designedes Startfenster erstellt,
nur bekomme ich lauter Fehlermeldungen, die einzelnen script laufen alle wenn ich die direkt starte, kann mir jemand helfen?
#!/usr/bin/env python3
import gi
import subprocess
import threading
import os
import stat
import shutil
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, GdkPixbuf
# Diese Liste enthält die Programme/Skripte, die gestartet werden sollen.
# Jedes Tupel besteht aus:
# (Anzeigename, Skriptname, ist_void_installer, Icon-Pfad)
PROGRAMS = [
("Drucker-Treiber und Scanner-Programme installieren", "drucker_installer.py", False, "/usr/local/bin/icons/drucker.png"),
("Grafikkarten-Treiber installieren", "gpu.py", False, "/usr/local/bin/icons/gpu.png"),
("Grafik-Programme installieren", "grafik_installer.py", False, "/usr/local/bin/icons/drawing.jpg"),
("Internet-Programme installieren", "internet_installer.py", False, "/usr/local/bin/icons/internet.png"),
("Multimedia-Programme installieren", "multimedia_installer.py", False, "/usr/local/bin/icons/video.png"),
("Office-Programme installieren", "office_installer.py", False, "/usr/local/bin/icons/office.png"),
("System-Wartungs - Tools", "system.py", False, "/usr/local/bin/icons/system.jpg"),
("Virtuelle-Maschinen installieren", "vm_installer.py", False, "/usr/local/bin/icons/vm.png"),
("Gaming-Tools (Steam, Lutris usw.) installieren", "gaming.py", False, "/usr/local/bin/icons/gaming.png"),
("Void-Installer starten", "void-installer", True, "/usr/local/bin/icons/installer.png"),
]
class AllInstallersWindow(Gtk.Window):
def __init__(self):
super().__init__(title="🛠️ Treiber und Software Installation für Void Community Flavours")
self.set_border_width(10)
self.set_default_size(750, 550)
self.vbox = Gtk.VBox(spacing=10)
self.add(self.vbox)
self.status_label = Gtk.Label(label="Wähle deine Kategorie aus:")
self.vbox.pack_start(self.status_label, False, False, 0)
self.select_all_cb = Gtk.CheckButton(label="Alle auswählen / abwählen")
self.select_all_cb.connect("toggled", self.on_select_all_toggled)
self.vbox.pack_start(self.select_all_cb, False, False, 0)
self.dark_mode_switch = Gtk.Switch()
self.dark_mode_switch.set_active(False)
self.dark_mode_switch.connect("notify::active", self.on_dark_mode_toggled)
dark_mode_box = Gtk.HBox(spacing=10)
dark_mode_label = Gtk.Label(label="Dunkelmodus")
dark_mode_box.pack_start(dark_mode_label, False, False, 0)
dark_mode_box.pack_end(self.dark_mode_switch, False, False, 0)
self.vbox.pack_start(dark_mode_box, False, False, 0)
self.checkbuttons = []
self.program_list = PROGRAMS.copy()
for i, (name, script_name, is_void_installer, icon_path) in enumerate(self.program_list):
self.add_program_row(name, script_name, is_void_installer, icon_path)
if script_name == "void-installer":
separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
self.vbox.pack_start(separator, False, False, 5)
button_box = Gtk.HBox(spacing=10)
run_button = Gtk.Button(label="Ausführen")
run_button.connect("clicked", self.on_run_clicked)
button_box.pack_start(run_button, True, True, 0)
self.vbox.pack_start(button_box, False, False, 0)
self.output_view = Gtk.TextView()
self.output_view.set_editable(False)
self.output_view.set_cursor_visible(False)
self.output_buffer = self.output_view.get_buffer()
scroll = Gtk.ScrolledWindow()
scroll.set_min_content_height(200)
scroll.add(self.output_view)
self.vbox.pack_start(scroll, True, True, 0)
self.progress = Gtk.ProgressBar()
self.vbox.pack_start(self.progress, False, False, 0)
self.css_provider = Gtk.CssProvider()
self.style_context = Gtk.StyleContext()
self.screen = self.get_screen()
self.style_context.add_provider_for_screen(self.screen, self.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.update_start_buttons()
self.apply_theme(False)
def add_program_row(self, name, script_name, is_void_installer, icon_path):
hbox = Gtk.HBox(spacing=10)
try:
if os.path.isfile(icon_path):
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(icon_path, 42, 43, preserve_aspect_ratio=True)
icon = Gtk.Image.new_from_pixbuf(pixbuf)
else:
icon = Gtk.Image.new_from_icon_name("image-missing", Gtk.IconSize.BUTTON)
except Exception:
icon = Gtk.Image.new_from_icon_name("image-missing", Gtk.IconSize.BUTTON)
hbox.pack_start(icon, False, False, 0)
check = Gtk.CheckButton(label=f"{name}")
start_button = Gtk.Button(label="Ausführen")
start_button.set_sensitive(False)
start_button.connect("clicked", self.on_start_program, (script_name, is_void_installer))
hbox.pack_start(check, True, True, 0)
hbox.pack_start(start_button, False, False, 0)
if script_name == "void-installer":
remove_button = Gtk.Button(label="Entfernen")
remove_button.connect("clicked", self.on_remove_program, (name, script_name, is_void_installer, hbox))
hbox.pack_start(remove_button, False, False, 0)
self.vbox.pack_start(hbox, False, False, 0)
self.checkbuttons.append((check, script_name, is_void_installer, start_button, hbox))
self.vbox.show_all()
def on_remove_program(self, button, data):
name, script_name, is_void_installer, hbox = data
self.program_list = [p for p in self.program_list if p[:3] != (name, script_name, is_void_installer)]
self.checkbuttons = [(c, sn, iv, btn, hb) for c, sn, iv, btn, hb in self.checkbuttons if hb != hbox]
self.vbox.remove(hbox)
for child in self.vbox.get_children():
if isinstance(child, Gtk.Separator) and script_name == "void-installer":
self.vbox.remove(child)
break
GLib.idle_add(self.append_output, f"Eintrag '{name}' wurde aus der Liste entfernt.")
self.vbox.show_all()
def on_select_all_toggled(self, widget):
active = widget.get_active()
for check, *_ in self.checkbuttons:
check.set_active(active)
def on_run_clicked(self, widget):
selected = [(script_name, is_void_installer) for check, script_name, is_void_installer, _, _ in self.checkbuttons if check.get_active()]
if selected:
threading.Thread(target=self.run_commands, args=(selected,)).start()
def make_script_executable(self, script_path):
try:
if os.path.isfile(script_path):
current_mode = os.stat(script_path).st_mode
os.chmod(script_path, current_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
return True
return False
except Exception as e:
GLib.idle_add(self.append_output, f"⚠️ Fehler beim Setzen der Ausführrechte für {script_path}: {e}")
return False
def run_commands(self, scripts):
total = len(scripts)
if shutil.which("pkexec") is None:
GLib.idle_add(self.append_output, "⚠️ Fehler: 'pkexec' nicht gefunden. Bitte installiere policykit-1.")
return
for i, (script_name, is_void_installer) in enumerate(scripts):
GLib.idle_add(self.progress.set_fraction, i / total)
GLib.idle_add(self.append_output, f"Starte {script_name}...")
if is_void_installer:
cmd = ["pkexec", "void-installer"]
else:
script_path = os.path.join("/usr/local/bin/", script_name)
if self.make_script_executable(script_path):
cmd = ["pkexec", "/usr/bin/python3", script_path]
else:
GLib.idle_add(self.append_output, f"⚠️ Fehler: {script_name} nicht gefunden oder nicht ausführbar in /usr/local/bin/")
continue
try:
subprocess.Popen(cmd)
GLib.idle_add(self.append_output, f"✅ '{script_name}' wurde gestartet. Bitte beachte die Passwortabfrage.")
except Exception as e:
GLib.idle_add(self.append_output, f"⚠️ Fehler beim Starten von {script_name}: {e}")
GLib.idle_add(self.progress.set_fraction, 1.0)
GLib.idle_add(self.append_output, "\n✅ Alle Aktionen abgeschlossen.")
GLib.idle_add(self.show_completion_notification)
def show_completion_notification(self):
dialog = Gtk.MessageDialog(
parent=self,
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text="Ausführung abgeschlossen",
)
dialog.format_secondary_text("Alle ausgewählten Installer wurden gestartet.")
dialog.run()
dialog.destroy()
def append_output(self, text):
end_iter = self.output_buffer.get_end_iter()
self.output_buffer.insert(end_iter, text + "\n")
# Automatisch zur letzten Zeile scrollen
scroll_to_end = self.output_view.get_property("parent").get_vadjustment()
scroll_to_end.set_value(scroll_to_end.get_upper() - scroll_to_end.get_page_size())
def update_start_buttons(self):
for _, script_name, is_void_installer, button, _ in self.checkbuttons:
if is_void_installer:
button.set_sensitive(shutil.which("void-installer") is not None)
else:
script_path = os.path.join("/usr/local/bin/", script_name)
button.set_sensitive(os.path.isfile(script_path))
def on_start_program(self, button, data):
script_name, is_void_installer = data
if shutil.which("pkexec") is None:
GLib.idle_add(self.append_output, "⚠️ Fehler: 'pkexec' nicht gefunden. Bitte installiere policykit-1.")
return
GLib.idle_add(self.append_output, f"Starte '{script_name}'...")
if is_void_installer:
if shutil.which("void-installer") is None:
GLib.idle_add(self.append_output, f"⚠️ Fehler: void-installer nicht gefunden")
return
try:
subprocess.Popen(["pkexec", "void-installer"])
GLib.idle_add(self.append_output, f"✅ '{script_name}' wurde gestartet. Bitte beachte die Passwortabfrage.")
except Exception as e:
GLib.idle_add(self.append_output, f"⚠️ Fehler beim Starten von {script_name}: {e}")
else:
script_path = os.path.join("/usr/local/bin/", script_name)
if not os.path.isfile(script_path):
GLib.idle_add(self.append_output, f"⚠️ Fehler: {script_name} nicht gefunden in /usr/local/bin/")
return
if self.make_script_executable(script_path):
try:
subprocess.Popen(["pkexec", "/usr/bin/python3", script_path])
GLib.idle_add(self.append_output, f"✅ '{script_name}' wurde gestartet. Bitte beachte die Passwortabfrage.")
except Exception as e:
GLib.idle_add(self.append_output, f"⚠️ Fehler beim Starten von {script_name}: {e}")
else:
GLib.idle_add(self.append_output, f"⚠️ Fehler: {script_name} ist nicht ausführbar")
def on_dark_mode_toggled(self, switch, *args):
self.apply_theme(switch.get_active())
def apply_theme(self, dark_mode):
if dark_mode:
css = """
window, box, button, label, textview, progressbar {
background-color: #2e2e2e;
color: #ffffff;
}
textview text {
background-color: #2e2e2e;
color: #ffffff;
}
checkbutton check {
background-color: #ffffff;
color: #000000;
border: 1px solid #ffffff;
}
checkbutton:checked check {
background-color: #4CAF50;
color: #ffffff;
}
checkbutton label {
color: #ffffff;
}
"""
self.css_provider.load_from_data(css.encode())
else:
self.css_provider.load_from_data(b"")
# Starte GUI
win = AllInstallersWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
Alles anzeigen