pre-commit and red pill

This commit is contained in:
Aman Ahmed Zahir 2024-04-19 20:02:44 +00:00
parent 1720af54e9
commit 536261dce7
18 changed files with 167 additions and 125 deletions

2
.gitignore vendored
View File

@ -158,4 +158,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
config.ini config.ini

32
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,32 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: debug-statements
- id: double-quote-string-fixer
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: destroyed-symlinks
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: fix-byte-order-marker
- id: mixed-line-ending
- repo: https://github.com/hhatto/autopep8
rev: v2.1.0
hooks:
- id: autopep8
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade

View File

@ -4,4 +4,4 @@ To run the app:
``` ```
flet run [app_directory] flet run [app_directory]
``` ```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -3,15 +3,17 @@ from utils import views_handler
def main(page: ft.Page): def main(page: ft.Page):
page.title = "BillPay" page.title = 'BillPay'
# print("Initial route:", page.route) # print("Initial route:", page.route)
def route_change(e): def route_change(e):
# print("Route change:", e.route) # print("Route change:", e.route)
page.views.clear() page.views.clear()
page.views.append( page.views.append(
views_handler(page)[page.route] views_handler(page)[page.route],
) )
page.update() page.update()
def view_pop(e): def view_pop(e):
# print("View pop:", e.view) # print("View pop:", e.view)
page.views.pop() page.views.pop()
@ -23,4 +25,4 @@ def main(page: ft.Page):
page.go(page.route) page.go(page.route)
ft.app(target=main, assets_dir="assets") ft.app(target=main, assets_dir='assets')

View File

@ -2,4 +2,4 @@ from .home import Home
from .settings import Settings from .settings import Settings
__all__ = ["Home", "Settings"] __all__ = ['Home', 'Settings']

View File

