-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainApp.py
345 lines (308 loc) · 13.8 KB
/
MainApp.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
import os
import sys
import time
from operator import itemgetter
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivymd.app import MDApp
from kivymd.uix.button import MDRaisedButton, MDFlatButton, MDFillRoundFlatIconButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel
from kivymd.uix.picker import MDTimePicker
from kivymd.uix.list import IRightBodyTouch
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.card import MDCardSwipe
import mysqllog
from Logic import mintohhmmss
if getattr(sys, "frozen", False):
os.environ["Scheduler-master"] = sys._MEIPASS
else:
sys.path.append(os.path.abspath(__file__).split("demos")[0])
os.environ["Scheduler-master"] = os.path.dirname(os.path.abspath(__file__))
def i2t(instance):
return instance.text2
email='Test@gmail.com'
KV = '''
<SwipeToDeleteItem>:
anchor:'right'
type_swipe: 'auto'
size_hint_y: None
height: content.height
on_swipe_complete:app.remove_item(root)
MDCardSwipeFrontBox:
TwoLineListItem:
id: content
text: root.text
secondary_text: root.text2
_no_ripple_effect: True
Screen:
NavigationLayout:
#x: toolbar.height
ScreenManager:
id: screen_manager
Screen:
name: "todo"
BoxLayout:
orientation: "vertical"
spacing: "10dp"
MDToolbar:
id: toolbar
pos_hint: {"top": 1}
elevation: 10
title: "Scheduler"
left_action_items: []
right_action_items:[["plus", lambda x: app.add()],["briefcase-plus", lambda x: app.addM()],["refresh", lambda x: app.refresh_callback()],["trash-can", lambda x:app.delete()]]
ScrollView:
MDList:
id:md_list
padding: "2dp"
Screen:
name: "edit"
MDLabel:
text: "edit here"
halign: "center"
MDFloatingActionButtonSpeedDial:
data: app.data
# on_release:
# app.event_handler()
rotation_root_button: False
'''
class custom_events(BoxLayout):
pass
class custom_events2(BoxLayout):
pass
class custom_events3(BoxLayout):
pass
class Container(IRightBodyTouch, MDBoxLayout):
adaptive_width = True
class SwipeToDeleteItem(MDCardSwipe):
text = StringProperty()
text2 = StringProperty()
class TestNavigationDrawer(MDApp):
main_text=''
temp_instance=None
main_event_list=[]
main_meeting_list=[]
main=[]
my_event=None
mytime=None
starttime=None
endtime=None
data = {'delete':'Delete','pencil':'Add'}
# def callback(self, instance, *args):
# self.cstm_evnt = MDDialog(title='Custom Event',type='custom',content_cls=custom_events())
# pass
def build(self):
self.theme_cls.theme_style = 'Dark'
Builder.load_file(f"{os.environ['Scheduler-master']}/KivyFiles/Main App/content.kv")
Builder.load_file(f"{os.environ['Scheduler-master']}/KivyFiles/Main App/content2.kv")
#Builder.load_file(f"{os.environ['Scheduler-master']}/KivyFiles/Main App/content3.kv")
return Builder.load_string(KV)
#self.refresh_callback()
def on_start(self):
self.load_schedule()
def load_schedule(self):
for i in mysqllog.return_schedule(email):
starttime=mintohhmmss(i[0])
endtime=mintohhmmss(i[1])
evnt=i[2]
self.main.append((evnt,starttime,endtime))
instance=SwipeToDeleteItem(text=evnt,text2=starttime+' - '+endtime)
self.root.ids.md_list.add_widget(instance)
cstm_evnt = None
cstm_evnt2=None
confirmd2=None
confirmdf=None
deleteb=None
dlt_event= None
def add(self):
#self.time_dialog=MDTimePicker()
if not self.cstm_evnt:
self.cstm_evnt = MDDialog(
title='[color=#FFFFFF]Add Event[/color]',
type='custom',
content_cls=custom_events(),
size_hint=(0.4, 0.3),
buttons=[MDFlatButton(text='CANCEL',
on_release=self.cstm_evnt_close,
text_color=self.theme_cls.primary_color),
MDFillRoundFlatIconButton(text='Set Time',
icon='clock',
on_release=self.time_picker
)
])
self.cstm_evnt.open()
def addM(self):
#self.time_dialog=MDTimePicker()
if not self.cstm_evnt2:
self.cstm_evnt2 = MDDialog(
title='[color=#FFFFFF]Add Meeting[/color]',
type='custom',
content_cls=custom_events2(),
size_hint=(0.4, 0.3),
buttons=[MDFlatButton(text='CANCEL',
on_release=self.cstm_evnt_close2,
text_color=self.theme_cls.primary_color),
MDFillRoundFlatIconButton(text='Starting Time',
icon='clock',
on_release=self.time_picker2
)
])
self.cstm_evnt2.open()
def delete(self):
self.cstm_evnt2=None
#self.time_dialog=MDTimePicker()
if not self.cstm_evnt2:
self.cstm_evnt2 = MDDialog(
title='[color=#FFFFFF]Delete[/color]',
type='custom',
content_cls=custom_events2(),
size_hint=(0.4, 0.3),
buttons=[MDFlatButton(text='CANCEL',
on_release=self.cstm_evnt_close2,
text_color=self.theme_cls.primary_color),
MDRaisedButton(text='Delete',
on_release=self.deleteevent
)
])
self.cstm_evnt2.open()
def deleteevent(self,*args):
for i in self.ids.md_list:
if str(i.text)==self.my_event:
self.root.ids.md_list.remove_widget(i)
try:
mysqllog.remove_routine(email,self.my_event)
except:
mysqllog.remove_user_data(email,self.my_event)
def time_picker(self, *args):
self.time_dialog=MDTimePicker()
#self.time_dialog.title=self.my_event
self.time_dialog.bind(time=self.show)
self.time_dialog.open()
self.cstm_evnt.dismiss()
self.cstm_event=None
#confirmd=None
def time_picker2(self, *args):
self.time_dialog=MDTimePicker()
#self.time_dialog.title=self.my_event
self.time_dialog.bind(time=self.show2)
self.time_dialog.open()
self.cstm_evnt2.dismiss()
self.cstm_event2=None
def time_picker3(self, *args):
self.time_dialog=MDTimePicker()
#self.time_dialog.title=self.my_event
self.time_dialog.bind(time=self.show3)
self.time_dialog.open()
self.confirmd2.dismiss()
def show2(self,instance,time):
self.starttime=time
print(self.starttime)
self.confirmd2=None
self.confirm2()
def show3(self,instance,time):
self.endtime=time
print(self.endtime)
self.confirmdf=None
self.confirmfinal()
def delete_callback(self):
pass
def confirm2(self):
if not self.confirmd2:
self.confirmd2=MDDialog(title='[color=#FFFFFF]Confirm[/color]',size_hint=(0.4, 0.3),text="{},{}".format(self.my_event,self.starttime),buttons=[MDFlatButton(text='Cancel',
on_release=self.clconfirmd2,
text_color=self.theme_cls.primary_color),
MDFillRoundFlatIconButton(text='Ending Time',
icon='clock',
on_release=self.time_picker3
)
])
self.confirmd2.open()
def confirmfinal(self):
if not self.confirmdf:
self.confirmdf=MDDialog(title='[color=#FFFFFF]Confirm[/color]',size_hint=(0.4, 0.3),text="Add Meeting {} at {} to {}?".format(self.my_event,self.starttime,self.endtime),buttons=[MDFlatButton(text='NO',
on_release=self.clconfirmdf,
text_color=self.theme_cls.primary_color),
MDRaisedButton(text='YES',
on_release=self.event_adder2
)
])
self.confirmdf.open()
def confirm(self):
if not self.confirmd:
self.confirmd=MDDialog(title='[color=#FFFFFF]Confirm[/color]',size_hint=(0.4, 0.3),text="Add Event {} at {} ?".format(self.my_event,self.mytime),buttons=[MDFlatButton(text='NO',
on_release=self.clconfirmd,
text_color=self.theme_cls.primary_color),
MDRaisedButton(text='YES',
on_release=self.event_adder
)
])
self.confirmd.open()
def deletecl(self,*args):
self.deleteb.dismiss()
def clconfirmd(self,*args):
self.confirmd.dismiss()
def clconfirmd2(self,*args):
self.confirmd2.dismiss()
def clconfirmdf(self,*args):
self.confirmdf.dismiss()
def refresh_callback(self, *args):
mysqllog.add_routine('Test@gmail.com',self.main_meeting_list)
mysqllog.add_user_data('Test@gmail.com',self.main_event_list)
self.main=sorted(self.main,key=itemgetter(1))
self.root.ids.md_list.clear_widgets()
for i in self.main:
if len(i)==2:
self.root.ids.md_list.add_widget(SwipeToDeleteItem(text=i[0],text2=i[1]))
else:
self.root.ids.md_list.add_widget(SwipeToDeleteItem(text=i[0],text2=i[1]+' - '+i[2]))
#self.root.ids.md_list.add_widget(i)
def textfrominstance(self,instance):
return instance.text
def show(self,instance,time):
self.mytime=time
self.confirmd=None
self.confirm()
#fixedtimedict[key]=time
def cstm_evnt_close(self,*args):
self.cstm_evnt.dismiss()
def cstm_evnt_close2(self,*args):
self.cstm_evnt2.dismiss()
def remove_item(self,instance):
print(instance.text)
self.temp_instance=instance
if not self.dlt_event:
self.dlt_event=MDDialog(title='[color=#FFFFFF]Confirm Delete[/color]',size_hint=(0.4, 0.3),text="Delete {}?".format(instance.text),buttons=[MDFlatButton(text='NO',on_release=self.cldelevent,text_color=self.theme_cls.primary_color),MDRaisedButton(text='YES',on_press=self.rem)])
self.dlt_event.open()
def rem(self,instance):
print(self.main_event_list)
self.dlt_event.dismiss()
self.root.ids.md_list.remove_widget(self.temp_instance)
for i in range(len(self.main_event_list)):
if self.main_event_list[i][0]==self.temp_instance.text:
del(self.main_event_list[i])
print(self.main_event_list)
break
self.dlt_event=None
def cldelevent(self,instance):
self.dlt_event.dismiss()
def event_adder(self,instance):
self.confirmd.dismiss()
instance=SwipeToDeleteItem(text=self.my_event,text2=str(self.mytime))
self.main_event_list.append((instance.text,instance.text2))
self.main.append((str(self.my_event),str(self.mytime)))
self.root.ids.md_list.add_widget(instance)
mysqllog.add_user_data(email,[(self.my_event,self.mytime)])
def event_adder2(self,instance):
self.confirmdf.dismiss()
instance=SwipeToDeleteItem(text=self.my_event,text2=str(self.starttime)+' - '+str(self.endtime))
self.main_meeting_list.append((str(self.my_event),str(self.starttime),str(self.endtime)))
self.main.append((str(self.my_event),str(self.starttime),str(self.endtime)))
self.root.ids.md_list.add_widget(instance)
mysqllog.add_routine(email,[(self.my_event,self.starttime,self.endtime)])
if __name__ == "__main__":
TestNavigationDrawer().run()