-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
170 lines (132 loc) · 4.82 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import flet as ft
from db import *
def main(page: ft.Page):
#Page initialization
page.window_height = 600
page.window_width = 400
page.title = "MyPass Manager"
page.scroll = "auto"
page.on_connect = initialize_db()
#Controls Logic
def handle_search_change(e):
if switch_row[1].value == False:
handle = search_box.value
results = get_by_handle(handle)
my_data[0] = my_data_table(data=results)
page.update()
if switch_row[1].value == True:
service = search_box.value
results = get_by_service(service)
my_data[0] = my_data_table(data=results)
page.update()
def handle_new_pass(service, account):
def open_dlg(*e):
page.dialog = dlg_modal
dlg_modal.open = True
page.update()
def close_dlg(*e):
dlg_modal.open = False
page.update()
def submit(*e):
password = new_password_field.value
create_pass(service, account, password)
close_dlg()
new_password_field = ft.TextField(label="New Password", width=200, height=40)
dlg_modal = ft.AlertDialog(
modal=True,
title=ft.Text(f"Enter {account} Passcode?"),
content=new_password_field,
actions=[ft.Row(
[
ft.TextButton("Cancel", on_click=close_dlg),
ft.TextButton("Submit", on_click=submit)
]
)
]
)
open_dlg()
def handle_account_click(password):
page.set_clipboard(password)
def handle_account_long_press(my_id, account):
def close_dlg(*e):
dlg_modal.open = False
page.update()
def open_dlg(*e):
page.dialog = dlg_modal
dlg_modal.open = True
page.update()
def edit_entry(e):
password = change_password_field.value
change_pass(my_id, password)
close_dlg()
def delete_entry(e):
delete_pass(my_id)
close_dlg()
change_password_field = ft.TextField(label="Change Password", width=200, height=40)
dlg_modal = ft.AlertDialog(
modal=True,
title=ft.Text(f"Edit {account} Passcode?"),
content=change_password_field,
actions=[ft.Row(
[ft.TextButton("Cancel", on_click=close_dlg),
ft.TextButton("Delete", on_click=delete_entry),
ft.TextButton("Submit", on_click=edit_entry)], spacing=0)
]
)
open_dlg()
#Controls Display
def my_data_table(data=None):
add_service = ft.TextField(label="Add Service", height=45)
add_account = ft.TextField(
label="Add Account",
on_submit=lambda _: handle_new_pass(add_service.value, add_account.value),
height=45
)
default = ft.DataRow(cells = [
ft.DataCell(add_service),
ft.DataCell(add_account)
])
data_rows = [default]
if data != None:
data_rows = [default]
for entry in data:
my_id=entry[0]
service=entry[1]
account=entry[2]
password=entry[3]
row = ft.DataRow(
cells=[
ft.DataCell(ft.Text(service)),
ft.DataCell(ft.TextButton(
account,
on_click=lambda _: handle_account_click(password),
on_long_press=lambda _: handle_account_long_press(my_id, account)
))
]
)
data_rows.append(row)
table = ft.DataTable(
width=350,
column_spacing=5,
columns=[
ft.DataColumn(ft.Text("Service")),
ft.DataColumn(ft.Text("Account"))
],
rows = data_rows
)
return table
header = ft.Text("Welcome to MyPass")
search_box = ft.TextField(
label="Search",
width=250, height=40,
suffix_icon=ft.icons.SEARCH,
on_change=handle_search_change)
switch_row = [ft.Text("Account"), ft.Switch(value=False), ft.Text("Service")]
my_data = [my_data_table()]
page.add(
ft.Row([header], alignment="center"),
ft.Row([search_box], alignment="center"),
ft.Row(switch_row, alignment="center"),
ft.Row(my_data, alignment="center")
)
ft.app(target=main)