-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
189 lines (136 loc) · 4.05 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.menu import MDDropdownMenu
from kivymd.uix.list import TwoLineListItem, TwoLineAvatarListItem
from kivymd.uix.behaviors import RoundedRectangularElevationBehavior
from kivymd.uix.card import MDCard
from kivymd.uix.card import MDCardSwipe
from kivy.properties import StringProperty
from kivymd.toast import toast
from kivymd.uix.snackbar import Snackbar
from kivymd.uix.list import OneLineAvatarIconListItem
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager
from kivymd.uix.screen import MDScreen
from kivy.uix.textinput import TextInput
from kivymd.uix.label import MDLabel
import re
from kivy.uix.recycleview import RecycleView
from conf import Conf
from create import TelaCadastro
import requests
response = requests.get('https://625e20a26c48e8761ba572c5.mockapi.io/api/v1/users').json()
print(response)
# Configurações de Tela
from kivy.utils import platform
if platform != 'android':
Window.size = 300, 600
from kivy.storage.jsonstore import JsonStore
# Banco de Dados
store = JsonStore('database/banco.json')
# store.put('tito', nome = 'Mathieu', idade=32)
kv = Builder.load_file('main.kv')
class Item(OneLineAvatarIconListItem):
left_icon = StringProperty()
right_text = StringProperty()
class ListComAvatar(TwoLineAvatarListItem):
source = StringProperty()
class SM(ScreenManager):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.add_widget(InicioWindow(name='inicio'))
self.add_widget(TelaCadastro(name='cadastro'))
self.add_widget(Conf(name='conf'))
class InicioWindow(MDScreen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def existe(self, text='', search=False):
def add_nome(nome, idade, avatar):
self.ids.rv.data.append(
{
'viewclass': 'ListComAvatar',
'text': str(nome),
'secondary_text': str(idade),
'source': str(avatar)
}
)
self.ids.rv.data = []
for key in response:
nome = key['name']
idade = key['idade']
avatar = key['avatar']
if search:
if text in nome:
add_nome(nome, idade, avatar)
else:
add_nome(nome, idade, avatar)
def add(self):
idade = self.ids.idade.text
colecao = self.ids.colecao.text
if store.exists(colecao):
print(f'{colecao} já existe')
toast(f'{colecao} já existe')
else:
store.put(colecao, nome = colecao, idade=idade)
toast(f'{colecao} foi adicionado')
def delete(self):
key = self.ids.colecao.text
if store.exists(key):
store.delete(key)
toast(f'{key} foi deletado')
else:
print(f'{key} não existe')
toast(f'{key} não existe')
class MyCrud(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.screen = SM()
self.inicio = InicioWindow()
data =(
{
'Create': 'file-document-edit',
'Read': 'book-open-variant',
'Update': 'update',
'Delete': 'delete',
}
)
def on_start(self):
self.inicio.existe()
def abrir(self, instance):
toast(instance.text)
def voltar(self):
self.root.current = self.previous_screen
def callback(self, instance):
# Snackbar(text = instance.icon).open()
if instance.icon:
self.screen.current = 'cadastro'
def build(self):
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "Purple"
lista = (
{'nome':'Ajuda', 'icon': 'help-box'},
{'nome':'Configurações', 'icon': 'cog'},
)
menu_items = (
{
"right_text": str(key.get('nome')) ,
"left_icon": str(key.get('icon')),
"viewclass": "Item" ,
"on_release": lambda x=(str(key.get('nome'))): self.menu_chamada(x),
} for key in lista
)
self.menu = MDDropdownMenu(
items=menu_items,
width_mult=4)
return self.inicio
def chamada(self, button):
self.menu.caller = button
self.menu.open()
def menu_chamada(self, text_item):
self.menu.dismiss()
if text_item == 'Configurações':
self.screen.current = 'conf'
print(text_item)
if __name__ == '__main__':
MyCrud().run()