@ -2,18 +2,19 @@ import flet as ft
from utils import AppView, Title from utils import AppView, Title
from modules.settings import config from modules.settings import config
def Home(page: ft.Page): def Home(page: ft.Page):
return AppView( return AppView(
"/", '/',
[ [
ft.AppBar( ft.AppBar(
title=ft.Text(Title(__file__)), title=ft.Text(Title(__file__)),
actions=[ actions=[
ft.IconButton( ft.IconButton(
icon=ft.icons.SETTINGS, icon=ft.icons.SETTINGS,
on_click=lambda _: page.go("/settings"), on_click=lambda _: page.go('/settings'),
) ),
] ],
), ),
ft.Container( ft.Container(
height=100, height=100,
@ -21,11 +22,11 @@ def Home(page: ft.Page):
content=ft.Column( content=ft.Column(
controls=[ controls=[
ft.Text( ft.Text(
"Goodmorning," 'Goodmorning,',
), ),
ft.Text( ft.Text(
config.get("general", "name") config.get('general', 'name'),
) ),
], ],
), ),
), ),

View File

@ -1,4 +1,4 @@
from .settings import Settings from .settings import Settings
from .functions import config from .functions import config
__all__ = ["Settings", "config"] __all__ = ['Settings', 'config']

View File

@ -1,3 +1,3 @@
from .config import config from .config import config
from .theme import Theme from .theme import Theme
__all__ = ['config', 'Theme'] __all__ = ['config', 'Theme']

View File

@ -5,8 +5,8 @@ static = """
[general] [general]
name = CustomIcon name = CustomIcon
phone = phone =
email = email =
[apps] [apps]
dhiraagu = true dhiraagu = true
@ -17,44 +17,45 @@ stelco = true
medianet = true medianet = true
[dhiraagu] [dhiraagu]
phone = phone =
otp = otp =
cookie = cookie =
[ooredoo] [ooredoo]
phone = phone =
otp = otp =
cookie = cookie =
[hdc] [hdc]
property = property =
nid = nid =
[mwsc] [mwsc]
meter_no = meter_no =
account_no = account_no =
mobile_no = mobile_no =
[stelco] [stelco]
account_no = account_no =
bill_no = bill_no =
[medianet] [medianet]
account_no = account_no =
nid = nid =
phone = phone =
""" """
class Config(ConfigParser): class Config(ConfigParser):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
if not os.path.exists("config.ini"): if not os.path.exists('config.ini'):
self.initialize(content=static) self.initialize(content=static)
self.read("config.ini") self.read('config.ini')
def initialize(self, content): def initialize(self, content):
with open("config.ini", 'a+') as file: with open('config.ini', 'a+') as file:
file.write(content) file.write(content)
config = Config() config = Config()

View File

@ -1,9 +1,10 @@
import flet as ft import flet as ft
class Theme: class Theme:
def __init__(self, page: ft.Page) -> None: def __init__(self, page: ft.Page) -> None:
self.page = page self.page = page
def change(self, theme: ft.ThemeMode = None): def change(self, theme: ft.ThemeMode = None):
if theme: if theme:
self.page.theme_mode = theme self.page.theme_mode = theme
@ -13,4 +14,4 @@ class Theme:
if self.page.theme_mode == ft.ThemeMode.LIGHT if self.page.theme_mode == ft.ThemeMode.LIGHT
else ft.ThemeMode.LIGHT else ft.ThemeMode.LIGHT
) )
self.page.update() self.page.update()

View File

@ -2,11 +2,12 @@ import flet as ft
from utils import AppView, Title from utils import AppView, Title
from .functions import Theme from .functions import Theme
def Settings(page: ft.Page): def Settings(page: ft.Page):
settingsContainer = ft.ListView( settingsContainer = ft.ListView(
expand=True expand=True,
) )
settingsContainer.controls.append(ft.Text("General")) settingsContainer.controls.append(ft.Text('General'))
generalSettings = ft.Container( generalSettings = ft.Container(
content=ft.Column( content=ft.Column(
controls=[ controls=[
@ -17,16 +18,16 @@ def Settings(page: ft.Page):
[ [
ft.ListTile( ft.ListTile(
leading=ft.Icon(ft.icons.PERSON), leading=ft.Icon(ft.icons.PERSON),
title=ft.Text("Username"), title=ft.Text('Username'),
subtitle=ft.Text( subtitle=ft.Text(
"The greeting message" 'The greeting message',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked username"), on_click=lambda _: print('clicked username'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -35,16 +36,16 @@ def Settings(page: ft.Page):
[ [
ft.ListTile( ft.ListTile(
leading=ft.Icon(ft.icons.PHONE), leading=ft.Icon(ft.icons.PHONE),
title=ft.Text("Phone"), title=ft.Text('Phone'),
subtitle=ft.Text( subtitle=ft.Text(
"Personal Phone number" 'Personal Phone number',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked phone"), on_click=lambda _: print('clicked phone'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -53,16 +54,16 @@ def Settings(page: ft.Page):
[ [
ft.ListTile( ft.ListTile(
leading=ft.Icon(ft.icons.EMAIL), leading=ft.Icon(ft.icons.EMAIL),
title=ft.Text("Email"), title=ft.Text('Email'),
subtitle=ft.Text( subtitle=ft.Text(
"Personal Email" 'Personal Email',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked email"), on_click=lambda _: print('clicked email'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -71,25 +72,25 @@ def Settings(page: ft.Page):
[ [
ft.ListTile( ft.ListTile(
leading=ft.Icon(ft.icons.CARD_TRAVEL), leading=ft.Icon(ft.icons.CARD_TRAVEL),
title=ft.Text("NID"), title=ft.Text('NID'),
subtitle=ft.Text( subtitle=ft.Text(
"National Idenity Number" 'National Idenity Number',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked email"), on_click=lambda _: print('clicked email'),
) ),
), ),
] ],
) ),
) )
settingsContainer.controls.append( settingsContainer.controls.append(
generalSettings generalSettings,
) )
settingsContainer.controls.append(ft.Divider()) settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text("Notifications")) settingsContainer.controls.append(ft.Text('Notifications'))
notificationsSettings = ft.Container( notificationsSettings = ft.Container(
content=ft.Column( content=ft.Column(
controls=[ controls=[
@ -100,25 +101,25 @@ def Settings(page: ft.Page):
[ [
ft.ListTile( ft.ListTile(
leading=ft.Icon(ft.icons.TELEGRAM), leading=ft.Icon(ft.icons.TELEGRAM),
title=ft.Text("Telegram"), title=ft.Text('Telegram'),
subtitle=ft.Text( subtitle=ft.Text(
"Telegram Notifications for reminders and Bill pays" 'Telegram Notifications for reminders and Bill pays',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked username"), on_click=lambda _: print('clicked username'),
) ),
), ),
] ],
) ),
) )
settingsContainer.controls.append( settingsContainer.controls.append(
notificationsSettings notificationsSettings,
) )
settingsContainer.controls.append(ft.Divider()) settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text("Apps")) settingsContainer.controls.append(ft.Text('Apps'))
appsSettings = ft.Container( appsSettings = ft.Container(
content=ft.Column( content=ft.Column(
controls=[ controls=[
@ -131,18 +132,18 @@ def Settings(page: ft.Page):
leading=ft.Image( leading=ft.Image(
border_radius=ft.border_radius.all(10), border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN, fit=ft.ImageFit.CONTAIN,
src="https://asset.brandfetch.io/idZJsIaold/id9-VJM_HU.png" src='https://asset.brandfetch.io/idZJsIaold/id9-VJM_HU.png',
), ),
title=ft.Text("Dhiraagu"), title=ft.Text('Dhiraagu'),
subtitle=ft.Text( subtitle=ft.Text(
"An ISP Service." 'An ISP Service.',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked dhiraagu"), on_click=lambda _: print('clicked dhiraagu'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -153,18 +154,18 @@ def Settings(page: ft.Page):
leading=ft.Image( leading=ft.Image(
border_radius=ft.border_radius.all(10), border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN, fit=ft.ImageFit.CONTAIN,
src="https://asset.brandfetch.io/idR1xFKHLD/idu6J-WQsm.jpeg" src='https://asset.brandfetch.io/idR1xFKHLD/idu6J-WQsm.jpeg',
), ),
title=ft.Text("Ooredoo"), title=ft.Text('Ooredoo'),
subtitle=ft.Text( subtitle=ft.Text(
"An ISP Service." 'An ISP Service.',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked ooredoo"), on_click=lambda _: print('clicked ooredoo'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -175,18 +176,18 @@ def Settings(page: ft.Page):
leading=ft.Image( leading=ft.Image(
border_radius=ft.border_radius.all(10), border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN, fit=ft.ImageFit.CONTAIN,
src="https://www.stelco.com.mv/wp-content/uploads/2022/02/unnamed.png" src='https://www.stelco.com.mv/wp-content/uploads/2022/02/unnamed.png',
), ),
title=ft.Text("STELCO"), title=ft.Text('STELCO'),
subtitle=ft.Text( subtitle=ft.Text(
"Electricity Bills" 'Electricity Bills',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked stelco"), on_click=lambda _: print('clicked stelco'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -197,18 +198,18 @@ def Settings(page: ft.Page):
leading=ft.Image( leading=ft.Image(
border_radius=ft.border_radius.all(10), border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN, fit=ft.ImageFit.CONTAIN,
src="https://asset.brandfetch.io/idOZWUOUm-/idNastd9Bg.jpeg" src='https://asset.brandfetch.io/idOZWUOUm-/idNastd9Bg.jpeg',
), ),
title=ft.Text("MWSC"), title=ft.Text('MWSC'),
subtitle=ft.Text( subtitle=ft.Text(
"Water Bills" 'Water Bills',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked mwsc"), on_click=lambda _: print('clicked mwsc'),
) ),
), ),
ft.Card( ft.Card(
content=ft.Container( content=ft.Container(
@ -219,25 +220,26 @@ def Settings(page: ft.Page):
leading=ft.Image( leading=ft.Image(
border_radius=ft.border_radius.all(10), border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN, fit=ft.ImageFit.CONTAIN,
src="https://asset.brandfetch.io/idLMZnv5SC/iduyX4keYN.jpeg" src='https://asset.brandfetch.io/idLMZnv5SC/iduyX4keYN.jpeg',
), ),
title=ft.Text("Medianet"), title=ft.Text('Medianet'),
subtitle=ft.Text( subtitle=ft.Text(
"Online Television Service" 'Online Television Service',
), ),
), ),
] ],
), ),
padding=10, padding=10,
on_click=lambda _: print("clicked medianet"), on_click=lambda _: print('clicked medianet'),
) ),
), ),
] ],
) ),
) )
settingsContainer.controls.append(appsSettings) settingsContainer.controls.append(appsSettings)
settingsContainer.controls.append(ft.Divider()) settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text("Theme")) settingsContainer.controls.append(ft.Text('Theme'))
def _on_theme_change(e): def _on_theme_change(e):
Theme(page).change() Theme(page).change()
themeSettings = ft.Container( themeSettings = ft.Container(
@ -248,29 +250,29 @@ def Settings(page: ft.Page):
content=ft.Container( content=ft.Container(
ft.Switch( ft.Switch(
value=True, value=True,
label=" Switch to dark theme", label=' Switch to dark theme',
on_change=_on_theme_change on_change=_on_theme_change,
), ),
), ),
padding=10, padding=10,
on_click=None, on_click=None,
) ),
), ),
] ],
) ),
) )
settingsContainer.controls.append(themeSettings) settingsContainer.controls.append(themeSettings)
return AppView( return AppView(
"/settings", '/settings',
[ [
ft.AppBar( ft.AppBar(
leading=ft.IconButton( leading=ft.IconButton(
ft.icons.ARROW_BACK_IOS_NEW_ROUNDED, ft.icons.ARROW_BACK_IOS_NEW_ROUNDED,
on_click=lambda _: page.go("/") on_click=lambda _: page.go('/'),
), ),
title=ft.Text(Title(str(__file__))), title=ft.Text(Title(str(__file__))),
bgcolor=ft.colors.TRANSPARENT bgcolor=ft.colors.TRANSPARENT,
), ),
settingsContainer settingsContainer,
], ],
) )

View File

@ -1 +1 @@
flet==0.22.* flet==0.22.*

View File

@ -3,7 +3,7 @@ from .title import Title
from .views import views_handler from .views import views_handler
__all__ = [ __all__ = [
"AppView", 'AppView',
"Title", 'Title',
"views_handler" 'views_handler',
] ]

View File

@ -1,4 +1,5 @@
import os import os
def Title(title: str): def Title(title: str):
return str(os.path.basename(title)).replace('.py', '').title() return str(os.path.basename(title)).replace('.py', '').title()

View File

@ -1,7 +1,8 @@
import flet as ft import flet as ft
class AppView(ft.View): class AppView(ft.View):
def __init__(self, route, controls): def __init__(self, route, controls):
super().__init__() super().__init__()
self.controls = controls self.controls = controls
self.route = route self.route = route

View File

@ -1,7 +1,8 @@
from modules import Home, Settings from modules import Home, Settings
def views_handler(page): def views_handler(page):
return { return {
'/': Home(page), '/': Home(page),
'/settings': Settings(page) '/settings': Settings(page),
} }