-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
335 lines (280 loc) · 12.2 KB
/
app.py
File metadata and controls
335 lines (280 loc) · 12.2 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import zoneinfo
import gi
import json
import os
gi.require_version('Gtk', '4.0')
from slides import InstallerSlide
from ui.welcome import welcome_slide
from ui.location import location_slide
from ui.keyboard import keyboard_slide
from ui.users import users_slide
from ui.desktop import desktop_slide
from ui.placeholder import placeholder_slide
from ui.partitions.partition_slide import partition_slide
from gi.repository import Gtk, GLib, Gdk
from ui.network import network_slide
from ui.summary import summary_slide
from ui.install import install_slide
import backend.data
class AlloyInstaller(Gtk.Application):
def __init__(self):
super().__init__(application_id="org.alloy.installer")
GLib.set_application_name('Alloy Installer')
self.current_slide = InstallerSlide.WELCOME
self.window = None
self.main_paned = None
self.sidebar = None
self.content_area = None
self.timezones = sorted(zoneinfo.available_timezones())
self.selected_timezone = "Europe/Amsterdam"
self.timezone_listbox = None
self.timezone_search = None
self.sidebar_buttons = {}
self.keyboard_layouts = self._load_keyboard_layouts("keyboard_layouts.json")
self.selected_keyboard = 'us'
self.keyboard_listbox = None
self.keyboard_search = None
self.selected_keyboard_display = None
self.selected_variant = None
css_provider = Gtk.CssProvider()
css_provider.load_from_path('style.css')
Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(),
css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
self.hostname = "alloy"
self.username = ""
self.user_password = ""
self.root_password = ""
self.selected_desktop = None
self.desktop_environments = ["Gnome", "KDE Plasma", "XFCE", "Cinnamon", "Cosmic", "LXQT", "Budgie", "MATE", "Deepin", "Pantheon", "No Desktop (tty)"]
self.selected_desktop = False
self.desktop_info = {
"Gnome": {
"image": "./content/gnome.svg",
"description": "GNOME offers a modern, simple, and distraction-free desktop. Great for newcomers and minimalists."
},
"KDE Plasma": {
"image": "./content/kde.svg",
"description": "KDE Plasma is a powerful, highly customizable desktop with advanced features and effects."
},
"XFCE": {
"image": "./content/xfce.svg",
"description": "XFCE is lightweight and fast, ideal for older systems or users who prefer performance over visuals."
},
"Cinnamon": {
"image": "./content/cinnamon.svg",
"description": "Cinnamon provides a traditional desktop layout. User-friendly and stable."
},
"Cosmic": {
"image": "./content/cosmic.svg",
"description": "COSMIC offers a modern and customizable user experience with an integrated tiling manager."
},
"LXQT": {
"image": "./content/lxqt.svg",
"description": "LXQt is a lightweight and fast desktop environment."
},
"Budgie": {
"image": "./content/budgie.svg",
"description": "Budgie is a modern and elegant desktop environment for Linux, focussing on minimalism, and user-friendliness."
},
"MATE": {
"image": "./content/mate.svg",
"description": "MATE is a classic-style desktop environment for Linux, continuing the traditional look and feel of the GNOME 2 interface."
},
"Deepin": {
"image": "./content/deepin.svg",
"description": "Deepin is a desktop environment providing a modern and polished look."
},
"Pantheon": {
"image": "./content/pantheon.svg",
"description": "Pantheon is a desktop environment that aims to be familiar to MacOS users."
},
"No Desktop (tty)": {
"image": "./content/tux.svg",
"description": "For those who want to install their own de/wm or use alloy on servers."
}
}
self.slide_save_callback = None
def do_activate(self):
self.window = Gtk.ApplicationWindow(
application=self,
title="Alloy Linux Installer",
default_width=800,
default_height=600
)
self.main_paned = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL)
self.sidebar = Gtk.Box(
orientation=Gtk.Orientation.VERTICAL,
spacing=10,
margin_start=10,
margin_end=10,
margin_top=10,
margin_bottom=10
)
self._build_sidebar()
self.content_area = Gtk.Box(
orientation=Gtk.Orientation.VERTICAL,
spacing=20,
margin_start=20,
margin_end=20,
margin_top=20,
margin_bottom=20
)
self.main_paned.set_start_child(self.sidebar)
self.main_paned.set_end_child(self.content_area)
self.main_paned.set_position(200)
self.window.set_child(self.main_paned)
self._update_content()
self.window.present()
def _build_sidebar(self):
header = Gtk.Label(label="Alloy Installer")
self.sidebar.append(header)
self.sidebar_buttons = {}
button_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
for slide in InstallerSlide:
btn = Gtk.Button(
label=slide.name.capitalize(),
halign=Gtk.Align.FILL,
hexpand=True
)
btn.connect('clicked', self._on_navigate, slide)
button_container.append(btn)
self.sidebar_buttons[slide] = btn
self.sidebar.append(button_container)
self._update_sidebar_styles()
def _update_content(self):
while self.content_area.get_first_child():
self.content_area.remove(self.content_area.get_first_child())
match self.current_slide:
case InstallerSlide.WELCOME:
welcome_slide(self.content_area, self._go_to_slide)
case InstallerSlide.NETWORK:
network_slide(self.content_area, self._go_to_slide)
case InstallerSlide.LOCATION:
location_slide(self.content_area, self._go_to_slide, self)
case InstallerSlide.KEYBOARD:
keyboard_slide(self.content_area, self._go_to_slide, self)
case InstallerSlide.PARTITIONING:
partition_slide(self.content_area, self._go_to_slide)
case InstallerSlide.USERS:
users_slide(self.content_area, self._go_to_slide, self)
case InstallerSlide.DESKTOP:
desktop_slide(self.content_area, self._go_to_slide, self)
case InstallerSlide.SUMMARY:
summary_slide(self.content_area, self._go_to_slide, self)
case InstallerSlide.INSTALL:
install_slide(self.content_area, self._go_to_slide, self)
case _:
placeholder_slide(self.content_area, self.current_slide.name)
# Time
def _populate_timezones(self, timezones):
while child := self.timezone_listbox.get_first_child():
self.timezone_listbox.remove(child)
for tz in timezones:
row = Gtk.ListBoxRow()
label = Gtk.Label(label=tz, halign=Gtk.Align.START, margin_start=10)
row.set_child(label)
self.timezone_listbox.append(row)
if tz == self.selected_timezone:
self.timezone_listbox.select_row(row)
def _on_search_changed(self, entry):
search_text = entry.get_text().lower()
if not search_text:
filtered = self.timezones
else:
filtered = [tz for tz in self.timezones if search_text in tz.lower()]
self._populate_timezones(filtered)
def _on_timezone_selected(self, listbox, row):
if row is not None:
label = row.get_child()
self.selected_timezone = label.get_text()
self.selected_display.set_text(self.selected_timezone)
# Keyboard
def _load_keyboard_layouts(self, filename):
try:
filepath = os.path.join(os.path.dirname(__file__), filename)
with open(filepath, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as e:
print(f"Error loading keyboard layouts: {e}")
return {}
def _populate_keyboards(self, layouts):
while child := self.keyboard_listbox.get_first_child():
self.keyboard_listbox.remove(child)
for layout in layouts:
row = Gtk.ListBoxRow()
label = Gtk.Label(label=layout, halign=Gtk.Align.START, margin_start=10)
row.set_child(label)
self.keyboard_listbox.append(row)
if layout == self.selected_keyboard:
self.keyboard_listbox.select_row(row)
def _on_keyboard_search_changed(self, entry):
search_text = entry.get_text().lower()
if not search_text:
filtered = self.keyboard_layouts
else:
filtered = [layout for layout in self.keyboard_layouts if search_text in layout.lower()]
self._populate_keyboards(filtered)
def _on_keyboard_selected(self, listbox, row):
if row:
layout = row.get_child().get_label()
self.selected_keyboard = layout
self.selected_keyboard_display.set_label(layout)
variants = self.keyboard_layouts.get(layout, [])
store = Gtk.StringList.new(variants)
self.variant_dropdown.set_model(store)
self.variant_dropdown.set_selected(0)
self.selected_variant = "default"
def _on_variant_selected(self, dropdown, _):
model = dropdown.get_model()
index = dropdown.get_selected()
if model and index >= 0:
self.selected_variant = model.get_string(index)
# Desktop
def _populate_desktops(self):
while child := self.desktop_listbox.get_first_child():
self.desktop_listbox.remove(child)
for de in self.desktop_environments:
row = Gtk.ListBoxRow()
label = Gtk.Label(label=de, halign=Gtk.Align.START, margin_start=10)
row.set_child(label)
self.desktop_listbox.append(row)
if self.selected_desktop not in self.desktop_environments:
self.selected_desktop = self.desktop_environments[0]
for row in self.desktop_listbox:
if row.get_child().get_label() == self.selected_desktop:
self.desktop_listbox.select_row(row)
break
def _on_desktop_selected(self, listbox, row):
if not row:
return
self.selected_desktop = row.get_child().get_label()
backend.data.desktop_environment = self.selected_desktop
if hasattr(self, 'desktop_image') and hasattr(self, 'desktop_description'):
info = self.desktop_info.get(self.selected_desktop, {})
image_path = info.get('image')
description = info.get('description')
if image_path:
self.desktop_image.set_from_file(image_path)
if description:
self.desktop_description.set_label(description)
def _on_navigate(self, button, slide):
self._go_to_slide(slide)
def _go_to_slide(self, slide):
if self.slide_save_callback:
try:
self.slide_save_callback()
except Exception as e:
print(f"Error saving data: {e}")
self.slide_save_callback = None
self.current_slide = slide
self._update_content()
self._update_sidebar_styles()
def _update_sidebar_styles(self):
for slide, button in self.sidebar_buttons.items():
if slide == self.current_slide:
button.add_css_class('suggested-action')
else:
button.remove_css_class('suggested-action')