-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional_not updating values_updtes when restarted_.py
1167 lines (990 loc) · 36.7 KB
/
functional_not updating values_updtes when restarted_.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
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
'''
pHint = size of calendar
date handeled at backend=%Y-%m-%d;frontend:"%d-%m-%Y"
size_hint = size of text label
size_hint:popup ka
pos_hint screen ka
imp for correct placements:
size: self.texture_size
size_hint: None,None
popup is edited and called externally
never forget that super.init()
init has no self for object property but need 1 when accesing
float layots's size hint is only accesed not pos hint
https://stackoverflow.com/questions/49935190/kivy-how-to-initialize-the-viewclass-of-the-recycleview-dynamically
https://kivy.org/doc/stable/api-kivy.properties.html--props,bind
in kivy .bind==@property
def state_change(self):
return _state_change
@state_change.setter
def state_change(self, value):
print(value, 'LOL--Changed', self.calendar._state_change)
# print(value, 'LOL--Changed', self.calendar.state)both prints same
# print(self.calendar, instance)both prints same
'''
'''
-------------bug----------
init problems for class--Solved
date sapcing in update-
rv-popup?--dropped 4 now
reading from file blocks highlight in set()
centering te text in databse label
'''
# Program to Show how to create a switch
# import kivy module
import kivy
from kivy.factory import Factory
# base Class of your App inherits from the App class.
# app:always refers to the instance of your application
from kivy.app import App
from kivy.uix.spinner import Spinner
# this restrict the kivy version i.e
# below this kivy version you cannot
# use the app or software
kivy.require('1.9.0')
from kivy.uix.textinput import TextInput
from kivy.properties import ObjectProperty, ListProperty
from kivy.uix.popup import Popup
from kivy.uix.label import Label
# Builder is used when .kv file is
# to be used in .py file
from kivy.lang import Builder
from kivy.core.window import Window
# The screen manager is a widget
# dedicated to managing multiple screens for your application.
from kivy.uix.screenmanager import ScreenManager, Screen
import datepicker
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.checkbox import CheckBox
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.properties import BooleanProperty
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.behaviors import FocusBehavior, ButtonBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.slider import Slider
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from att_interactdb import database
import datetime
from functools import partial # --animation progress bar circular
from kivy.clock import Clock
from kivy.core.text import Label as CoreLabel
from kivy.graphics import Color, Ellipse, Rectangle
from kivy.uix.image import Image
from kivy.uix.progressbar import ProgressBar
import time
# Window.size = (550, 700)
#-------------to be changed at interaction-------------
max = 7
default = 5
max_view = 5 # days
daysoff = 2
days_val = 'Saturday,Sunday'
data = 'none' # string vala none xD
error = 'none'
db = None
def set_data():
global max, max_view, default, daysoff, days_val, data, error, db
with open('settings.txt', 'w+') as f:
f.write('lec_in_day:' + str(max) + '\n')
f.write('daysoff:' + str(daysoff) + '\n')
f.write('days_val:' + str(days_val) + '\n')
f.write('lec_default:' + str(default) + '\n')
f.write('max_days:' + str(max_view) + '\n') # max views
f.write('Data:' + str(data))
def get_data():
global max, max_view, default, daysoff, days_val, data, error, db
try:
with open('settings.txt', 'r') as f:
values = [x.split(':') for x in f.read().split('\n')]
max = int(values[0][1])
daysoff = int(values[1][1])
days_val = values[2][1]
default = int(values[3][1])
max_view = int(values[4][1])
data = values[5][1]
except:
error = 'Internl error code:unable to read database of settings'
print(error)
set_data()
get_data()
get_data()
def set_database():
global max, max_view, default, daysoff, days_val, data, error, db
db = database(max, data)
db.create()
def parse_date(text):
day, month, year = (int(i) for i in text.split('-'))
return day, month, year
Builder.load_string("""
#:import Factory kivy.factory.Factory
# ------------------Essentials---------------------------
<SelectableLabel>:
# Draw a background to indicate selection
col_1:col_1
col_2:col_2
col_3:col_3
col_4:col_4
col_5:col_5
canvas.before:
Color:
rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
Rectangle:
pos: self.pos
size: self.size
Label:
id:col_1
text:'None'
Label:
id:col_2
text:'None'
Label:
id:col_3
text:'None'
Label:
id:col_4
text:'None'
Label:
id:col_5
text:'None'
<Imagebutton>:
size_hint: (None, None)
<MultiSelectOption@ToggleButton>:
size_hint: 1, None
height: '48dp'
<Customlabel@Label>:
color:0,0,0,1
font_size:44
multiline:True
text_size: root.width, None
size: self.texture_size
size_hint_y: None ##imp
<Custombutton@Button>:
font_size: 24
size_hint: None,None
focus:True
<Custominput@TextInput>:
size_hint: .12,.07
font_size:30
text_size: root.width, None
focus:True
multiline:False
padding:(40,5)
<Infopopup>:
auto_dismiss: False
title:"Invalid Entry"
label:label
layout:layout
size_hint:0.5,0.5
FloatLayout:
pos_hint:{'center_y':.5,'center_x':.5}
##after dividing screen now .5,.5 is base_size all iszes will be added accordingly
FloatLayout:
size_hint:1,0.5
##pos:root.width*.2, root.height / 2
pos_hint:{'top':0.4,'center_x':0.2}
Customlabel:
id:label
pos_hint:{'x':0.4,'y':1}
font_size:23
Custombutton:
size_hint:0.2,0.2
pos_hint:{'center_x':0.8,'center_y':0.5}
text: 'OK'
on_release: root.dismiss(),root.my_widget.remove_widgets()
FloatLayout:
size_hint:1,0.5
pos_hint:{'top':0.8,'center_x':0.3}
id:layout
<MyPopup>:
auto_dismiss: False
title:"Confirm"
label:label
size_hint:0.5,0.5
FloatLayout:
Customlabel:
id:label
pos_hint:{'x':0.015,'y':0.6}
font_size:23
Custombutton:
size_hint:0.2,0.2
pos_hint:{'x':0.6,'y':0.16}
text: 'Close'
on_release: root.dismiss()
Custombutton:
size_hint:0.2,0.2
pos_hint:{'x':0.2,'y':0.16}
text: 'Save'
on_release:root.my_widget.submit()
<Submitbutton@Button>:
font_size: 24
size_hint: None,None
<RV>:
viewclass: 'SelectableLabel'
SelectableRecycleBoxLayout:
default_pos_hint:{"x":0.01,}
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
multiselect: True
touch_multiselect: True
# ------------------Main_interface---------------------------
<MainWindow>:
name:"main"
FloatLayout:
padding : 10, 10
Customlabel:
text:'Attendance Monitiring'
pos_hint:{'x':0.3,'y':0.9}
Custombutton:
pos_hint:{'x':0.05,'y':0.45}
text: "update"
on_release:
app.root.current = "update"
root.manager.transition.direction = "left"
Custombutton:
pos_hint:{'x':0.05,'y':0.05}
text: "Settings"
on_release:
app.root.current = "set"
root.manager.transition.direction = "left"
Custombutton:
pos_hint:{'x':0.55,'y':0.05}
text: "delete"
on_release:
app.root.current = "delete"
root.manager.transition.direction = "left"
Custombutton:
pos_hint:{'x':0.55,'y':0.45}
text: "View"
on_release:
app.root.current = "View_data"
root.manager.transition.direction = "left"
# ------------------Update_data---------------------------
<Updating>:
name:"update"
datepickers:datepickers
spinner_up_lt:spinner_up_lt
spinner_up_la:spinner_up_la
box_id:box_id
took_off:took_off
notification:notification
FloatLayout:
padding : 10, 10
Customlabel:
text:'Updating Data'
pos_hint:{'x':0.3,'y':0.9}
Submitbutton:
size_hint:0.2,0.1
pos_hint:{'x':0.4,'y':0.2}
text:"submit"
on_press:root.popup()
Customlabel:
text:"Enter Date:"
font_size:30
pos_hint:{'x':0.1,'y':0.7}
DatePicker: ##for calender handling------------------------kivy-ui-commands
id:datepickers
on_text:root.checkdate(self)
pHint:(0.8,0.8)
size_hint: .12,.07
padding : 10, 10
pos_hint:{'x':0.5,'y':0.7}
Customlabel:
text:"Lectures Attended:"
font_size:30
pos_hint:{'x':0.1,'y':0.6}
Spinner: ##for changing lectures attended-------------------------db-commands
id:spinner_up_la
text:'0'
size_hint:0.12,0.07
pos_hint:{'x':0.5,'y':0.6}
Customlabel:
text:"Lectures Took:"
font_size:30
pos_hint:{'x':0.1,'y':0.5}
Spinner: ##for changing lectures took-------------------------db-commands
id:spinner_up_lt
text:'0'
size_hint:0.12,0.07
pos_hint:{'x':0.5,'y':0.5}
Customlabel:
text:"Holiday"
font_size:30
pos_hint:{'x':0.1,'y':0.4}
Customlabel:
id:notification
text:"(unchecking this box will make the holiday counted as working day)"
font_size:12
opacity: 0
pos_hint:{'x':0.1,'y':0.38}
CheckBox: ##for holiday cheking-------------------------------ui-command
id: box_id
size_hint:0.12,0.07
pos_hint:{'x':0.5,'y':0.4}
on_active: root.box_on(self,self.active)
color:0,0,0,1
Customlabel:
text:"Took Off"
font_size:30
pos_hint:{'x':0.1,'y':0.3}
CheckBox: ##for holiday taken-------------------------------ui-command
id: took_off
size_hint:0.12,0.07
pos_hint:{'x':0.5,'y':0.3}
on_active: root.took_off_day(self,self.active)
color:0,0,0,1
Custombutton:
font_size:14
size_hint:0.06,0.06
pos_hint:{"x":0.8,"y":0.85}
text: "Home"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
root.manager.transition.duration = 0.5
# ------------------Delete_data---------------------------
<Deleting>:
name:"delete"
switch_id:switch_id
slider:slider
val:val
recycleview:recycleview
FloatLayout:
size_hint:1,0.5
padding : 10, 10
Customlabel:
text:"deleting"
pos_hint:{'x':0.3,'y':0.9+0.92}
Customlabel:
text:"Record of days:"
pos_hint:{'x':0.1,'y':0.7+0.87}
font_size:30
Slider:
id: slider
size_hint:0.8,0.1
pos_hint:{'x':0.1,'y':0.55+0.77}
min: 1
max: 2
step: 1
Customlabel:
text: str(slider.value)
pos_hint:{'x':0.5,'y':0.5+0.97}
font_size:30
Customlabel:
text:"show data box:"
pos_hint:{'x':0.1,'y':0.4+0.67}
font_size:30
Switch:
id:switch_id
size_hint:None,None
pos_hint:{'x':0.4,'y':0.3+0.67}
# self.active passes self,instance,value-which true or flase
on_active: root.on_active(self,self.active)
Custombutton:
font_size:14
size_hint:0.06,0.06
pos_hint:{"x":0.8,"y":0.85+0.92}
text: "Home"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
root.manager.transition.duration = 0.5
FloatLayout:
size_hint:1,0
id:val
Imagebutton:##--to update database
pos_hint:{'x':0.6,'y':0.45+0.67}
size_hint:0.1,0.07
source:'icons/checkmark-outline.png'
on_press:root.update()
Imagebutton:##--to refresh text
pos_hint:{'x':0.7,'y':0.45+0.67}
size_hint:0.1,0.07
source:'icons/refresh-outline.png'
on_press:root.refresh()
RV:
id:recycleview
# ------------------Set_data---------------------------
<Set>:
name:"set"
max_l:max_l
days:days
default_la:default_la
spinner_up:spinner_up
database_name:database_name
FloatLayout:
padding:10,10
Customlabel:
text:"Settings"
pos_hint:{'x':0.3,'y':0.9}
Customlabel:
text:"Enter Max Lectures:"
font_size:30
pos_hint:{'x':0.1,'y':0.7}
Custominput:
id:max_l
text:'7'
pos_hint:{'x':0.6,'y':0.7}
Customlabel:
text:"Enter Default Lectures:"
font_size:30
pos_hint:{'x':0.1,'y':0.6}
Custominput:
id:default_la
text:'5'
pos_hint:{'x':0.6,'y':0.6}
Customlabel:
text:"Enter Max records to display:"
font_size:30
pos_hint:{'x':0.1,'y':0.5}
Custominput:
id:days
text:'5'
pos_hint:{'x':0.6,'y':0.5}
Customlabel:
text:"Enter Holidays:"
font_size:30
pos_hint:{'x':0.1,'y':0.4}
MultiSelectSpinner: ##for changing holidays took-------------------------db-commands
id:spinner_up
text:'Saturday,Sunday'
padding:(10,10)
text_size : self.width, None
values:'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'
size_hint:0.35,0.07
pos_hint:{'x':0.6,'y':0.4}
Submitbutton:
size_hint:0.2,0.1
pos_hint:{'x':0.4,'y':0.2}
text:"submit"
on_press:root.popup()
Customlabel:
text:"Enter person name:"
font_size:30
pos_hint:{'x':0.1,'y':0.3}
Custominput:
id:database_name
padding:(20,5)
size_hint: .35,.07
text:'5'
text_size : self.width, None
pos_hint:{'x':0.6,'y':0.3}
Custombutton:
font_size:14
size_hint:0.06,0.06
pos_hint:{"x":0.8,"y":0.85}
text: "Home"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
root.manager.transition.duration = 0.5
# ------------------View_data---------------------------
<View_data>:
name:"view_data"
cp:cp
calendar:calendar
FloatLayout:
Customlabel:
text:'Viewing Records'
pos_hint:{'x':0.3,'y':0.9}
CircularProgressBar:
id:cp
size_hint: (None, None)
height: root.height*0.2
width: root.height*0.2
max: 100
pos_hint:{'x':0.4,'y':0.65}
CalendarWidget:
id:calendar
## pHint:(0.5,0.5)
pos_hint:{'x':0.1,'y':0.05}
size_hint:(0.6,0.6)
padding : 10, 10
Custombutton:
font_size:14
size_hint:0.06,0.06
pos_hint:{"x":0.8,"y":0.85}
text: "Home"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
root.manager.transition.duration = 0.5
""")
# Create a class for all screens in which you can include
# helpful methods specific to that screen
class MainWindow(Screen):
pass
#-------------------------------UPDATING----------------------------------
class Updating(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
#-----------Calling-Ids--------------Class-Variables-----------
Clock.schedule_once(self._do_setup)
# self.t is aninstance of mypop and here self passed act as my_widget
self.set()
def _do_setup(self, *args):
datepickers = ObjectProperty(None)
spinner_up_lt = ObjectProperty(None)
spinner_up_la = ObjectProperty(None)
box_id = ObjectProperty(None)
took_off = ObjectProperty(None)
notification = ObjectProperty(None)
self.t = MyPopup(self)
self.i = Infopopup(self)
self.holiday = 'w'
self.days = 'Monday'
#-----------Holidays-setting-------------------------
def set_holiday(self): # setting values for all spinners in case of holiday
self.spinner_up_la.values = self.spinner_up_lt.values = (
'0') # (total lectures equal)
self.spinner_up_la.text = self.spinner_up_lt.text = '0'
def box_on(self, instance, value):
print('called box on')
if(value is True):
self.set_holiday()
self.notification.opacity = 1
self.holiday = 'h'
self.took_off.active = False
else:
# self.notification.font_size = 0
self.notification.opacity = 0
self.holiday = 'w'
self.set_la_lt_default()
def on_enter(self):
print('/n \n entered called')
def took_off_day(self, instance, value):
print('caleed took off')
if(value is True):
self.box_id.active = False
self.holiday = 'w'
self.spinner_up_la.values = ('0')
self.spinner_up_la.text = '0'
print('took off called')
else:
self.checkdate()
def popup(self):
text = "Confirm entery of " + self.datepickers.text + " as a " + \
("\n holiday" if(self.box_id.state == "down") else "\n working day.")
self.t.open()
self.t.label.text = text
# self.t.label refers to label decalred in my_wifget in popup
def checkdate(self, *args, **kwargs):
global max, max_view, default, daysoff, days_val, data, error, db
day, month, year= parse_date(self.datepickers.text)
print(year, month, day)
self.days = datetime.date(year, month, day).strftime("%A")
if(self.days in days_val.split(',')):
print('callllled')
self.box_id.active = True
def submit(self):
global error, db
print("called submit", self.datepickers.text)
db.create()
day, month, year = parse_date(self.datepickers.text)
parsed_date=datetime.date(
year, month, day).strftime("%Y-%m-%d")
try:
db.insert(self.days, parsed_date, int(self.spinner_up_la.text), int(
self.spinner_up_lt.text), self.holiday)
except:
self.i.open()
self.i.label.text = '\nINVALID ENTRY TO DATABASE\n\n ->Check Respective Constrain\n ->Chek for duplicate entries'
print(db.show_all(), db) # -----------------testing
self.set()
self.t.dismiss()
def remove_widgets(self):
self.i.layout.clear_widgets()
def set_la_lt_default(self):
self.spinner_up_la.values = tuple([str(x) for x in range(max + 1)])
# (total lectures equal)
self.spinner_up_lt.values = self.spinner_up_la.values
self.spinner_up_la.text = str(default)
self.spinner_up_lt.text = str(max)
#-----------Ideal-Settings--------------------------
def set(self):
global max, max_view, default, daysoff, days_val, data, error, db
#-----------la-lt-being-setted-----------------------
self.datepickers.text = ('-'.join(self.datepickers.text.split('/')))
print("Set func date picker value", self.datepickers.text)
self.set_la_lt_default()
self.box_id.value = False
#------------------------DELETING_INTERFACE---------------------------------
class Deleting(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Clock.schedule_once(self._do_setup)
self.set()
def _do_setup(self, *args):
switch_id = ObjectProperty(None)
slider = ObjectProperty(None)
val = ObjectProperty(None)
row = ListProperty([]) # list because data is type of kivy list object
no_entries = {}
recycleview = ObjectProperty(None)
def on_enter(self):
print('/n \n entered called')
self.refresh()
def on_active(self, instance, value):
print("caleed ", value)
if (value is True):
self.val.size_hint = 1, 0.5
# self.x = FloatLayout(
# size_hint=(1, 0.5), id='val')
# self.ids.val.add_widget(RV(id='y'))
else:
self.val.size_hint = 1, 0
# self.remove_widget(self.x)
def refresh(self):
global db
# db.insert('M', '12.10.19', 5, 7, 'h')
# print(db, db.show_all())
self.recycleview.data = self.row
database_values = db.show_all()
try: # handle any excpetion in rv
if(database_values):
for tuples in database_values:
print(tuples[0])
self.recycleview.data.append({'col1': {'text': str(tuples[0])}, 'col2': {'text': str(tuples[1])}, 'col3': {
'text': str(tuples[2])}, 'col4': {'text': str(tuples[3])}, 'col5': {'text': str(tuples[4])}})
# {[ {'label2': {'text': 'pineapple'}, 'label3': {'text': 'cat'} }, {'label2': {'text': 'apple'}, 'label3': {'text': 'rat'}}, {'label2': {'text': 'banana'}, 'label3': {'text': 'dog'}}, {'label2': {'text': 'pear'}, 'label3': {'text': 'bat'}}]}
# print("Nope", self.recycleview.data) # - -no need of zip here
else:
self.recycleview.data.append(self.no_entries)
except:
error = 'Internl error code:error indeleting/rv probs'
print(error)
# def get_selected(self):
# global max, max_view, default, daysoff, days_val, data, error, db
def update(self):
global db, error
try:
if(SelectableLabel.selected_values):
if(SelectableLabel.selected_values[0] == 'no entry yet'):
self.delete_empty()
else:
print(SelectableLabel.selected_values)
for i in SelectableLabel.selected_values:
db.delete(i['col2']['text'])
self.refresh()
else:
self.delete_empty()
except:
error = 'Internl error code:error in updating/database commands'
print(error)
def delete_empty(self):
global error
error = 'Nothing to Delete / Update here'
print(error)
def set(self):
# self.data requires----------------- {'text': '9'}]--list pf dictonary
set_database() # database must exist before delete
self.row = [{'col1': {'text': 'Day'}, 'col2': {'text': 'Date'}, 'col3': {
'text': 'Lecture Attended'}, 'col4': {'text': 'Lecture took'}, 'col5': {'text': 'Holiday'}}] # a base row
self.no_entries = {'col1': {'text': ''}, 'col2': {'text': ''}, 'col3': {
'text': 'no entry yet'}, 'col4': {'text': ''}, 'col5': {'text': ''}}
print("called set of RV")
print('rv,setted=', self.row)
# print(db.show_all()) # -----------------testing
self.slider.max = max_view
self.refresh()
#------------------------SETTING_INTERFACE---------------------------------
class Set(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.t = MyPopup(self)
max_l = ObjectProperty(None)
days = ObjectProperty(None)
default_la = ObjectProperty(None)
spinner_up = ObjectProperty(None)
database_name = ObjectProperty(None)
self.sets()
def popup(self):
text = "Save Changes?"
self.t.open()
self.t.label.text = text
def submit(self):
print("Changes saved", self.max_l.text,
self.days.text, self.default_la.text)
self.set_help() # global helping
set_data() # global_saving
get_data() # global adding
self.t.dismiss()
def set_help(self):
global max, max_view, default, daysoff, days_val, data
max = self.max_l.text
max_view = int(self.days.text) # max_view
default = int(self.default_la.text)
days_val = self.spinner_up.text
daysoff = len(days_val.split(','))
# no of days,sunday,saturdayetc
data = str(self.database_name.text)
def sets(self):
self.max_l.text = str(max)
self.days.text = str(max_view) # max_view
self.default_la.text = str(default)
self.spinner_up.text = str(days_val)
self.database_name.text = str(data)
# Updating.set()
# self.spinner_up.self.selected_values = ['Saturday', 'Sunday']
pass
#-----!@$#%^&*()- Clock.schedule_once(self.checkdate)
#------------------------VIEW_DATA_INTERFACE---------------------------------
class View_data(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Clock.schedule_once(self._do_setup)
def _do_setup(self, *args):
cp = ObjectProperty(None)
calendar = ObjectProperty(None)
app = App.get_running_app()
self.cp.opacity = 0
self.i = Infopopup(self)
self.cp.height = app.root.height * 0.2
# self.calendar.init_ui([17, 18, 19], [9]) # --tKWN OFF
def on_btn_press(self, instance, value):
global db
# print(value, 'LOL--Changed', self.calendar.state)both prints same
# print(self.calendar, instance)both prints same
print(instance.active_date)#handling list
text_maker = [str(i) for i in instance.active_date]
# equilizing date adding 0 before
# if(len(text_maker[0]) % 2 == 1):
# text_maker[0] = '0' + text_maker[0]
text_maker = '-'.join(text_maker)
day, month, year= parse_date(text_maker)
text_maker=datetime.date(
year, month, day).strftime("%Y-%m-%d")
self.i.open()
self.i.title = 'ok'
info = db.show_by_date(text_maker)
print(info, type(info))
# holiday represented by col
if(len(info) > 0):
i = info[0]
grid = GridLayout(cols=4, pos_hint={'x': 0.2, 'y': 0.6})
grid.add_widget(Label(text=str(i[0]), font_size=14))
grid.add_widget(Label(text=str(i[1]), font_size=14))
grid.add_widget(Label(text=str(i[2]), font_size=14))
grid.add_widget(Label(text=str(i[3]), font_size=14))
self.i.layout.add_widget(grid)
else:
self.remove_widgets() # it may delete exit button
print("Valuees are:", self.i.layout.height, self.i.layout.width,
self.i.layout.pos, self.i.layout.pos_hint)
def remove_widgets(self):
self.i.layout.clear_widgets()
def on_enter(self):
self.cp.value = 0
self.max_value = db.percentage()
steps = self.max_value * 0.25 if self.max_value!=0 else 0
e = Clock.schedule_interval(
partial(self.animate, self.max_value, steps), 0.03)
self.calendar.bind(state=self.on_btn_press) # state in calendar class
_, _, info_off = db.working_la_lt_find()
info_holiday = db.show_holidays('h')
#date alteration for this handeled at backend(parsed as %Y-%m-%d)
# info_off=[datetime.date(
# *parse_date(i)).strftime("%d-%m-%Y") for i in info_off ]#parse will reurnas yr,m,d
# info_holiday=[datetime.date(
# *parse_date(i)).strftime("%d-%m-%Y") for i in info_holiday ]
self.calendar.init_ui(True, info_off, info_holiday)
print("info_off", info_off, info_holiday)
# self.check()
def animate(self, max, steps, dt):
self.cp.opacity = 1
print(self.cp.value)
if(self.cp.value == 100 or self.cp.value > max):#= not handeled as first inital value is required to call draw() for correct positioning instead steps is handeled
self.cp.set_label(self.max_value)
return False
else:
self.cp.set_value(self.cp.value + steps)
if(self.cp.value==0):
return False
#------------------------ESSENTIAL_REQUIREMENT---------------------------------
class MyPopup(Popup):
# my_widget is now the object where popup was called from.
def __init__(self, my_widget, **kwargs):
super().__init__(**kwargs)
self.my_widget = my_widget # mywidget instance is used to accees child values
label = ObjectProperty(None)
pass
class MultiSelectSpinner(Button):
"""Widget allowing to select multiple text options."""
dropdown = ObjectProperty(None)
"""(internal) DropDown used with MultiSelectSpinner."""
values = ListProperty([])
"""Values to choose from."""
selected_values = ListProperty([])
"""List of values selected by the user."""
def __init__(self, **kwargs):
self.bind(dropdown=self.update_dropdown)
self.bind(values=self.update_dropdown)
super(MultiSelectSpinner, self).__init__(**kwargs)
self.bind(on_release=self.toggle_dropdown)
def toggle_dropdown(self, *args):
if self.dropdown.parent:
self.dropdown.dismiss()
else:
self.dropdown.open(self)
def update_dropdown(self, *args):
if not self.dropdown:
self.dropdown = DropDown()
values = self.values
if values:
if self.dropdown.children:
self.dropdown.clear_widgets()
for value in values:
b = Factory.MultiSelectOption(text=value)
b.bind(state=self.select_value)
self.dropdown.add_widget(b)
def select_value(self, instance, value):
if value == 'down':
if instance.text not in self.selected_values:
self.selected_values.append(instance.text)
else:
if instance.text in self.selected_values:
self.selected_values.remove(instance.text)
def on_selected_values(self, instance, value):
if value:
self.text = ', '.join(value)
else:
self.text = ''
class Infopopup(Popup):
# my_widget is now the object where popup was called from.
def __init__(self, my_widget, **kwargs):
super().__init__(**kwargs)
self.my_widget = my_widget # mywidget instance is used to accees child values
label = ObjectProperty(None)
layout = ObjectProperty(None)
class Imagebutton(ButtonBehavior, Image): # -------------oder yhi hpga call ka