General Settings - Functional

This commit is contained in:
2024-04-20 08:00:17 +00:00
parent 8869f77118
commit 2c011a6c34
7 changed files with 208 additions and 66 deletions

View File

@ -4,9 +4,10 @@ import os
static = """
[general]
name =
name =
phone =
email =
theme = dark
[apps]
dhiraagu = true
@ -57,5 +58,11 @@ class Config(ConfigParser):
with open('config.ini', 'a+') as file:
file.write(content)
def save(self, section, key, value):
config.set(section, key, value)
with open('config.ini', 'w') as configfile:
self.write(configfile)
self.read('config.ini')
config = Config()

View File

@ -1,4 +1,5 @@
import flet as ft
from .config import config
class Theme:
@ -8,10 +9,5 @@ class Theme:
def change(self, theme: ft.ThemeMode = None):
if theme:
self.page.theme_mode = theme
else:
self.page.theme_mode = (
ft.ThemeMode.DARK
if self.page.theme_mode == ft.ThemeMode.LIGHT
else ft.ThemeMode.LIGHT
)
print(theme)
self.page.update()

View File

@ -1,6 +1,6 @@
import flet as ft
from utils import AppView, Title
from .functions import Theme
from .functions import Theme, config
def Settings(page: ft.Page):
@ -8,6 +8,131 @@ def Settings(page: ft.Page):
expand=True,
)
settingsContainer.controls.append(ft.Text('General'))
def _on_name_change(e):
newName = ft.CupertinoTextField(value=config.get('general', 'name'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your Full name'),
content=newName,
actions=[
ft.CupertinoButton(
'Save', on_click=lambda _: (
setattr(
dlg, 'open', False,
),
config.save(
'general', 'name',
newName.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close', on_click=lambda _: (
setattr(dlg, 'open', False),
page.update()
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
def _on_phone_change(e):
newPhone = ft.CupertinoTextField(value=config.get('general', 'phone'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your Mobile'),
content=newPhone,
actions=[
ft.CupertinoButton(
'Save', on_click=lambda _: (
setattr(
dlg, 'open', False,
),
config.save(
'general', 'phone',
newPhone.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close', on_click=lambda _: (
setattr(dlg, 'open', False),
page.update()
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
def _on_email_change(e):
newEmail = ft.CupertinoTextField(value=config.get('general', 'email'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your Email'),
content=newEmail,
actions=[
ft.CupertinoButton(
'Save', on_click=lambda _: (
setattr(
dlg, 'open', False,
),
config.save(
'general', 'email',
newEmail.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close', on_click=lambda _: (
setattr(dlg, 'open', False),
page.update()
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
def _on_nid_change(e):
newNID = ft.CupertinoTextField(value=config.get('general', 'nid'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your NID'),
content=newNID,
actions=[
ft.CupertinoButton(
'Save', on_click=lambda _: (
setattr(
dlg, 'open', False,
),
config.save(
'general', 'nid',
newNID.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close', on_click=lambda _: (
setattr(dlg, 'open', False),
page.update()
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
generalSettings = ft.Container(
content=ft.Column(
controls=[
@ -26,7 +151,7 @@ def Settings(page: ft.Page):
],
),
padding=10,
on_click=lambda _: print('clicked username'),
on_click=_on_name_change,
),
),
ft.Card(
@ -44,7 +169,7 @@ def Settings(page: ft.Page):
],
),
padding=10,
on_click=lambda _: print('clicked phone'),
on_click=_on_phone_change,
),
),
ft.Card(
@ -62,7 +187,7 @@ def Settings(page: ft.Page):
],
),
padding=10,
on_click=lambda _: print('clicked email'),
on_click=_on_email_change,
),
),
ft.Card(
@ -80,7 +205,7 @@ def Settings(page: ft.Page):
],
),
padding=10,
on_click=lambda _: print('clicked email'),
on_click=_on_nid_change,
),
),
],
@ -89,35 +214,35 @@ def Settings(page: ft.Page):
settingsContainer.controls.append(
generalSettings,
)
settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text('Notifications'))
notificationsSettings = ft.Container(
content=ft.Column(
controls=[
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Icon(ft.icons.TELEGRAM),
title=ft.Text('Telegram'),
subtitle=ft.Text(
'Telegram Notifications for reminders and Bill pays',
),
),
],
),
padding=10,
on_click=lambda _: print('clicked username'),
),
),
],
),
)
settingsContainer.controls.append(
notificationsSettings,
)
# settingsContainer.controls.append(ft.Divider())
# settingsContainer.controls.append(ft.Text('Notifications'))
# notificationsSettings = ft.Container(
# content=ft.Column(
# controls=[
# ft.Card(
# content=ft.Container(
# ink=True,
# content=ft.Column(
# [
# ft.ListTile(
# leading=ft.Icon(ft.icons.TELEGRAM),
# title=ft.Text('Telegram'),
# subtitle=ft.Text(
# 'Telegram Notifications for reminders and Bill pays',
# ),
# ),
# ],
# ),
# padding=10,
# on_click=lambda _: print('clicked username'),
# ),
# ),
# ],
# ),
# )
# settingsContainer.controls.append(
# notificationsSettings,
# )
settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text('Apps'))
appsSettings = ft.Container(
@ -241,7 +366,16 @@ def Settings(page: ft.Page):
settingsContainer.controls.append(ft.Text('Theme'))
def _on_theme_change(e):
Theme(page).change()
if page.theme_mode == ft.ThemeMode.LIGHT:
e.value = False
config.save('general', 'theme', 'light')
else:
e.value = True
config.save('general', 'theme', 'dark')
Theme(page).change(
ft.ThemeMode.DARK if page.theme_mode ==
ft.ThemeMode.LIGHT else ft.ThemeMode.LIGHT,
)
themeSettings = ft.Container(
content=ft.Column(
controls=[
@ -249,9 +383,9 @@ def Settings(page: ft.Page):
content=ft.Container(
content=ft.Container(
ft.Switch(
value=True,
label=' Switch to dark theme',
on_change=_on_theme_change,
value=True,
),
),
padding=10,