Add badly made settings page
This commit is contained in:
parent
6681ab4cf3
commit
5616173290
5 changed files with 87 additions and 13 deletions
|
@ -11,6 +11,7 @@ grade = [
|
|||
defconf = {
|
||||
'isLogged': False,
|
||||
'language': 'pl',
|
||||
'themecolor': 'PINK'
|
||||
}
|
||||
|
||||
usrconf = {
|
||||
|
|
|
@ -9,7 +9,7 @@ import os
|
|||
try:
|
||||
config = configparser.ConfigParser()
|
||||
config.read(f"{getconfigpath()}/config.ini")
|
||||
lang = config["DEFAULT"]["language"]
|
||||
lang = config["Settings"]["language"]
|
||||
except FileNotFoundError:
|
||||
lang = "pl"
|
||||
print("Defaulting to Polish due to missing config file")
|
||||
|
|
11
src/main.py
11
src/main.py
|
@ -51,7 +51,7 @@ def main(page: ft.Page):
|
|||
# Page settings
|
||||
page.title = "Fuji"
|
||||
page.theme = ft.Theme(
|
||||
color_scheme_seed=ft.Colors.RED,
|
||||
color_scheme_seed=getattr(ft.Colors, getthemecolor()),
|
||||
font_family="Roboto",
|
||||
page_transitions=ft.PageTransitionsTheme(
|
||||
macos=ft.PageTransitionTheme.NONE,
|
||||
|
@ -121,7 +121,6 @@ def main(page: ft.Page):
|
|||
page.on_route_change = on_route_change
|
||||
page.go("/")
|
||||
|
||||
|
||||
def login(page: ft.Page):
|
||||
# Page settings
|
||||
page.title = "Log in"
|
||||
|
@ -186,7 +185,7 @@ def login(page: ft.Page):
|
|||
saveauth("Fuji", "Auth Context", jsoncontext)
|
||||
|
||||
config.read(f"{getconfigpath()}/config.ini")
|
||||
config['DEFAULT']['isLogged'] = 'True'
|
||||
config['Settings']['isLogged'] = 'True'
|
||||
config['User']['fullName'] = students[selected_index].full_name
|
||||
config['User']['grade'] = students[selected_index].class_name
|
||||
|
||||
|
@ -356,7 +355,7 @@ if __name__ == "__main__":
|
|||
try:
|
||||
config.read(f"{getconfigpath()}/config.ini")
|
||||
|
||||
isLogged = config['DEFAULT']['isLogged']
|
||||
isLogged = config['Settings']['isLogged']
|
||||
|
||||
match isLogged:
|
||||
case 'True':
|
||||
|
@ -366,7 +365,7 @@ if __name__ == "__main__":
|
|||
|
||||
except (FileNotFoundError, KeyError):
|
||||
os.makedirs(getconfigpath())
|
||||
config['DEFAULT'] = defconf
|
||||
config['Settings'] = defconf
|
||||
config['User'] = usrconf
|
||||
|
||||
with open(f"{getconfigpath()}/config.ini", "w") as file:
|
||||
|
@ -374,7 +373,7 @@ if __name__ == "__main__":
|
|||
ft.app(target=login)
|
||||
|
||||
except FileExistsError:
|
||||
config['DEFAULT'] = defconf
|
||||
config['Settings'] = defconf
|
||||
config['User'] = usrconf
|
||||
|
||||
with open(f"{getconfigpath()}/config.ini", "w") as file:
|
||||
|
|
|
@ -1,11 +1,56 @@
|
|||
import flet as ft
|
||||
from constants import *
|
||||
from utils import setthemecolor, setlanguage
|
||||
from i18n import _
|
||||
|
||||
|
||||
def SettingsPage():
|
||||
return ft.Column([
|
||||
ft.Text((_("Settings")), size=30, weight="bold"),
|
||||
ft.Placeholder()
|
||||
])
|
||||
def getlangoptions():
|
||||
return [
|
||||
ft.DropdownOption(key="Polski", content=ft.Text("Polski")),
|
||||
ft.DropdownOption(key="English", content=ft.Text("English")),
|
||||
]
|
||||
|
||||
|
||||
def getthemeoptions():
|
||||
return [
|
||||
ft.DropdownOption(key="RED", content=ft.Text(_("Red"))),
|
||||
ft.DropdownOption(key="ORANGE", content=ft.Text(_("Orange"))),
|
||||
ft.DropdownOption(key="YELLOW", content=ft.Text(_("Yellow"))),
|
||||
ft.DropdownOption(key="GREEN", content=ft.Text(_("Green"))),
|
||||
ft.DropdownOption(key="BLUE", content=ft.Text(_("Blue"))),
|
||||
ft.DropdownOption(key="PURPLE", content=ft.Text(_("Purple"))),
|
||||
ft.DropdownOption(key="PINK", content=ft.Text(_("Pink"))),
|
||||
ft.DropdownOption(key="BROWN", content=ft.Text(_("Brown"))),
|
||||
ft.DropdownOption(key="GREY", content=ft.Text(_("Grey"))),
|
||||
ft.DropdownOption(key="AMBER", content=ft.Text(_("Amber"))),
|
||||
ft.DropdownOption(key="CYAN", content=ft.Text(_("Cyan"))),
|
||||
]
|
||||
|
||||
def onlangchange(e):
|
||||
setlanguage(e)
|
||||
|
||||
def onthemechange(e):
|
||||
setthemecolor(e.data)
|
||||
|
||||
|
||||
return ft.Column([
|
||||
ft.Text(_("Settings"), size=30, weight="bold"),
|
||||
ft.Row([
|
||||
ft.Text(_("Language (Requires restart)")),
|
||||
ft.Dropdown(
|
||||
width=200,
|
||||
label=(_("Language")),
|
||||
options=getlangoptions(),
|
||||
on_change=onlangchange
|
||||
),
|
||||
]),
|
||||
|
||||
ft.Row([
|
||||
ft.Text(_("Theme (Requires restart)")),
|
||||
ft.Dropdown(
|
||||
width=200,
|
||||
label=(_("Theme")),
|
||||
options=getthemeoptions(),
|
||||
on_change=onthemechange
|
||||
)
|
||||
]),
|
||||
])
|
29
src/utils.py
29
src/utils.py
|
@ -1,6 +1,7 @@
|
|||
import keyring
|
||||
import os
|
||||
from pathlib import Path
|
||||
import configparser
|
||||
|
||||
def saveauth(service, username, data, chunk_size=1000):
|
||||
chunks = [data[i:i+chunk_size] for i in range(0, len(data), chunk_size)]
|
||||
|
@ -27,3 +28,31 @@ def getconfigpath():
|
|||
return f"{home}/.FujiConfig"
|
||||
case 'nt':
|
||||
return f"{home}/AppData/Local/Fuji"
|
||||
|
||||
def getthemecolor():
|
||||
config = configparser.ConfigParser()
|
||||
config.read(f"{getconfigpath()}/config.ini")
|
||||
color = config['Settings']['themecolor']
|
||||
|
||||
return color
|
||||
|
||||
def setthemecolor(color):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(f"{getconfigpath()}/config.ini")
|
||||
config["Settings"]["themecolor"] = color
|
||||
|
||||
with open(f"{getconfigpath()}/config.ini", "w") as file:
|
||||
config.write(file)
|
||||
|
||||
def setlanguage(lang):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(f"{getconfigpath()}/config.ini")
|
||||
|
||||
match lang.data:
|
||||
case "Polski":
|
||||
config["Settings"]["language"] = "pl"
|
||||
case "English":
|
||||
config["Settings"]["language"] = "en"
|
||||
|
||||
with open(f"{getconfigpath()}/config.ini", "w") as file:
|
||||
config.write(file)
|
Loading…
Add table
Reference in a new issue