123 lines
3.3 KiB
Python
123 lines
3.3 KiB
Python
import gi
|
|
|
|
gi.require_version("Gtk", "4.0")
|
|
gi.require_version("Adw", "1")
|
|
from gi.repository import Adw, Gtk
|
|
|
|
|
|
class UserPage(Adw.Bin):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
clamp = Adw.Clamp()
|
|
clamp.set_maximum_size(500)
|
|
self.set_child(clamp)
|
|
|
|
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
|
box.set_spacing(24)
|
|
box.set_valign(Gtk.Align.CENTER)
|
|
box.set_margin_top(24)
|
|
box.set_margin_bottom(24)
|
|
clamp.set_child(box)
|
|
|
|
title = Gtk.Label(label="Create User Account")
|
|
title.add_css_class("title-1")
|
|
box.append(title)
|
|
|
|
# Form Group
|
|
group = Adw.PreferencesGroup()
|
|
box.append(group)
|
|
|
|
self.fullname_row = Adw.EntryRow()
|
|
self.fullname_row.set_title("Full Name")
|
|
self.fullname_row.set_text("Administrator")
|
|
self.fullname_row.connect("notify::text", self.on_fullname_changed)
|
|
group.add(self.fullname_row)
|
|
|
|
self.username_row = Adw.EntryRow()
|
|
self.username_row.set_title("Username")
|
|
self.username_row.set_text("admin")
|
|
self.username_handler_id = self.username_row.connect(
|
|
"notify::text", self.on_username_changed
|
|
)
|
|
group.add(self.username_row)
|
|
|
|
self.password_row = Adw.PasswordEntryRow()
|
|
self.password_row.set_title("Password")
|
|
group.add(self.password_row)
|
|
|
|
self.confirm_row = Adw.PasswordEntryRow()
|
|
self.confirm_row.set_title("Confirm Password")
|
|
group.add(self.confirm_row)
|
|
|
|
# Hostname
|
|
host_group = Adw.PreferencesGroup()
|
|
host_group.set_margin_top(12)
|
|
box.append(host_group)
|
|
|
|
self.hostname_row = Adw.EntryRow()
|
|
self.hostname_row.set_title("Hostname")
|
|
self.hostname_row.set_text("iridium")
|
|
host_group.add(self.hostname_row)
|
|
|
|
self.username_manually_set = False
|
|
|
|
def on_fullname_changed(self, entry, _pspec):
|
|
if self.username_manually_set:
|
|
return
|
|
|
|
username = entry.get_text().lower()
|
|
if username == "administrator":
|
|
username = "admin"
|
|
for sign in (
|
|
" ",
|
|
"-",
|
|
"_",
|
|
".",
|
|
",",
|
|
":",
|
|
";",
|
|
"!",
|
|
"?",
|
|
"/",
|
|
"\\",
|
|
"|",
|
|
"@",
|
|
"#",
|
|
"$",
|
|
"%",
|
|
"^",
|
|
"&",
|
|
"*",
|
|
"(",
|
|
")",
|
|
"[",
|
|
"]",
|
|
"{",
|
|
"}",
|
|
"'",
|
|
'"',
|
|
"`",
|
|
"~",
|
|
"<",
|
|
">",
|
|
"=",
|
|
"+",
|
|
):
|
|
username = username.replace(sign, "_")
|
|
|
|
self.username_row.handler_block(self.username_handler_id)
|
|
self.username_row.set_text(username)
|
|
self.username_row.handler_unblock(self.username_handler_id)
|
|
|
|
def on_username_changed(self, entry, _pspec):
|
|
self.username_manually_set = True
|
|
|
|
def get_user_info(self):
|
|
return {
|
|
"fullname": self.fullname_row.get_text(),
|
|
"username": self.username_row.get_text(),
|
|
"password": self.password_row.get_text(),
|
|
"hostname": self.hostname_row.get_text(),
|
|
}
|