-
Notifications
You must be signed in to change notification settings - Fork 1
/
gfs.py
660 lines (573 loc) · 21.4 KB
/
gfs.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
########################################################
# -*- coding: utf-8 -*-
import sys, time,datetime
from datetime import timedelta
if '--prod' in sys.argv:
PROD = True
sys.argv.remove('--prod')
else: PROD = None
########################################################
from models.models import Database, _SESSION
from models.config import CONFIG
########################################################
from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', '978')
Config.set('graphics', 'height', '628')
########################################################
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.floatlayout import FloatLayout
from kivy.utils import get_color_from_hex
from kivymd.font_definitions import fonts
from kivy.uix.boxlayout import BoxLayout
from kivy.factory import Factory
from kivy.lang import Builder
from kivy.clock import Clock
########################################################
from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.card import MDCard
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton, MDFloatingActionButton, MDRoundFlatIconButton,MDIconButton
from kivymd.uix.menu import MDDropdownMenu
from kivymd.theming import ThemableBehavior
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.icon_definitions import md_icons
from kivymd.uix.textfield import MDTextField
from kivymd.uix.datatables import MDDataTable
from kivymd.uix.dropdownitem import MDDropDownItem
from kivymd.uix.picker import MDDatePicker
from kivymd.uix.behaviors import RectangularElevationBehavior
class CustomToolbar(ThemableBehavior, RectangularElevationBehavior, MDBoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
class GFS(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
if PROD:
self.db = Database(CONFIG)
###Load the kv file with the encoding utf8 [!important in winidows]
with open('main.kv', encoding='utf-8') as f:
self.INTERFACE = Builder.load_string(f.read())
###Application color_theme parameter in general
self.theme_cls.primary_palette = "Red"
self.theme_cls.primary_hue = "A700"
self.theme_cls.theme_style= "Light"
self.quit_dialog = None
self.dialog = None
self.db = None
self.__tableau()
self.__tableau_status()
self.__tableau_status_facture()
self.transact = []
self.__tableau_transaction(self.transact)
###For the MDRaisedButton in Grand-menage
for i in range(10): self.INTERFACE.ids[f'raisedBtn{i+1}'].md_bg_color = get_color_from_hex("#2763e1")
###The dropdown menu in the profile button in the top-right
menu_items = [
{"icon": "account", "text": "Profil"},
{"icon": "logout", "text": "Déconnexion"},
{"icon": "exit-run", "text": "Quit"}
]
self.menu = MDDropdownMenu(
caller=self.INTERFACE.ids.button_2,
items=menu_items,
width_mult=5,
)
self.menu.bind(on_release=self.logout)
self.date_dialog = MDDatePicker(
callback=self.get_date,
year=2010,
month=2,
day=12,
)
###Instance of the Database class
def on_start(self):
if PROD:
self.db = Database(CONFIG)
def build(self):
return self.INTERFACE
####################################################
## About login #
####################################################
def loadConnection(self):
if not self.db and PROD:
self.INTERFACE.ids.errorLogin.text = "Vérifier votre connexion Internet"
return
self.INTERFACE.ids.button_login.text = " "
self.INTERFACE.ids.button_login.icon = " "
self.INTERFACE.ids.loader.color = (1,1,1,1)
self.INTERFACE.ids.loader.active = True
Clock.schedule_once(self.login, 1)
def initialisaion(self):
self.INTERFACE.ids.loader.active = False
self.INTERFACE.ids.password.text = ""
self.INTERFACE.ids.button_login.icon = "arrow-right"
self.INTERFACE.ids.button_login.text = "S'identifier"
def login(self, event):
username = self.INTERFACE.ids.username.text
password = self.INTERFACE.ids.password.text
if not PROD or self.db.login(username,password):
self.INTERFACE.current = "Main"
self.INTERFACE.ids.username.text = ""
self.INTERFACE.ids.errorLogin.text
self.initialisaion()
return
self.initialisaion()
self.INTERFACE.ids.errorLogin.text = "Le mot de passe est incorrect !"
####################################################
## Logout || Quit the app #
####################################################
def logout(self, menu, item):
if item.text == "Déconnexion":
_SESSION = None
self.INTERFACE.current = "Login"
self.menu.dismiss()
if item.text == "Quit":
self.show_quit_dialog()
def show_quit_dialog(self):
if not self.quit_dialog:
self.quit_dialog = MDDialog(
text="Etes vous sur de quittez ?",
buttons=[
MDFlatButton(
text="ANNULER", text_color=self.theme_cls.primary_color,on_press=self.close_quit_Dialog
),
MDFlatButton(
text="CONFIRMER", text_color=self.theme_cls.primary_color,on_press=self.close_quit_Dialog
),
],
)
self.quit_dialog.bind(on_release=self.close_quit_Dialog)
self.quit_dialog.open()
def close_quit_Dialog(self,btn):
if btn.text == "ANNULER":
self.quit_dialog.dismiss()
else:
self.stop()
####################################################
## Tour de tâche #
####################################################
def tour_de_tache(self,jour,tache,slide):
date_tache = datetime.date.today()
if jour == "hier":
if slide == 1 : date_tache = datetime.date.today() - timedelta(1)
elif slide == 2 : date_tache = datetime.date.today() + timedelta(2)
elif jour == "aujourdhui":
if slide == 1 : date_tache = datetime.date.today()
elif slide == 2 : date_tache = datetime.date.today() + timedelta(3)
elif jour == "demain":
if slide == 1 : date_tache = datetime.date.today() + timedelta(1)
elif slide == 2 : date_tache = datetime.date.today() + timedelta(4)
date_tache = date_tache.strftime("%Y-%m-%d")
return self.db.tour_tache(date_tache,tache)
def jour_de_tache(self,jour,slide):
date_tache = datetime.date.today()
if jour == "hier":
if slide == 1 : date_tache = datetime.date.today() - timedelta(1)
elif slide == 2 : date_tache = datetime.date.today() + timedelta(2)
elif jour == "aujourdhui":
if slide == 1 : date_tache = datetime.date.today()
elif slide == 2 : date_tache = datetime.date.today() + timedelta(3)
elif jour == "demain":
if slide == 1 : date_tache = datetime.date.today() + timedelta(1)
elif slide == 2 : date_tache = datetime.date.today() + timedelta(4)
return date_tache.strftime("%d-%m-%y")
####################################################
## Tableau in the cook menu #
####################################################
def __tableau(self):
tab = MDDataTable(
size_hint=(0.9, 0.3),
column_data=[
("Lundi", dp(24)),
("Mardi", dp(24)),
("Mercredi", dp(24)),
("Jeudi", dp(24)),
("Vendredi", dp(24)),
("Samedi", dp(24)),
("Dimanche", dp(24)),
],
row_data=[
(
"Oeuf sauce",
"Kitoza",
"Voanjobory",
"Soupe Légume",
"Poulet frite",
"Tsaramaso",
"Brède",
),
(
"4 500 Ar",
"2 500 Ar",
"5 000 Ar",
"6 000 Ar",
"2 000 Ar",
"3 500 Ar",
"3 000 Ar",
)
],
)
self.INTERFACE.ids.tableau_repas.add_widget(tab)
####################################################
## Tableau de status de cotisation #
####################################################
def __tableau_status(self):
tab = MDDataTable(
size_hint=(0.815, 0.45),
column_data=[
("Membres", dp(50)),
("Cotisations", dp(50)),
("Status", dp(50)),
],
row_data=[
# The number of elements must match the length
# of the `column_data` list.
(
"Landry",
"Bazar",
("alert", [255 / 256, 165 / 256, 0, 1], "En attente"),
),
(
"Gaetan",
"Tee-shirt",
("alert", [255 / 256, 165 / 256, 0, 1], "En attente"),
),
(
"Haja",
"Tee-shirt",
(
"checkbox-marked-circle",
[39 / 256, 174 / 256, 96 / 256, 1],
"Payé",
),
),
(
"Fabien",
"Bazar",
("alert", [255 / 256, 165 / 256, 0, 1], "En attente"),
),
(
"Casmir",
"Tee-shirt",
(
"checkbox-marked-circle",
[39 / 256, 174 / 256, 96 / 256, 1],
"Payé",
),
),
],
)
self.INTERFACE.ids.tableau_status_cotisation.add_widget(tab)
####################################################
## Tableau de status de cotisation #
####################################################
def __tableau_status_facture(self):
tab = MDDataTable(
size_hint=(0.815, 0.45),
column_data=[
("Membres", dp(50)),
("Factures", dp(50)),
("Status", dp(50)),
],
row_data=[
# The number of elements must match the length
# of the `column_data` list.
(
"Landry",
"Septembre",
("alert", [255 / 256, 165 / 256, 0, 1], "En attente"),
),
(
"Gaetan",
"Février",
("alert", [255 / 256, 165 / 256, 0, 1], "En attente"),
),
(
"Haja",
"Novembre",
(
"checkbox-marked-circle",
[39 / 256, 174 / 256, 96 / 256, 1],
"Payé",
),
),
(
"Fabien",
"Janvier",
("alert", [255 / 256, 165 / 256, 0, 1], "En attente"),
),
(
"Casmir",
"Décembre",
(
"checkbox-marked-circle",
[39 / 256, 174 / 256, 96 / 256, 1],
"Payé",
),
),
],
)
self.INTERFACE.ids.tableau_status_facture.add_widget(tab)
####################################################
## Tableau de transaction #
####################################################
def __tableau_transaction(self,transact):
self.tab = MDDataTable(
size_hint=(0.813, 0.45),
column_data=[
("Dates de transaction", dp(35)),
("Dates d'insertion", dp(30)),
("Membres", dp(25)),
("Montants", dp(25)),
("Raisons", dp(40)),
],
row_data=transact,
)
self.INTERFACE.ids.tableau_transaction.clear_widgets()
self.INTERFACE.ids.tableau_transaction.add_widget(self.tab)
####################################################
## Grand Menage #
####################################################
###Reinitialiser les tâches
def show_init_dialog(self,num):
self.num = num
self.dialog = None
if not self.dialog:
self.dialog = MDDialog(
title="Réinitialisation ?",
text="Voulez-vous vraiment réinitialiser cette tâche ?",
buttons=[
MDFlatButton(
text="ANNULER", text_color=self.theme_cls.primary_color, on_press=self.close_init_Dialog
),
MDFlatButton(
text="VALIDER", text_color=self.theme_cls.primary_color, on_press=self.close_init_Dialog
),
],
)
self.dialog.open()
def close_init_Dialog(self,btn):
if btn.text == "ANNULER":
self.dialog.dismiss()
if btn.text == "VALIDER":
self.INTERFACE.ids[f'raisedBtn{self.num}'].text = ""
self.dialog.dismiss()
###Modifier les tâches
def show_edit_dialog(self,num):
self.num = num
self.dialog = None
if not self.dialog:
cls = BoxLayout(
orientation= "vertical",
spacing= "12dp",
size_hint_y= None,
height= "120dp"
)
cls.add_widget(
MDLabel(
text = self.INTERFACE.ids[f'raisedBtn{self.num-1}'].text
)
)
self.personne = MDTextField(
text = self.INTERFACE.ids[f'raisedBtn{self.num}'].text,
)
self.dialog = MDDialog(
title="Grand Menage:",
type="custom",
content_cls = cls,
buttons=[
MDFlatButton(
text="ANNULER", text_color=self.theme_cls.primary_color, on_press=self.close_edit_Dialog
),
MDFlatButton(
text="OK", text_color=self.theme_cls.primary_color, on_press=self.close_edit_Dialog
),
],
)
cls.add_widget(self.personne)
self.dialog.open()
def close_edit_Dialog(self,btn):
if btn.text == "ANNULER":
self.dialog.dismiss()
if btn.text == "OK":
self.INTERFACE.ids[f'raisedBtn{self.num}'].text = self.personne.text
self.dialog.dismiss()
####################################################
## Cotisation #
####################################################
###Add cotisation
def add_cotis_dialog(self):
self.dialog = None
if not self.dialog:
cls = BoxLayout(
orientation= "vertical",
spacing= "12dp",
size_hint_y= None,
height= "210dp"
)
###Reason of the cotisation
cls.add_widget(
MDLabel(
text = "Motifs"
)
)
self.motifs_cotis = MDTextField()
cls.add_widget(self.motifs_cotis)
###Amount of the cotisation
cls.add_widget(
MDLabel(
text = "Montant"
)
)
self.argent_cotis = MDTextField()
cls.add_widget(self.argent_cotis)
###The date of the transaction
cls.add_widget(
MDLabel(
text = "Date"
)
)
self.date_cotis = MDTextField(on_release= self.show_date_picker)
cls.add_widget(self.date_cotis)
self.dialog = MDDialog(
title="Ajouter cotisation:",
type="custom",
content_cls = cls,
buttons=[
MDFlatButton(
text="ANNULER", text_color=self.theme_cls.primary_color, on_press=self.close_cotis_Dialog
),
MDFlatButton(
text="OK", text_color=self.theme_cls.primary_color, on_press=self.close_cotis_Dialog
),
],
)
self.dialog.open()
self.date_cotis.bind(
focus= lambda *args: self.show_date_picker()
)
def close_cotis_Dialog(self,btn):
if btn.text == "OK":
new_card = MDCard(
orientation = "vertical",
padding = "15dp",
size_hint = (None, None),
size = ("180dp", "220dp"),
pos_hint = {"center_x": 0.80, "center_y": 0.31}
)
new_card.add_widget(
MDFloatingActionButton(
icon = "alert",
user_font_size = "14sp",
theme_text_color = "Custom",
text_color = get_color_from_hex("#ffffff"),
md_bg_color = get_color_from_hex("#faaf00"),
elevation_normal = 0
)
)
new_card.add_widget(
MDLabel(
text = self.motifs_cotis.text,
pos_hint = {"x":0.30, "y":0.75},
font_size = '18sp'
)
)
new_card.add_widget(
MDRoundFlatIconButton(
icon = "currency-eur",
text = self.argent_cotis.text,
pos_hint = {"center_x":0.5, "center_y":0.5},
font_size = '17sp',
margin = "30dp"
)
)
new_card.add_widget(
MDIconButton(
icon= "trash-can",
theme_text_color = "Custom",
font_size = "18sp",
text_color = get_color_from_hex("#071f38"),
pos_hint= {"center_x":0.5, "center_y":0.3}
)
)
self.INTERFACE.ids.Cotisation.add_widget(new_card)
self.dialog.dismiss()
###Payer cotisation
def paye_cotisation(self):
self.dialog = None
if not self.dialog:
cls = BoxLayout(
orientation= "vertical",
spacing= "12dp",
size_hint_y= None,
height= "300dp"
)
###Reason of the payement
cls.add_widget(
MDLabel(
text = "Motifs"
)
)
self.motifs_paye = MDTextField()
cls.add_widget(self.motifs_paye)
###Who did the payement
cls.add_widget(
MDLabel(
text = "Prenom"
)
)
self.who_paye = MDTextField()
cls.add_widget(self.who_paye)
###Amount of the payement
cls.add_widget(
MDLabel(
text = "Montant"
)
)
self.argent_paye = MDTextField()
cls.add_widget(self.argent_paye)
###The date of the transaction
cls.add_widget(
MDLabel(
text = "Date de payement"
)
)
self.date_paye = MDTextField()
cls.add_widget(self.date_paye)
self.dialog = MDDialog(
title="Payement de cotisation:",
type="custom",
content_cls = cls,
buttons=[
MDFlatButton(
text="ANNULER", text_color=self.theme_cls.primary_color, on_press=self.close_paye_Dialog
),
MDFlatButton(
text="OK", text_color=self.theme_cls.primary_color, on_press=self.close_paye_Dialog
),
],
)
self.dialog.open()
def close_paye_Dialog(self,btn):
if btn.text == "OK":
self.transact.append((
self.date_paye.text,
datetime.date.today().strftime("%d-%m-%Y"),
self.who_paye.text,
self.argent_paye.text,
self.motifs_paye.text
))
self.__tableau_transaction(self.transact)
self.dialog.dismiss()
###Show DatePicker
def get_date(self, date):
'''
:type date: <class 'datetime.date'>
'''
def show_date_picker(self):
date_dialog = MDDatePicker(callback=self.get_date)
date_dialog.open()
GFS().run()