PaganOS Luna 0.6.0
PL EN DE
🔒 Repository is read-only – file editing is disabled.

recipes/gui/pagan-mkiso/pagan-mkiso-gui.py main

116 lines Raw ← Back
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
#!/usr/bin/env python3
# =============================================================================
# pagan-mkiso-gui.py — prosty frontend GTK3 do /usr/bin/pagan-mkiso
# =============================================================================
# Uruchamiany przez `pagan-mkiso --gui` (przez pkexec z wpisu .desktop).
# Uruchamia budowę ISO w tle i strumieniuje log do okna.
import os
import shutil
import subprocess
import sys
import threading

try:
    import gi
    gi.require_version("Gtk", "3.0")
    from gi.repository import GLib, Gtk
except Exception as exc:  # brak GTK – poinformuj i wyjdź
    sys.stderr.write("pagan-mkiso-gui: brak GTK3 (%s)\n" % exc)
    sys.exit(1)


class MkIsoWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="Generator ISO Pagan")
        self.set_default_size(720, 480)
        self.set_border_width(10)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
        self.add(box)

        out_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        box.pack_start(out_row, False, False, 0)
        out_row.pack_start(Gtk.Label(label="Plik ISO:"), False, False, 0)
        default = os.path.join(GLib.get_home_dir(),
                               "Pagan-Linux-%s-live.iso" % GLib.DateTime.new_now_local().format("%Y.%m.%d"))
        self.out_entry = Gtk.Entry(text=default)
        out_row.pack_start(self.out_entry, True, True, 0)
        browse = Gtk.Button(label="Wybierz…")
        browse.connect("clicked", self.on_browse)
        out_row.pack_start(browse, False, False, 0)

        opts = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
        box.pack_start(opts, False, False, 0)
        self.chk_bios = Gtk.CheckButton(label="BIOS")
        self.chk_bios.set_active(True)
        self.chk_uefi = Gtk.CheckButton(label="UEFI")
        self.chk_uefi.set_active(True)
        opts.pack_start(self.chk_bios, False, False, 0)
        opts.pack_start(self.chk_uefi, False, False, 0)

        self.run_btn = Gtk.Button(label="Zbuduj ISO")
        self.run_btn.connect("clicked", self.on_run)
        box.pack_start(self.run_btn, False, False, 0)

        sw = Gtk.ScrolledWindow()
        box.pack_start(sw, True, True, 0)
        self.log = Gtk.TextView()
        self.log.set_editable(False)
        self.log.set_monospace(True)
        sw.add(self.log)

    def append(self, text):
        buf = self.log.get_buffer()
        buf.insert(buf.get_end_iter(), text)

    def on_browse(self, _btn):
        d = Gtk.FileChooserDialog(title="Zapisz ISO jako", parent=self,
                                  action=Gtk.FileChooserAction.SAVE)
        d.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                      Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
        d.set_do_overwrite_confirmation(True)
        d.set_current_name(os.path.basename(self.out_entry.get_text()))
        if d.run() == Gtk.ResponseType.OK:
            self.out_entry.set_text(d.get_filename())
        d.destroy()

    def on_run(self, _btn):
        self.run_btn.set_sensitive(False)
        out = self.out_entry.get_text().strip()
        cmd = ["/usr/bin/pagan-mkiso", "-y", "-o", out]
        if not self.chk_bios.get_active():
            cmd.append("--no-bios")
        if not self.chk_uefi.get_active():
            cmd.append("--no-uefi")
        self.append("$ %s\n" % " ".join(cmd))
        threading.Thread(target=self._run, args=(cmd,), daemon=True).start()

    def _run(self, cmd):
        try:
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT, text=True,
                                    errors="replace")
            for line in proc.stdout:
                GLib.idle_add(self.append, line)
            proc.wait()
            rc = proc.returncode
        except Exception as exc:
            GLib.idle_add(self.append, "BŁĄD: %s\n" % exc)
            rc = 1
        GLib.idle_add(self.append, "\n[zakończono, kod %s]\n" % rc)
        GLib.idle_add(self.run_btn.set_sensitive, True)


def main():
    if shutil.which("pagan-mkiso") is None:
        sys.stderr.write("pagan-mkiso-gui: brak /usr/bin/pagan-mkiso\n")
        return 1
    win = MkIsoWindow()
    win.connect("destroy", Gtk.main_quit)
    win.show_all()
    Gtk.main()
    return 0


if __name__ == "__main__":
    sys.exit(main())