-
Notifications
You must be signed in to change notification settings - Fork 0
/
serene-setupwizard.py
154 lines (130 loc) · 4.92 KB
/
serene-setupwizard.py
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
#!/usr/bin/env python3
#== Import ==#
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import configparser
import json
import subprocess
#== Function ==#
def go(num):
num = str(num)
select_window(num)
def run_command(command):
command = command.split()
result = subprocess.run(command, stdout=subprocess.PIPE, stderr = subprocess.DEVNULL)
return result.stdout.decode("utf8")
#== Selct Window ==#
def select_window(num):
class SelectWindow(Gtk.Window):
#= __init__ Function =#
def __init__(self):
#-- Create Window --#
Gtk.Window.__init__(self, title="Serene Setup Wizard")
self.selected = []
#-- Define lauouts --#
sub_layout_1 = Gtk.Box(spacing=10)
sub_layout_2 = Gtk.Box(spacing=10)
main_layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
#-- Generate icons & buttons --#
for name in select_list:
#- Generate icon --#
icon_list = Gtk.ListStore(Pixbuf)
pixbuf = Gtk.IconTheme.get_default().load_icon(name, 90, 0)
icon_list.append([pixbuf])
icon = Gtk.IconView.new()
icon.set_model(icon_list)
icon.set_text_column(-1)
icon.set_pixbuf_column(0)
icon.set_selection_mode(0)
#- Geneate Button -#
button = Gtk.ToggleButton(name)
button.connect("toggled", self.on_button_toggled, name)
try:
if name in selected[num]:
button.set_active(True)
except:
pass
#- Define layout -#
layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
#- Add layout -#
layout.pack_start(icon, True, True, 0)
layout.pack_start(button, True, True, 0)
#- Add sub layout 1 -#
sub_layout_1.pack_start(layout, True, True, 10)
#-- Generate Label --#
#- desc label -#
desc_label = Gtk.Label()
desc_label.set_markup("\n\n<big><b>" + desc + "</b></big>")
desc_label.set_line_wrap(True)
#- copyright
copyright_label = Gtk.Label()
copyright_label.set_markup("<small>Copyright (C) 2019-2020 FascodeNetwork</small>")
#-- Generate Button --#
#- back button -#
if not number == 0:
back = Gtk.Button("前へ")
back.connect("clicked", self.back)
if not str(number + 1) in config.options("desc"):
#- next button -#
next = Gtk.Button("終了")
next.connect("clicked", self.end)
else:
#- end button -#
next = Gtk.Button("次へ")
next.connect("clicked", self.next)
#-- Add sub layout 2 --#
if not number == 0:
sub_layout_2.pack_start(back, True, True, 10)
sub_layout_2.pack_start(next, True, True, 10)
#- Add main layout -#
main_layout.pack_start(desc_label, True, True, 0)
main_layout.pack_start(sub_layout_1, True, True, 0)
main_layout.pack_start(sub_layout_2, True, True, 0)
main_layout.pack_start(copyright_label, True, True, 10)
#-- Show main layout --#
self.add(main_layout)
#= Button Function =#
#-- toggle button --#
def on_button_toggled(self, button, name):
if button.get_active():
self.selected.append(name)
else:
self.selected.remove(name)
#-- next button -#
def next(self, button):
selected[num] = self.selected
self.close()
go(number+1)
#-- back button -#
def back(self, button):
selected[num] = self.selected
self.close()
go(number-1)
#-- end button --#
def end(self, button):
selected[num] = self.selected
install_list = []
self.close()
Gtk.main_quit()
for key in range(len(config.options("desc"))):
install_list += selected[str(key)]
print(install_list)
#= Define =#
desc = config.get("desc", num)
number = int(num)
select_list = []
select_list = json.loads(config.get("pkg", num))
#= Run =#
win = SelectWindow()
win.show_all()
win.connect("destroy", Gtk.main_quit)
Gtk.main()
#== Run ==#
if __name__ == "__main__":
global selected
selected = {}
config = configparser.ConfigParser()
config.read('serene-setupwizard.conf')
select_window("0")