3 # (C) 2019-2020 Fascode Network
6 import gi, subprocess, sys, threading
7 gi.require_version("Gtk", "3.0")
8 from gi.repository import GLib, Gtk, GObject
11 class MainWindow(Gtk.Window):
15 y = Gtk.RadioButton.new_with_label_from_widget(None, "Yes")
16 y.connect("toggled", self.on_button_toggled, name, True)
17 n = Gtk.RadioButton.new_with_mnemonic_from_widget(y, "No")
18 n.connect("toggled", self.on_button_toggled, name, False)
21 def combobox(name, list):
22 list_store = Gtk.ListStore(int, str)
23 for num in range(len(list)):
24 list_store.append([num, list[num]])
26 combo = Gtk.ComboBox.new_with_model_and_entry(list_store)
27 combo.connect("changed", self.on_combo_changed, name)
28 combo.set_entry_text_column(1)
33 Gtk.Window.__init__(self, title="build wizard")
36 self.bool = {"plymouth": True, "japanese": True}
37 self.selected = {"build": "native"}
41 sub_layout1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
44 label1 = Gtk.Label("select desktop environment")
45 label2 = Gtk.Label("select kernel")
48 de = combobox("de", ["xfce", "plasma", "lxde"])
49 kernel= combobox("kernel", ["zen", "linux", "lts", "lqx", "ck", "rt", "rt-lts", "xanmod-lts"])
52 for name in "plymouth", "japanese":
54 subs_layout = Gtk.Box(spacing=5)
55 subs_layout.pack_start(y, True, True, 30)
56 subs_layout.pack_start(n, True, True, 30)
57 label = Gtk.Label("Enable" + " " + name + "?")
58 sub_layout1.pack_start(label, True, True, 5)
59 sub_layout1.pack_start(subs_layout, True, True, 5)
62 for name in label1, de, label2, kernel:
63 sub_layout1.pack_start(name, True, True, 5)
67 sub_layout2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
70 label1 = Gtk.Label("select compression")
71 label2 = Gtk.Label("user name")
72 label3 = Gtk.Label("password")
75 comp = combobox("comp", ["zstd", "lzma", "lzo", "lz4", "xz", "gzip"])
78 self.usr = Gtk.Entry()
79 self.usr.set_text("alter")
80 self.passwd = Gtk.Entry()
81 self.passwd.set_visibility(False)
82 self.passwd.set_text("alter")
85 showpasswd = Gtk.ToggleButton("Show password")
86 showpasswd.connect("toggled", self.on_button_toggled, "1")
89 for name in label1, comp, label2, self.usr, label3, self.passwd, showpasswd:
90 sub_layout2.pack_start(name, True, True, 5)
94 sub_layout3 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
97 label = Gtk.Label("select build type")
100 button1 = Gtk.RadioButton.new_with_label_from_widget(None, "native")
101 button1.connect("toggled", self.select_build, "native")
104 sub_layout3.pack_start(label, True, True, 5)
105 sub_layout3.pack_start(button1, True, True, 5)
108 for name in "docker", "ssh":
109 button = Gtk.RadioButton.new_with_mnemonic_from_widget(button1, name)
110 button.connect("toggled", self.select_build, name)
111 sub_layout3.pack_start(button, True, True, 5)
115 grid = Gtk.Grid(column_spacing=10, row_spacing=10)
118 self.progressbar = Gtk.ProgressBar()
121 build = Gtk.Button("build")
122 build.connect("clicked", self.on_click_build)
125 grid.attach(sub_layout1, 0, 0, 1, 1)
126 grid.attach(sub_layout2, 1, 0, 1, 1)
127 grid.attach(sub_layout3, 2, 0, 1, 1)
128 grid.attach(self.progressbar, 0, 1, 2, 1)
129 grid.attach(build, 2, 1, 1, 1)
133 layout = Gtk.Box(spacing=10)
136 layout.pack_start(grid, True, True, 10)
140 main_layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
143 main_layout.pack_start(layout, True, True, 10)
145 #-- Add Main Window --#
146 self.add(main_layout)
148 def on_button_toggled(self, button, name):
149 if button.get_active():
150 self.passwd.set_visibility(True)
152 self.passwd.set_visibility(False)
154 def on_combo_changed(self, combo, name):
155 self.selected[name] = combo.get_model()[combo.get_active_iter()][1]
157 def select_build(self, button, name):
158 self.selected["build"] = name
160 def on_click_build(self, button):
161 cmd = ["sudo", "./build.sh"]
163 if self.selected["build"] == "native":
164 if self.bool["plymouth"]:
167 if self.bool["japanese"]:
170 for name in "-k", self.selected["kernel"], "-c", self.selected["comp"], "-u", self.usr.get_text(), "-p", self.passwd.get_text():
175 self.progressbar.set_show_text(1)
176 self.progressbar.set_text("not supported!")
177 print("not supported!")
179 def run_cmd(self, cmd):
181 self.progressbar.pulse()
182 self.progressbar.set_show_text(1)
183 self.progressbar.set_ellipsize(True)
184 self.progressbar.set_text(line)
188 run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
189 while run.poll() is None:
190 line = run.stdout.readline().decode('utf-8')
196 GLib.idle_add(update, line)
197 sys.stdout.write(line)
199 thread = threading.Thread(target=echo)
204 if __name__ == "__main__":
207 win.connect("destroy", Gtk.main_quit)