-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf_user_account.py
More file actions
1056 lines (974 loc) · 39 KB
/
f_user_account.py
File metadata and controls
1056 lines (974 loc) · 39 KB
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import f_login
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import MDFlatButton, MDIconButton, MDRaisedButton
from kivymd.uix.screen import MDScreen
from kivymd.uix.dialog import MDDialog
from kivymd.uix.textfield import MDTextField
from kivymd.uix.label import MDLabel
from kivymd.uix.pickers import MDDatePicker
from b_buyer_log import read_logs, delete_log
from kivy.clock import Clock
import pygame
from b_product import read_product
from f_components import MDFlatButton, MDIconButton, MDPersianLabel, MDBoxLayoutNoReverse
from b_charge_and_buy import buy, charge, read_charge
from f_create_numbers import create_numbers
from b_manage_buyers import check_name_is_new, change_buyer_name, change_buyer_face
from b_manage_users import user_type, current_user_name
from important_variables import FONT_PATH
from arabic_reshaper import reshape
from bidi.algorithm import get_display
import threading
import queue
last_was_operator = None
calculator_value = 0
user_name_ = ""
user_charge = 0
user_school = ""
user_class = ""
do = False
filter = []
date_filter = []
value_filter = []
type_filter = None
KV = """
<UserAccount>:
MDFloatLayout:
MDRectangleFlatIconButton:
button_text: app.language_dialogs["edit"]
icon: "account-cog"
pos_hint: {"x": 0,"y": .9}
size_hint: .4, .1
on_release: root.go_to_setting_page()
line_color: app.theme_cls.bg_normal
MDRectangleFlatIconButton:
button_text: app.language_dialogs["home"]
icon: "home"
pos_hint: {"x": .4,"y": .9}
size_hint: .4, .1
on_release: root.manager.current = "home"
line_color: app.theme_cls.bg_normal
MDPersianLabel:
label_text: root.user_name
id: user_name
pos_hint: {"x": .6,"y": .8}
size_hint: .2, .1
MDLabel:
id: user_charge
text: root.user_charge
pos_hint: {"x": 0,"y": .8}
size_hint: .2, .1
halign: "center"
valign: "center"
MDRectangleFlatIconButton:
button_text: app.language_dialogs["history"]
icon: "history"
size_hint: .2, .1
pos_hint: {"x": .8, "y": .9}
on_release: root.manager.current = "log"
line_color: app.theme_cls.bg_normal
MDIconButton:
icon: "delete"
pos_hint: {"x": 0,"y": .7}
size_hint: .2, .1
on_release: root.clear_products()
MDPersianLabel:
label_text: app.language_dialogs["buy"]
pos_hint: {"x": .15,"y": .7}
size_hint: .1, .1
MDTextField:
font_size: 20
valign: "center"
id: buy
text: "0"
pos_hint: {"x": .25,"y": .7125}
size_hint: .3, .075
readonly: True
MDRectangleFlatIconButton:
button_text: app.language_dialogs["buy"]
font_size: 12
icon: "credit-card"
on_release: root.charge_or_buy(root.user_name, root.ids.buy.text, "buy")
pos_hint: {"x": .55,"y": .7}
size_hint: .2, .1
line_color: app.theme_cls.bg_normal
MDFloatLayout:
id: charge_or_hand_enter
size_hint: 1, 1
pos_hint: {"x": -1,"y": 0}
MDIconButton:
icon: "delete"
pos_hint: {"x": 0,"y": .6}
size_hint: .2, .1
on_release: root.ids.charge.text = "0"
MDPersianLabel:
label_text: app.language_dialogs["charge"]
pos_hint: {"x": .15,"y": .6}
size_hint: .1, .1
MDTextField:
font_size: 20
valign: "center"
id: charge
text: "0"
pos_hint: {"x": .25,"y": .6125}
size_hint: .3, .075
readonly: True
MDRectangleFlatIconButton:
button_text: app.language_dialogs["charge"]
font_size: 12
icon: "battery-70"
on_release: root.charge_or_buy(root.user_name, root.ids.charge.text, "charge")
pos_hint: {"x": .55,"y": .6}
size_hint: .2, .1
line_color: app.theme_cls.bg_normal
Calculator:
id: calculator
pos_hint: {"x": 0,"y": .1}
size_hint: .8, .5
MDRectangleFlatIconButton:
button_text: app.language_dialogs["enter_product"]
font_size: 12
pos_hint: {"x": 0,"y": 0}
size_hint: .2, .1
on_release: root.change_view("charge_or_hand_enter", "enter_products")
line_color: app.theme_cls.bg_normal
MDRectangleFlatIconButton:
button_text: app.language_dialogs["add_to_buy"]
icon: "credit-card-plus"
font_size: 12
icon_size: 15
on_release: root.add_to_buy()
pos_hint: {"x": .2,"y": 0}
size_hint: .3, .1
line_color: app.theme_cls.bg_normal
MDRectangleFlatIconButton:
button_text: app.language_dialogs["add_to_charge"]
icon: "battery-plus"
font_size: 12
icon_size: 15
on_release: root.add_to_charge()
pos_hint: {"x": .5,"y": 0}
size_hint: .3, .1
line_color: app.theme_cls.bg_normal
MDFloatLayout:
id: enter_products
size_hint: 1, 1
pos_hint: {"x": 0,"y": 0}
MDPersianLabel:
id: product_name
pos_hint: {"x": .45,"y": .4}
size_hint: .15, .1
MDPersianLabel:
id: product_price
pos_hint: {"x": .3,"y": .4}
size_hint: .15, .1
MDIconButton:
icon: "minus-circle"
icon_size: 30
pos_hint: {"x": .425,"y": .325}
size_hint: .05, .05
on_release: root.ids.number_of_products.text = str(int(root.ids.number_of_products.text) - 1) if int(root.ids.number_of_products.text) > 0 else root.ids.number_of_products.text
MDLabel:
id: number_of_products
text: "0"
pos_hint: {"x": .49,"y": .325}
size_hint: .02, .05
font_size: 30
MDIconButton:
icon: "plus-circle"
icon_size: 30
pos_hint: {"x": .525,"y": .325}
size_hint: .05, .05
on_release: root.ids.number_of_products.text = str(int(root.ids.number_of_products.text) + 1)
MDRectangleFlatIconButton:
button_text: app.language_dialogs["add"]
icon: "arrow-left"
pos_hint: {"x": .65,"y": .3}
size_hint: .1, .1
on_release: root.add_product()
line_color: app.theme_cls.bg_normal
MDIconButton:
icon: "delete"
icon_size: 30
pos_hint: {"x": .3,"y": .3}
size_hint: .1, .1
on_release: root.clear_product_input()
MDTextFieldPersian:
mode: "round"
id: product_code
pos_hint: {"x": .29,"y": .2}
size_hint: .3, .1
on_text: root.update_product_name(self.str)
font_size: 30
halign: "center"
MDScrollView:
id: products_list
size_hint: .25, .5
pos_hint: {'x': 0,'y': .15}
MDRectangleFlatIconButton:
button_text: app.language_dialogs["charge_or_import_manually"]
font_size: 12
pos_hint: {"x": 0,"y": 0}
size_hint: .2, .1
on_release: root.change_view("enter_products", "charge_or_hand_enter")
line_color: app.theme_cls.bg_normal
MDPersianLabel:
id: school
pos_hint: {'x': .4, 'y': .8}
size_hint: .2, .1
MDPersianLabel:
id: class_
pos_hint: {'x': .2, 'y': .8}
size_hint: .2, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["reprocessing"]
pos_hint: {"x": .8,"y": 0}
size_hint: .2, .9
on_release: root.manager.current = "login"
line_color: app.theme_cls.bg_normal
<Setting>:
MDFloatLayout:
MDRectangleFlatIconButton:
button_text: app.language_dialogs["exit"]
icon: "location-exit"
on_release: root.manager.current = "user_account"
pos_hint: {"x": 0, "y": .9}
size_hint: .2, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_name"]
icon: "rename-box"
on_release: root.manager.current = "change_user_name"
pos_hint: {"x": .1,"y": .5}
size_hint: .8,.2
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_face"]
icon: "face-recognition"
on_release: root.manager.current = "change_user_face_ask"
pos_hint: {"x": .1,"y": .2}
size_hint: .8,.2
<ChangeUserName>:
FloatLayout:
MDRectangleFlatIconButton:
button_text: app.language_dialogs["exit"]
icon: "location-exit"
pos_hint: {"x": 0, "y": .9}
size_hint: .2, .1
on_release: root.manager.current = "setting"
MDTextFieldPersian:
id: new_name
persian_hint_text: app.language_dialogs["new_name"]
halign: "right"
pos_hint: {"x": .1, "y": .5}
size_hint: .8, .1
font_size: 15
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change"]
pos_hint: {"x": .1, "y": .1}
size_hint: .8, .2
on_release: root.change_user_name()
<ChangeUserFaceAsk>:
MDFloatLayout:
MDRectangleFlatIconButton:
button_text: app.language_dialogs["exit"]
icon: "location-exit"
pos_hint: {"x": 0, "y": .9}
size_hint: .2, .1
on_release: root.manager.current = "setting"
MDPersianLabel:
label_text: app.language_dialogs["are_you_sure"]
pos_hint: {"x": .1, "y": .5}
size_hint: .8, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["yes"]
pos_hint: {"x": .1, "y": .1}
size_hint: .8, .2
on_release: root.manager.current = "change_user_face_process"
<ChangeUserFaceProcess>:
MDFloatLayout:
MDPersianLabel:
label_text: app.language_dialogs["taking_picture"] + "..."
size_hint: .2, .1
pos_hint: {"x": .4, "y": .45}
MDSpinner:
size_hint: None, None
size: dp(46), dp(46)
pos_hint: {'center_x': .5, 'center_y': .4}
<Log>:
MDBoxLayout:
orientation: "vertical"
MDBoxLayout:
orientation: "horizontal"
size_hint: 1, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["exit"]
icon: "location-exit"
on_release: root.manager.current = "user_account"
MDLabel:
size_hint: 1, 1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["filter"]
icon: "filter-outline"
on_release: root.manager.current = "filter"
MDLabel:
size_hint: 1, 1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["delete"]
icon: "delete"
on_release: root.delete_log()
MDBoxLayout:
size_hint_y: .2
MDPersianLabel:
label_text: app.language_dialogs["products"]
size_hint: .2, .2
font_size: 30
MDPersianLabel:
label_text: app.language_dialogs["date"]
size_hint: .2, .2
font_size: 30
MDPersianLabel:
label_text: app.language_dialogs["price"]
size_hint: .1, .2
font_size: 30
MDPersianLabel:
label_text: app.language_dialogs["operation"]
size_hint: .1, .2
font_size: 30
MDBoxLayout:
orientation: "horizontal"
MDBoxLayout:
id: log_products
size_hint: 2, 1
orientation: "vertical"
MDBoxLayout:
id: log_date
size_hint: 2, 1
orientation: "vertical"
MDBoxLayout:
id: log_value
orientation: "vertical"
MDBoxLayout:
id: log_type
orientation: "vertical"
MDBoxLayout:
orientation: "horizontal"
size_hint: 1, .1
MDIconButton:
icon: "arrow-down"
on_release: root.scroll_down()
MDIconButton:
icon: "arrow-up"
on_release: root.scroll_up()
<Filter>:
MDFloatLayout:
MDCheckbox:
id: check_date
size_hint: .1, .1
pos_hint: {'x': .9, 'y': .85}
MDLabel:
text: app.persian(app.language_dialogs["date"])
font_name: app.FONT_PATH
size_hint: .1, .1
pos_hint: {'x': .85, 'y': .85}
MDRectangleFlatIconButton:
button_text: app.language_dialogs["select_date_from"]
icon: "calendar"
size_hint: .2, .1
pos_hint: {'x': .6, 'y': .75}
on_release: root.set_date_filter()
MDLabel:
id: from_date
size_hint: .2, .1
pos_hint: {'x': .6, 'y': .65}
MDRectangleFlatIconButton:
button_text: app.language_dialogs["select_date_to"]
icon: "calendar"
size_hint: .2, .1
pos_hint: {'x': .35, 'y': .75}
on_release: root.set_date_filter("to")
MDLabel:
id: to_date
size_hint: .2, .1
pos_hint: {'x': .35, 'y': .65}
MDCheckbox:
id: check_type
on_active: root.set_type_filter(self.active)
size_hint: .1, .1
pos_hint: {'x': .9, 'y': .6}
MDPersianLabel:
label_text: app.language_dialogs["operation"]
size_hint: .15, .1
pos_hint: {'x': .78, 'y': .6}
MDCheckbox:
group: "type"
id: is_buy
on_active: root.set_type_filter(root.ids.check_type.active)
size_hint: .1, .1
pos_hint: {'x': .6, 'y': .5}
MDCheckbox:
group: "type"
id: is_charge
on_active: root.set_type_filter(root.ids.check_type.active)
size_hint: .1, .1
pos_hint: {'x': .3, 'y': .5}
MDPersianLabel:
label_text: app.language_dialogs["buy"]
size_hint: .1, .1
pos_hint: {'x': .55, 'y': .5}
MDPersianLabel:
label_text: app.language_dialogs["charge"]
size_hint: .1, .1
pos_hint: {'x': .25, 'y': .5}
MDCheckbox:
id: check_value
size_hint: .1, .1
pos_hint: {'x': .9, 'y': .35}
MDPersianLabel:
label_text: app.language_dialogs["price_log"]
size_hint: .15, .1
pos_hint: {'x': .78, 'y': .35}
MDTextField:
id: value_from
font_size: 35
input_filter: "int"
size_hint: .3, .1
pos_hint: {'x': .44, 'y': .3}
MDTextField:
id: value_to
font_size: 35
input_filter: "int"
size_hint: .3, .1
pos_hint: {'x': .04, 'y': .3}
MDPersianLabel:
label_text: app.language_dialogs["from"]
size_hint: .1, .1
pos_hint: {'x': .7, 'y': .3}
MDPersianLabel:
label_text: app.language_dialogs["to"]
size_hint: .1, .1
pos_hint: {'x': .3, 'y': .3}
MDRectangleFlatIconButton:
button_text: app.language_dialogs["cancel"]
icon: "cancel"
on_release: root.cancel()
size_hint: .2, .1
pos_hint: {'x': .25, 'y': .05}
MDRectangleFlatIconButton:
button_text: app.language_dialogs["done"]
icon: "filter"
on_release: root.set_filter()
size_hint: .2, .1
pos_hint: {'x': .05, 'y': .05}
"""
class UserAccount(MDScreen):
user_name = ""
show_user_name = ""
user_charge = ""
products_list = []
do_shortcuts = False
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.event = Clock.schedule_interval(self.update, 1 / 10)
def on_leave(self, *args):
self.do_shortcuts = False
return super().on_leave(*args)
def update(self, dt):
if self.do_shortcuts:
keys = pygame.key.get_pressed()
keys_ = [str(number) for number in range(10)]
for key in keys_:
if keys[eval(f"pygame.K_KP_{key}")]:
self.ids.calculator.on_button_press(MDFlatButton(text=key))
if keys[pygame.K_KP_PLUS]:
self.ids.calculator.on_button_press(MDFlatButton(text='+'))
if keys[pygame.K_KP_MINUS]:
self.ids.calculator.on_button_press(MDFlatButton(text='-'))
if keys[pygame.K_KP_MULTIPLY]:
self.ids.calculator.on_button_press(MDFlatButton(text='×'))
if keys[pygame.K_KP_DIVIDE]:
self.ids.calculator.on_button_press(MDFlatButton(text='÷'))
if keys[pygame.K_KP_ENTER]:
self.ids.calculator.on_solution('')
if keys[pygame.K_HOME]:
self.change_screen('home')
if keys[pygame.K_s] and pygame.key.get_mods() & pygame.KMOD_CTRL:
self.change_screen('setting')
if keys[pygame.K_BACKSPACE]:
self.ids.calculator.delete_last_character('')
if keys[pygame.K_DELETE]:
self.ids.calculator.on_button_press(MDFlatButton(text='C'))
if keys[pygame.K_b] and pygame.key.get_mods() & pygame.KMOD_ALT:
self.add_to_buy()
if keys[pygame.K_b] and pygame.key.get_mods() & pygame.KMOD_CTRL:
self.charge_or_buy(self.user_name, self.ids.buy.text, "buy")
if keys[pygame.K_c] and pygame.key.get_mods() & pygame.KMOD_ALT:
self.add_to_charge()
if keys[pygame.K_c] and pygame.key.get_mods() & pygame.KMOD_CTRL:
self.charge_or_buy(
self.user_name, self.ids.charge.text, "charge")
if keys[pygame.K_r] and pygame.key.get_mods() & pygame.KMOD_CTRL:
self.change_screen("login")
def update_product_name(self, text):
product = read_product(text)
if product:
self.ids.product_name.label_text = MDApp.get_running_app(
).language_dialogs["name"] + ": " + \
product[0]
self.ids.product_price.label_text = MDApp.get_running_app(
).language_dialogs["price"] + ": " + \
str(product[2])
self.ids.number_of_products.text = "1"
else:
self.ids.product_name.label_text = ""
self.ids.product_price.label_text = ""
self.ids.number_of_products.text = "0"
def clear_product_input(self):
self.ids.product_code.text = ""
self.ids.product_code.str = ""
self.ids.product_name.label_text = ""
self.ids.product_price.label_text = ""
self.ids.number_of_products.text = "0"
def change_view(self, from_, to_):
self.ids[from_].pos_hint = {"x": -1, "y": 0}
self.ids[to_].pos_hint = {"x": 0, "y": 0}
def change_screen(self, screen_name):
self.manager.current = screen_name
def reduce_products(self, instance):
counted_items = []
count_dict = {}
for code, item in [[i[1], i] for i in self.products_list]:
if code in counted_items:
count_dict[code][0] += 1
else:
counted_items.append(code)
count_dict[code] = [1, item[1], item[2], item[0]]
code = instance.name
self.products_list.remove(read_product(int(code)))
if count_dict[int(code)][0] == 1:
del count_dict[int(code)]
else:
count_dict[int(code)][0] -= 1
items_layout = MDBoxLayout(
spacing=30, size_hint_y=None, orientation='vertical')
items_layout.bind(minimum_height=items_layout.setter('height'))
last_price = 0
for count, code, price, name in list(count_dict.values()):
last_price += count * int(price)
item_layout = MDBoxLayout(
orientation="horizontal", size_hint_y=None, height=40)
item_layout.add_widget(MDPersianLabel(
label_text=f"{MDApp.get_running_app().language_dialogs["name"]}: {name} {MDApp.get_running_app().language_dialogs["number"]}: {count}", size_hint_x=2))
item_layout.add_widget(MDIconButton(
name=str(code), icon="minus-circle", on_release=self.reduce_products))
items_layout.add_widget(item_layout)
self.ids.products_list.clear_widgets()
self.ids.products_list.add_widget(items_layout)
self.ids.buy.text = UserAccount.create_numbers(str(last_price))
def add_product(self):
if self.ids.product_code.str != "" and read_product(self.ids.product_code.str):
for _ in range(int(self.ids.number_of_products.text)):
self.products_list.append(read_product(
self.ids.product_code.str))
counted_items = []
count_dict = {}
for code, item in [[i[1], i] for i in self.products_list]:
if code in counted_items:
count_dict[code][0] += 1
else:
counted_items.append(code)
count_dict[code] = [1, item[1], item[2],
item[0]]
items_layout = MDBoxLayout(
spacing=30, size_hint_y=None, orientation='vertical')
items_layout.bind(minimum_height=items_layout.setter('height'))
last_price = 0
for count, code, price, name in list(count_dict.values()):
last_price += count * int(price)
item_layout = MDBoxLayout(
orientation="horizontal", size_hint_y=None, height=40)
item_layout.add_widget(MDPersianLabel(
label_text=f"{MDApp.get_running_app().language_dialogs["name"]}: {name} {MDApp.get_running_app().language_dialogs["number"]}: {count}", size_hint_x=2))
item_layout.add_widget(MDIconButton(
name=str(code), icon="minus-circle", on_release=self.reduce_products))
items_layout.add_widget(item_layout)
self.ids.products_list.clear_widgets()
self.ids.products_list.add_widget(items_layout)
self.ids.buy.text = UserAccount.create_numbers(str(last_price))
self.clear_product_input()
def clear_products(self):
self.ids.products_list.clear_widgets()
self.ids.buy.text = "0"
self.products_list = []
def on_enter(self):
global user_name_, user_charge, user_school, user_class
try:
user_name_ = f_login.user_name
charge_ = str(read_charge(user_name_))
user_charge = charge_
user_school = f_login.user_school
user_class = f_login.user_class
self.user_name = user_name_
self.ids.school.label_text = MDApp.get_running_app().language_dialogs["school"] + " " + \
f_login.user_school
self.ids.class_.label_text = MDApp.get_running_app(
).language_dialogs["class"] + " " + f_login.user_class
self.show_user_name = self.user_name
self.ids.user_name.label_text = self.show_user_name
self.user_charge = self.create_numbers(int(user_charge))
self.ids.user_charge.text = self.user_charge
self.products_list = []
self.do_shortcuts = True
except KeyError:
pass
@staticmethod
def create_numbers(number, extract: bool = False):
return create_numbers(number, extract)
def charge_or_buy(self, name: str, value: str, type: str) -> None:
global user_charge
value = self.create_numbers(value, True)
if type == "buy":
products_names_list = [item[0] for item in self.products_list]
buy(name, products_names_list, value)
self.clear_products()
elif type == "charge":
charge(name, value)
charge_ = str(read_charge(name))
self.ids.buy.text = "0"
self.ids.charge.text = "0"
self.ids.user_charge.text = self.create_numbers(charge_)
user_charge = charge_
def add_to_buy(self):
self.ids.calculator.on_solution("=")
try:
self.ids.buy.text = self.create_numbers(
self.create_numbers(self.ids.buy.text, True) + calculator_value)
if self.create_numbers(self.ids.buy.text, True) < 0:
self.ids.buy.text = "0"
except ValueError:
self.ids.buy.text = str(calculator_value)
self.ids.calculator.solution.text = "0"
def add_to_charge(self):
self.ids.calculator.on_solution("=")
try:
self.ids.charge.text = self.create_numbers(
self.create_numbers(self.ids.charge.text, True) + calculator_value)
if self.create_numbers(self.ids.charge.text, True) < 0:
self.ids.charge.text = "0"
except ValueError:
self.ids.charge.text = str(calculator_value)
self.ids.calculator.solution.text = "0"
def go_to_setting_page(self):
if user_type(current_user_name()) in ("creator", "admin"):
self.manager.current = "setting"
else:
persian_text = MDApp.get_running_app(
).language_dialogs["admin_and_manager"]
text = "[font={}]{}[/font]".format(FONT_PATH,
get_display(reshape(persian_text)))
self.dialog = MDDialog(
title=text,
buttons=[
MDFlatButton(
text=get_display(
reshape(
MDApp.get_running_app(
).language_dialogs["i_got_it"]
)
),
font_name=FONT_PATH,
on_release=lambda instance: self.dialog.dismiss()
)
]
)
self.dialog.open()
class Calculator(MDBoxLayoutNoReverse):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
self.solution = MDTextField(
text="0", multiline=False, readonly=True,
halign="right", font_size=25
)
self.add_widget(self.solution)
buttons = [
["7", "8", "9", "Del"],
["4", "5", "6", "C"],
["1", "2", "3", "÷"],
["00", "0", "000", "×"],
["=", "+", "-"]
]
for row in buttons:
h_layout = MDBoxLayoutNoReverse()
for label in row:
if label not in ["=", "Del"]:
button = MDRaisedButton(
text=label,
font_size=25,
size_hint=(1, 1)
)
elif label == "Del":
button = MDIconButton(
icon="backspace",
icon_size=40,
size_hint=(1, 1)
)
else:
button = MDRaisedButton(
text=label,
font_size=25,
size_hint=(2, 1)
)
if label in ("+", "-", "×", "÷"):
button.md_bg_color = (0, 1, 0, 1)
elif label == "C":
button.md_bg_color = (1, 0, 0, 1)
elif label == "Del":
button.md_bg_color = (0, 0, 0, 0)
else:
button.md_bg_color = (.4, .4, 1, 1)
if label == "000":
button.font_size = 20
if label not in ("=", "Del"):
button.bind(on_press=self.on_button_press)
elif label == "Del":
button.bind(on_press=self.delete_last_character)
else:
button.md_bg_color = (1, 1, 0, 1)
button.bind(on_press=self.on_solution)
h_layout.add_widget(button)
self.add_widget(h_layout)
def delete_last_character(self, instance):
self.solution.text = self.solution.text[:-1]
if self.solution.text == "":
self.solution.text = "0"
def on_button_press(self, instance):
global last_was_operator
button_text = instance.text
if button_text in ["÷", "×"]:
button_text = {"×": "*", "÷": "/"}[button_text]
operators = ["/", "*", "+", "-"]
current = self.solution.text
if button_text == "C":
self.solution.text = "0"
else:
if self.solution.text == "Error":
return
if last_was_operator and button_text in operators:
return
elif current == "" and button_text in operators:
return
elif (current.endswith(("-0", "+0", "*0", "/0"))
or current == "0") and button_text in ("0", "00", "000"):
return
elif last_was_operator and button_text in ("00", "000"):
return
else:
if (current.endswith(("-0", "+0", "*0", "/0")) or current ==
"0") and button_text in [str(x + 1) for x in range(9)]:
current = current[:-1]
new_text = current + button_text
self.solution.text = new_text.replace(
"/", "÷", new_text.count("/")).replace("*", "×", new_text.count("*"))
last_was_operator = button_text in operators
def on_solution(self, instance):
global calculator_value
text = self.solution.text
try:
if text:
if text != "Error":
calculator_value = int(eval(self.solution.text.replace(
"÷", "/", self.solution.text.count("÷")).replace("×", "*", self.solution.text.count("×"))))
solution = str(calculator_value)
self.solution.text = solution
else:
self.solution.text = "0"
except (SyntaxError, ZeroDivisionError):
self.solution.text = "Error"
class Setting(MDScreen):
pass
class ChangeUserName(MDScreen):
do_shortcuts = False
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.event = Clock.schedule_interval(self.update, 1 / 10)
def on_leave(self, *args):
self.do_shortcuts = False
return super().on_leave(*args)
def update(self, dt):
if self.do_shortcuts:
keys = pygame.key.get_pressed()
if keys[pygame.K_RETURN]:
self.change_user_name()
def on_enter(self):
self.do_shortcuts = True
def close_dialog(self, instance):
self.dialog.dismiss()
def change_user_name(self):
new_name = self.ids.new_name.str
if new_name != "" and check_name_is_new(new_name):
change_buyer_name(user_name_, new_name)
f_login.user_name = new_name
self.ids.new_name.str = ""
self.manager.current = "user_account"
else:
persian_text = MDApp.get_running_app(
).language_dialogs["name_wrong_error"]
text = "[font={}]{}[/font]".format(FONT_PATH,
get_display(reshape(persian_text)))
self.dialog = MDDialog(
title=text,
buttons=[
MDFlatButton(
text=get_display(
reshape(
MDApp.get_running_app(
).language_dialogs["i_got_it"]
)
),
font_name=FONT_PATH,
on_release=self.close_dialog
)
]
)
self.dialog.open()
class ChangeUserFaceAsk(MDScreen):
pass
class ChangeUserFaceProcess(MDScreen):
def on_enter(self):
self.queue = queue.Queue()
Clock.schedule_interval(self.process_queue, 0.1)
self.start_worker_thread()
def start_worker_thread(self):
def worker():
global user_name_
change_buyer_face(user_name_)
self.queue.put(lambda: setattr(self.manager, 'current', 'user_account'))
threading.Thread(target=worker).start()
def process_queue(self, dt):
while not self.queue.empty():
callback = self.queue.get()
callback()
class Log(MDScreen):
first_item_index = 0
items = []
def delete_log(self):
global filter, date_filter, type_filter, value_filter
if user_type(current_user_name()) in ("creator", "admin"):
delete_log(self.items)
filter = []
date_filter = []
value_filter = []
type_filter = None
self.on_enter()
else:
persian_text = MDApp.get_running_app().language_dialogs["admin_and_manager"]
text = "[font={}]{}[/font]".format(FONT_PATH,
get_display(reshape(persian_text)))
self.dialog = MDDialog(
title=text,
buttons=[
MDFlatButton(
text=get_display(
reshape(
MDApp.get_running_app(
).language_dialogs["i_got_it"]
)
),
font_name=FONT_PATH,
on_release=lambda instance: self.dialog.dismiss()
)
]
)
self.dialog.open()
def scroll_up(self):
self.first_item_index -= 5
self.update()
def scroll_down(self):
self.first_item_index += 5
self.update()
def on_enter(self):
global filter, date_filter, type_filter, value_filter
self.first_item_index = 0
try:
self.items = read_logs(by="name", name=user_name_)
for filter_item in filter:
if filter_item == "operation":
self.items = read_logs(
by=filter_item, logs=self.items, operation={"c": "charge", "b": "buy"}[type_filter])
elif filter_item == "price":
self.items = read_logs(
by=filter_item, logs=self.items, start_price=value_filter[0], end_price=value_filter[1])
elif filter_item == "date":
self.items = read_logs(
by=filter_item, logs=self.items, start_date=date_filter[0], end_date=date_filter[1])
self.update()
except:
self.items = read_logs(by="name", name=user_name_)
self.update()
def update(self):
if self.first_item_index < 0:
self.first_item_index = 0
self.ids.log_value.clear_widgets()
self.ids.log_type.clear_widgets()
self.ids.log_date.clear_widgets()
self.ids.log_products.clear_widgets()
products_str = ""
for item in self.items[self.first_item_index:self.first_item_index + 5]:
try:
for product in eval(item[4]):
products_str += product + " - "
products_str = products_str[:-3]
except:
pass
products_str = "------" if products_str == "" else products_str
self.ids.log_products.add_widget(MDPersianLabel(
label_text=products_str, size_hint=(1, 1)))
products_str = ""