← recipes

Commit 753aa043

2
files
+119
added
-0
deleted
@@ -23,3 +23,6 @@ __pycache__/
23 23
24 24 # Logi
25 25 *.log
26 +
27 +# Dozwolone pliki .py w recepturach (recipes .gitignore ma *.py):
28 +!gui/pagan-mkiso/pagan-mkiso-gui.py
26 29 new file mode 100644
@@ -0,0 +1,116 @@
1 +#!/usr/bin/env python3
2 +# =============================================================================
3 +# pagan-mkiso-gui.py — prosty frontend GTK3 do /usr/bin/pagan-mkiso
4 +# =============================================================================
5 +# Uruchamiany przez `pagan-mkiso --gui` (przez pkexec z wpisu .desktop).
6 +# Uruchamia budowę ISO w tle i strumieniuje log do okna.
7 +import os
8 +import shutil
9 +import subprocess
10 +import sys
11 +import threading
12 +
13 +try:
14 + import gi
15 + gi.require_version("Gtk", "3.0")
16 + from gi.repository import GLib, Gtk
17 +except Exception as exc: # brak GTK – poinformuj i wyjdź
18 + sys.stderr.write("pagan-mkiso-gui: brak GTK3 (%s)\n" % exc)
19 + sys.exit(1)
20 +
21 +
22 +class MkIsoWindow(Gtk.Window):
23 + def __init__(self):
24 + super().__init__(title="Generator ISO Pagan")
25 + self.set_default_size(720, 480)
26 + self.set_border_width(10)
27 +
28 + box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
29 + self.add(box)
30 +
31 + out_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
32 + box.pack_start(out_row, False, False, 0)
33 + out_row.pack_start(Gtk.Label(label="Plik ISO:"), False, False, 0)
34 + default = os.path.join(GLib.get_home_dir(),
35 + "Pagan-Linux-%s-live.iso" % GLib.DateTime.new_now_local().format("%Y.%m.%d"))
36 + self.out_entry = Gtk.Entry(text=default)
37 + out_row.pack_start(self.out_entry, True, True, 0)
38 + browse = Gtk.Button(label="Wybierz…")
39 + browse.connect("clicked", self.on_browse)
40 + out_row.pack_start(browse, False, False, 0)
41 +
42 + opts = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
43 + box.pack_start(opts, False, False, 0)
44 + self.chk_bios = Gtk.CheckButton(label="BIOS")
45 + self.chk_bios.set_active(True)
46 + self.chk_uefi = Gtk.CheckButton(label="UEFI")
47 + self.chk_uefi.set_active(True)
48 + opts.pack_start(self.chk_bios, False, False, 0)
49 + opts.pack_start(self.chk_uefi, False, False, 0)
50 +
51 + self.run_btn = Gtk.Button(label="Zbuduj ISO")
52 + self.run_btn.connect("clicked", self.on_run)
53 + box.pack_start(self.run_btn, False, False, 0)
54 +
55 + sw = Gtk.ScrolledWindow()
56 + box.pack_start(sw, True, True, 0)
57 + self.log = Gtk.TextView()
58 + self.log.set_editable(False)
59 + self.log.set_monospace(True)
60 + sw.add(self.log)
61 +
62 + def append(self, text):
63 + buf = self.log.get_buffer()
64 + buf.insert(buf.get_end_iter(), text)
65 +
66 + def on_browse(self, _btn):
67 + d = Gtk.FileChooserDialog(title="Zapisz ISO jako", parent=self,
68 + action=Gtk.FileChooserAction.SAVE)
69 + d.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
70 + Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
71 + d.set_do_overwrite_confirmation(True)
72 + d.set_current_name(os.path.basename(self.out_entry.get_text()))
73 + if d.run() == Gtk.ResponseType.OK:
74 + self.out_entry.set_text(d.get_filename())
75 + d.destroy()
76 +
77 + def on_run(self, _btn):
78 + self.run_btn.set_sensitive(False)
79 + out = self.out_entry.get_text().strip()
80 + cmd = ["/usr/bin/pagan-mkiso", "-y", "-o", out]
81 + if not self.chk_bios.get_active():
82 + cmd.append("--no-bios")
83 + if not self.chk_uefi.get_active():
84 + cmd.append("--no-uefi")
85 + self.append("$ %s\n" % " ".join(cmd))
86 + threading.Thread(target=self._run, args=(cmd,), daemon=True).start()
87 +
88 + def _run(self, cmd):
89 + try:
90 + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
91 + stderr=subprocess.STDOUT, text=True,
92 + errors="replace")
93 + for line in proc.stdout:
94 + GLib.idle_add(self.append, line)
95 + proc.wait()
96 + rc = proc.returncode
97 + except Exception as exc:
98 + GLib.idle_add(self.append, "BŁĄD: %s\n" % exc)
99 + rc = 1
100 + GLib.idle_add(self.append, "\n[zakończono, kod %s]\n" % rc)
101 + GLib.idle_add(self.run_btn.set_sensitive, True)
102 +
103 +
104 +def main():
105 + if shutil.which("pagan-mkiso") is None:
106 + sys.stderr.write("pagan-mkiso-gui: brak /usr/bin/pagan-mkiso\n")
107 + return 1
108 + win = MkIsoWindow()
109 + win.connect("destroy", Gtk.main_quit)
110 + win.show_all()
111 + Gtk.main()
112 + return 0
113 +
114 +
115 +if __name__ == "__main__":
116 + sys.exit(main())