-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings.py
151 lines (137 loc) · 5.81 KB
/
settings.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
from kivy.app import App
from kivy.uix.screenmanager import Screen, SlideTransition
from kivy.config import Config
from kivy.core.window import Window
import login
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from login import Status
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
class Settings(Screen):
def __init__(self,**kwargs):
super(Screen,self).__init__(**kwargs)
#self.prev=''
def setprev_(self,prev):
self.prev=prev
def back(self):
if self.prev=='login':
Window.size = (340, 250)
if self.prev=='connected':
Window.size = (340, 150)
self.manager.transition = SlideTransition(direction="down")
self.manager.current = self.prev
def cred(self):
Window.size=(340,500)
creds={}
credman=Screen(name='credman',id='screen')
base=BoxLayout(padding=[0,0,0,0],orientation='vertical',id='base',size_hint_y=None,height=500)
buttons=BoxLayout(padding=[0,0,0,0],orientation='horizontal',id='buttons',height=450)
buttons.add_widget(Button(text= 'add',font_size= 15,pos=[40, 40],size_hint=[1, None],height=30,on_press=lambda x:self.p_add(credman)))
buttons.add_widget(Button(text= 'save',font_size= 15,pos=[40, 40],size_hint=[1, None],height=30,on_press=lambda x:self.c_save(credman)))
buttons.add_widget(Button(text= 'back',font_size= 15,pos=[40, 40],size_hint=[1, None],height=30,on_press=lambda x:self.c_back(credman)))
# print('yolo')
with open('cred.bin','rb') as f:
from pickle import load
creds=load(f)
i=0
layout=GridLayout(cols=1,size_hint=[1,None],height=450)
# layout.bind(minimum_height=layout.setter('height'))
for user in creds.keys():
# print(user)
usr=TextInput(text=str(user),id=str(str(i)+'u'),multiline=False,write_tab=False,use_bubble=True,size_hint=[1, None],height=35)
pwd=TextInput(text=str(creds[user]),id=str(str(i)+'p'),multiline=False,write_tab=False,password=True,use_bubble=True,size_hint=[1, None],height=35)
dele=Button(text=str('x'),size_hint=[None,1],width=20,id=str(i),on_press=lambda i:self.c_dele(credman,i.id),height=35)
lay=BoxLayout(orientation='horizontal',id=str(i))
lay.add_widget(usr)
lay.add_widget(pwd)
lay.add_widget(dele)
layout.add_widget(lay)
i=i+1
layout.height=i*35
sc=ScrollView(id='list',size_hint=[1,None],height=470)
sc.add_widget(layout)
base.add_widget(sc)
base.add_widget(buttons)
credman.add_widget(base)
self.manager.add_widget(credman)
self.manager.current='credman'
def about(self):
popup = Popup(title='Made by Uday.', content=Label(text='click outside the box to dismiss',font_size='9sp'),auto_dismiss=True,size_hint=(None, None), size=(200, 100),title_size='20sp',title_align='center')
popup.open()
def c_back(self,screen):
Window.size = (340, 250)
self.manager.remove_widget(self.manager.get_screen('credman'))
self.manager.current='settings'
def c_save(self,credman):
creds={}
with open('cred.bin','rb') as f:
from pickle import load
creds=load(f)
i=0
wid={}
for widget in self.manager.get_screen('credman').walk():
wid[widget.id]=widget
# print(wid)
new_creds={}
for keys in creds.keys():
new_creds[wid[str(i)+'u'].text]=str(wid[str(i)+'p'].text)
i=i+1
with open('cred.bin','wb') as f:
from pickle import dump
dump(new_creds,f)
self.c_back(credman)
self.cred()
def c_dele(self,credman,id):
creds={}
with open('cred.bin','rb') as f:
from pickle import load
creds=load(f)
i=0
wid={}
for widget in self.manager.get_screen('credman').walk():
wid[widget.id]=widget
# print(wid)
new_creds={}
for keys in creds.keys():
if str(i)==id:
i=i+1
continue
else:
new_creds[wid[str(i)+'u'].text]=str(wid[str(i)+'p'].text)
i=i+1
with open('cred.bin','wb') as f:
from pickle import dump
dump(new_creds,f)
self.c_back(credman)
self.cred()
def p_add(self,credman):
base=BoxLayout(orientation="vertical",id="box")
user=TextInput(id="user",hint_text="username",multiline=False,write_tab=False,use_bubble=True)
pwd=TextInput(id="user",hint_text="password",multiline=False,write_tab=False,use_bubble=True,password=True)
add=Button(id="add",text="add",on_press=lambda x:self.c_add(user,pwd,credman))
quit=Label(text='click outside the box to dismiss',font_size='9sp')
base.add_widget(user)
base.add_widget(pwd)
base.add_widget(add)
base.add_widget(quit)
popup = Popup(title='Add User', content=base,auto_dismiss=True,size_hint=(None, None), size=(200, 200),title_size='20sp',title_align='center')
popup.open()
def c_add(self,username,password,credman):
if username == '' or password == '':
return
creds={}
with open('cred.bin','rb') as f:
from pickle import load
creds=load(f)
creds[username.text]=password.text
with open('cred.bin','wb') as f:
from pickle import dump
dump(creds,f)
username.text=''
password.text=''
self.c_back(credman)
self.cred()