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
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.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]
```
```

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):
page.title = "BillPay"
page.title = 'BillPay'
# print("Initial route:", page.route)
def route_change(e):
# print("Route change:", e.route)
page.views.clear()
page.views.append(
views_handler(page)[page.route]
views_handler(page)[page.route],
)
page.update()
def view_pop(e):
# print("View pop:", e.view)
page.views.pop()
@ -23,4 +25,4 @@ def main(page: ft.Page):
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
__all__ = ["Home", "Settings"]
__all__ = ['Home', 'Settings']

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,10 @@
import flet as ft
class Theme:
def __init__(self, page: ft.Page) -> None:
self.page = page
def change(self, theme: ft.ThemeMode = None):
if theme:
self.page.theme_mode = theme
@ -13,4 +14,4 @@ class Theme:
if self.page.theme_mode == 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 .functions import Theme
def Settings(page: ft.Page):
settingsContainer = ft.ListView(
expand=True
expand=True,
)
settingsContainer.controls.append(ft.Text("General"))
settingsContainer.controls.append(ft.Text('General'))
generalSettings = ft.Container(
content=ft.Column(
controls=[
@ -17,16 +18,16 @@ def Settings(page: ft.Page):
[
ft.ListTile(
leading=ft.Icon(ft.icons.PERSON),
title=ft.Text("Username"),
title=ft.Text('Username'),
subtitle=ft.Text(
"The greeting message"
'The greeting message',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked username"),
)
on_click=lambda _: print('clicked username'),
),
),
ft.Card(
content=ft.Container(
@ -35,16 +36,16 @@ def Settings(page: ft.Page):
[
ft.ListTile(
leading=ft.Icon(ft.icons.PHONE),
title=ft.Text("Phone"),
title=ft.Text('Phone'),
subtitle=ft.Text(
"Personal Phone number"
'Personal Phone number',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked phone"),
)
on_click=lambda _: print('clicked phone'),
),
),
ft.Card(
content=ft.Container(
@ -53,16 +54,16 @@ def Settings(page: ft.Page):
[
ft.ListTile(
leading=ft.Icon(ft.icons.EMAIL),
title=ft.Text("Email"),
title=ft.Text('Email'),
subtitle=ft.Text(
"Personal Email"
'Personal Email',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked email"),
)
on_click=lambda _: print('clicked email'),
),
),
ft.Card(
content=ft.Container(
@ -71,25 +72,25 @@ def Settings(page: ft.Page):
[
ft.ListTile(
leading=ft.Icon(ft.icons.CARD_TRAVEL),
title=ft.Text("NID"),
title=ft.Text('NID'),
subtitle=ft.Text(
"National Idenity Number"
'National Idenity Number',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked email"),
)
on_click=lambda _: print('clicked email'),
),
),
]
)
],
),
)
settingsContainer.controls.append(
generalSettings
generalSettings,
)
settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text("Notifications"))
settingsContainer.controls.append(ft.Text('Notifications'))
notificationsSettings = ft.Container(
content=ft.Column(
controls=[
@ -100,25 +101,25 @@ def Settings(page: ft.Page):
[
ft.ListTile(
leading=ft.Icon(ft.icons.TELEGRAM),
title=ft.Text("Telegram"),
title=ft.Text('Telegram'),
subtitle=ft.Text(
"Telegram Notifications for reminders and Bill pays"
'Telegram Notifications for reminders and Bill pays',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked username"),
)
on_click=lambda _: print('clicked username'),
),
),
]
)
],
),
)
settingsContainer.controls.append(
notificationsSettings
notificationsSettings,
)
settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text("Apps"))
settingsContainer.controls.append(ft.Text('Apps'))
appsSettings = ft.Container(
content=ft.Column(
controls=[
@ -131,18 +132,18 @@ def Settings(page: ft.Page):
leading=ft.Image(
border_radius=ft.border_radius.all(10),
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(
"An ISP Service."
'An ISP Service.',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked dhiraagu"),
)
on_click=lambda _: print('clicked dhiraagu'),
),
),
ft.Card(
content=ft.Container(
@ -153,18 +154,18 @@ def Settings(page: ft.Page):
leading=ft.Image(
border_radius=ft.border_radius.all(10),
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(
"An ISP Service."
'An ISP Service.',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked ooredoo"),
)
on_click=lambda _: print('clicked ooredoo'),
),
),
ft.Card(
content=ft.Container(
@ -175,18 +176,18 @@ def Settings(page: ft.Page):
leading=ft.Image(
border_radius=ft.border_radius.all(10),
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(
"Electricity Bills"
'Electricity Bills',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked stelco"),
)
on_click=lambda _: print('clicked stelco'),
),
),
ft.Card(
content=ft.Container(
@ -197,18 +198,18 @@ def Settings(page: ft.Page):
leading=ft.Image(
border_radius=ft.border_radius.all(10),
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(
"Water Bills"
'Water Bills',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked mwsc"),
)
on_click=lambda _: print('clicked mwsc'),
),
),
ft.Card(
content=ft.Container(
@ -219,25 +220,26 @@ def Settings(page: ft.Page):
leading=ft.Image(
border_radius=ft.border_radius.all(10),
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(
"Online Television Service"
'Online Television Service',
),
),
]
],
),
padding=10,
on_click=lambda _: print("clicked medianet"),
)
on_click=lambda _: print('clicked medianet'),
),
),
]
)
],
),
)
settingsContainer.controls.append(appsSettings)
settingsContainer.controls.append(ft.Divider())
settingsContainer.controls.append(ft.Text("Theme"))
settingsContainer.controls.append(ft.Text('Theme'))
def _on_theme_change(e):
Theme(page).change()
themeSettings = ft.Container(
@ -248,29 +250,29 @@ def Settings(page: ft.Page):
content=ft.Container(
ft.Switch(
value=True,
label=" Switch to dark theme",
on_change=_on_theme_change
label=' Switch to dark theme',
on_change=_on_theme_change,
),
),
padding=10,
on_click=None,
)
),
),
]
)
],
),
)
settingsContainer.controls.append(themeSettings)
return AppView(
"/settings",
'/settings',
[
ft.AppBar(
leading=ft.IconButton(
ft.icons.ARROW_BACK_IOS_NEW_ROUNDED,
on_click=lambda _: page.go("/")
on_click=lambda _: page.go('/'),
),
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
__all__ = [
"AppView",
"Title",
"views_handler"
]
'AppView',
'Title',
'views_handler',
]

View File

@ -1,4 +1,5 @@
import os
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
class AppView(ft.View):
def __init__(self, route, controls):
super().__init__()
self.controls = controls
self.route = route
self.route = route

View File

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