-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrashCourseApp.py
713 lines (615 loc) · 31.3 KB
/
CrashCourseApp.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
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 8 20:41:40 2014
@author: ihill, mborges, mkeene, hpelletier, sgrimshaw
"""
import os
import kivy
from kivy.graphics import *
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader, StripLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.button import Button
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.checkbox import CheckBox
from kivy.uix.scrollview import ScrollView
from kivy.base import runTouchApp
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import ScreenManager, Screen, WipeTransition
from kivy.clock import Clock
from FileManager import FileManager
from NetworkManager import NetworkManager
from Course_Item import Course_Item
from Proto5_NoScroll import DragTab
from datastructures import User
from CreateCoursePopUp import Build_Course
from TabTextInput import TabTextInput
import all_globals
#new_user = User('hpelletier','crashcourse','Haley Pelletier',2017,'MechE',{'AHSE':0,'ENGR':0,'MTH':0,'SCI':0},[],'')
#all_globals.fm.save_user(new_user)
## Removes the multi-touch red dots ##
kivy.config.Config.set ('input', 'mouse', 'mouse,disable_multitouch')
search_temp_list = []
class StartUpScreen(Screen):
"""Screen that displays the logo for 3 seconds upon startup"""
def __init__(self,sm,**kwargs):
super(StartUpScreen, self).__init__(**kwargs)
self.sm = sm
self.orientation = 'vertical'
self.image = Image(source='logo1.png',allow_stretch=False,keep_ratio=True)
Clock.schedule_once(self.transition,3)
self.add_widget(self.image)
def transition(self,instance):
self.sm.current = 'login'
class LogInScreen(BoxLayout,Screen):
"""Screen for user log-in"""
def __init__(self,sm,**kwargs):
super(LogInScreen, self).__init__(**kwargs)
self.sm = sm
self.orientation = 'vertical'
## Username ##
self.username = GridLayout(cols=4,size_hint=(1.0,0.05))
self.username.add_widget(Label())
self.username.add_widget(Label(text='Username:'))
self.u_entry = TabTextInput(multiline=False)
self.username.add_widget(self.u_entry)
self.username.add_widget(Label())
## Password ##
self.password = GridLayout(cols=4,size_hint=(1.0,0.05))
self.password.add_widget(Label())
self.password.add_widget(Label(text='Password:'))
self.p_entry = TabTextInput(multiline=False,password=True)
self.password.add_widget(self.p_entry)
self.password.add_widget(Label())
## Allow for Tabbing ##
self.u_entry.set_next(self.p_entry)
self.p_entry.set_next(self.u_entry)
## New User / Log In Buttons ##
self.buttons = GridLayout(cols=4,size_hint=(1.0,0.05))
self.buttons.add_widget(Label())
self.buttons.add_widget(Button(text='New User?',on_press=self.new_user_function))
self.buttons.add_widget(Button(text='Log In',on_press=self.enter_function))
self.buttons.add_widget(Label())
## Offline ##
self.offline = BoxLayout(size_hint = (1.0,0.05))
self.offline_label = Label(text='Offline Mode',size_hint=(0.15,1.0))
self.offline_check = CheckBox(active=False,size_hint=(0.05,1.0))
self.offline.add_widget(Label(size_hint=(0.4,1.0)))
self.offline.add_widget(self.offline_label)
self.offline.add_widget(self.offline_check)
self.offline.add_widget(Label(size_hint=(0.4,1.0)))
## Logo and Empy Space ##
self.logo = Image(source='logo1.png',size_hint=(1.0,0.3))
self.space1 = Label(size_hint=(1.0,0.175))
self.space2 = Label(size_hint=(1.0,0.1))
self.space3 = Label(size_hint=(1.0,0.05))
self.space4 = Label(size_hint=(1.0,0.175))
## Add Widgets to Tab ##
self.add_widget(self.space1)
self.add_widget(self.logo)
self.add_widget(self.space2)
self.add_widget(self.username)
self.add_widget(self.password)
self.add_widget(self.space3)
self.add_widget(self.buttons)
self.add_widget(self.offline)
self.add_widget(self.space4)
def new_user_function(self,instance):
self.sm.current = 'newuser'
def enter_function(self,instance):
"""Determines if the user is able to log in and loads information for online or offline use"""
## Online Log-In: ##
if self.offline_check.active == False:
self.space4.text = 'Connecting...'
result = all_globals.nm.update(self.u_entry.text,self.p_entry.text)
if result == 0:
self.space4.text = 'No internet connection.'
return
elif result == -1:
self.space4.text = 'User does not exist on server. Please create new user'
return
elif result == -3:
self.space4.text = 'Connecting to server. Incorrect password.'
return
elif result == -4:
self.space4.text = 'Lost internet connection while downloading new content.'
return
elif result == -5:
self.space4.text = 'Lost internet connection while syncing user information.'
return
elif result == True:
all_globals.user = all_globals.fm.load_user(self.u_entry.text,self.p_entry.text)
if all_globals.user != None:
all_globals.catalog = all_globals.fm.load_courses()
self.space4.text = 'All systems go!'
self.sm.current = 'tabs'
else:
self.space4.text = 'Login failed. Incorrect username or password.'
## Offline Log-In: ##
else:
student = all_globals.fm.load_user(self.u_entry.text,self.p_entry.text)
#print all_globals.user.name
#print all_globals.user.credits['AHSE']
all_globals.catalog = all_globals.fm.load_courses()
if all_globals.catalog == None:
self.space4.text = 'Login failed. No courses.csv file.'
elif student == None:
self.space4.text = 'Login failed. Incorrect username or password for local user.'
else:
all_globals.user = student
self.space4.text = 'Starting in Offline Mode.'
self.sm.current = 'tabs'
class NewUserScreen(BoxLayout,Screen):
"""Screen for new user creation"""
def __init__(self,sm,**kwargs):
super(NewUserScreen, self).__init__(**kwargs)
self.sm = sm
self.orientation = 'vertical'
## Username ##
self.username = GridLayout(cols=4,size_hint=(1.0,0.05))
self.username.add_widget(Label())
self.username.add_widget(Label(text='Please enter a username:'))
self.u_entry = TabTextInput(multiline=False)
self.username.add_widget(self.u_entry)
self.username.add_widget(Label())
## Password ##
self.password = GridLayout(cols=4,size_hint=(1.0,0.05))
self.password.add_widget(Label())
self.password.add_widget(Label(text='Please enter a password:'))
self.p_entry = TabTextInput(multiline=False,password=True)
self.password.add_widget(self.p_entry)
self.password.add_widget(Label())
## Full Name ##
self.fullname = GridLayout(cols=4,size_hint=(1.0,0.05))
self.fullname.add_widget(Label())
self.fullname.add_widget(Label(text='Please enter your full name:'))
self.fullname_entry = TabTextInput(multiline=False)
self.fullname.add_widget(self.fullname_entry)
self.fullname.add_widget(Label())
## Allow for Tabbing ##
self.u_entry.set_next(self.p_entry)
self.p_entry.set_next(self.fullname_entry)
self.fullname_entry.set_next(self.u_entry)
## Back / Create Account Buttons ##
self.buttons = GridLayout(cols=4,size_hint=(1.0,0.05))
self.buttons.add_widget(Label())
self.buttons.add_widget(Button(text = 'Back',on_press = self.back_function))
self.buttons.add_widget(Button(text = 'Create Account',on_press = self.enter_function))
self.buttons.add_widget(Label())
## Logo, Warning, and Empty Space ##
self.logo = Image(source='logo1.png',size_hint=(1.0,0.3))
self.space1 = Label(size_hint=(1.0,0.175))
self.space2 = Label(size_hint=(1.0,0.1))
self.space3 = Label(size_hint=(1.0,0.05))
self.warning = Label(text='*WARNING* Once you choose a username and password, they CAN NOT be changed!',size_hint=(1.0,0.175))
## Add Widgets to Tab ##
self.add_widget(self.space1)
self.add_widget(self.logo)
self.add_widget(self.space2)
self.add_widget(self.username)
self.add_widget(self.password)
self.add_widget(self.fullname)
self.add_widget(self.space3)
self.add_widget(self.buttons)
self.add_widget(self.warning)
def back_function(self,instance):
self.sm.current = 'login'
def enter_function(self,instance):
#TODO: create new user file with self.u_entry.text and self.p_entry.text and self.fullname_entry.text
all_globals.user = User(self.u_entry.text,self.p_entry.text,self.fullname_entry.text,2017,'ECE',{'AHSE':0,'ENGR':0,'MTH':0,'SCI':0},None,'')
try:
all_globals.fm.save_user(all_globals.user)
all_globals.nm.create_user(all_globals.user.username)
self.sm.current = 'tabs'
except:
self.warning.text = "User creation failed. Check your internet connection."
else:
self.warning.text = "User creation successful. Downloading the lastest course information."
result = all_globals.nm.update(self.u_entry.text,self.p_entry.text)
if result == True:
all_globals.user = all_globals.fm.load_user(self.u_entry.text,self.p_entry.text)
if all_globals.user != None:
all_globals.catalog = all_globals.fm.load_courses()
self.warning.text = 'Download successful!'
self.sm.current = 'tabs'
else:
self.warning.text = 'Download failed. Check your internet connection.'
class Dashboard(BoxLayout):
"""Home tab that displays user statistics"""
def __init__(self,sm,**kwargs):
super(Dashboard, self).__init__(**kwargs)
self.sm = sm
self.ahse_cred = 0
self.engr_cred = 0
self.mth_cred = 0
self.sci_cred = 0
will_grad = 'No'
## USER INFORMATION HALF ##
self.info = GridLayout(rows=5,size_hint=(0.5,1.0))
# User's Name #
self.display_name = Label(size_hint=(1.0,0.05))
# Grad Year #
self.years = BoxLayout(size_hint=(1.0,0.1))
year1 = BoxLayout(size_hint=(0.2,1.0))
self.year1_check=CheckBox(active=False,group='year',size_hint=(0.1,1.0))
self.year1_label = Label(text=str(2014),size_hint=(0.9,1.0))
year1.add_widget(self.year1_label)
year1.add_widget(self.year1_check)
year2 = BoxLayout(size_hint=(0.2,1.0))
self.year2_check=CheckBox(active=False,group='year',size_hint=(0.1,1.0))
self.year2_label = Label(text=str(2015),size_hint=(0.9,1.0))
year2.add_widget(self.year2_label)
year2.add_widget(self.year2_check)
year3 = BoxLayout(size_hint=(0.2,1.0))
self.year3_check=CheckBox(active=False,group='year',size_hint=(0.1,1.0))
self.year3_label = Label(text=str(2016),size_hint=(0.9,1.0))
year3.add_widget(self.year3_label)
year3.add_widget(self.year3_check)
year4 = BoxLayout(size_hint=(0.2,1.0))
self.year4_check=CheckBox(active=False,group='year',size_hint=(0.1,1.0))
self.year4_label = Label(text=str(2017),size_hint=(0.9,1.0))
year4.add_widget(self.year4_label)
year4.add_widget(self.year4_check)
self.years.add_widget(Label(size_hint=(0.1,1.0)))
radio_buttons1=[year1,year2,year3,year4]
for button in radio_buttons1:
self.years.add_widget(button)
self.years.add_widget(Label(size_hint=(0.1,1.0)))
# Major #
self.majors = GridLayout(cols=1,size_hint=(1.0,0.7))
ece = BoxLayout()
self.ece_check = CheckBox(active=False,group='majors')
self.ece_label = Label(text='ECE')
ece.add_widget(Label())
ece.add_widget(self.ece_label)
ece.add_widget(self.ece_check)
ece.add_widget(Label())
meche = BoxLayout()
self.meche_check = CheckBox(active=False,group='majors')
self.meche_label = Label(text='MechE')
meche.add_widget(Label())
meche.add_widget(self.meche_label)
meche.add_widget(self.meche_check)
meche.add_widget(Label())
roboe = BoxLayout()
self.roboe_check = CheckBox(active=False,group='majors')
self.roboe_label = Label(text='E:Robo')
roboe.add_widget(Label())
roboe.add_widget(self.roboe_label)
roboe.add_widget(self.roboe_check)
roboe.add_widget(Label())
bioe = BoxLayout()
self.bioe_check = CheckBox(active=False,group='majors')
self.bioe_label = Label(text='E:Bio')
bioe.add_widget(Label())
bioe.add_widget(self.bioe_label)
bioe.add_widget(self.bioe_check)
bioe.add_widget(Label())
designe = BoxLayout()
self.designe_check = CheckBox(active=False,group='majors')
self.designe_label = Label(text='E:Design')
designe.add_widget(Label())
designe.add_widget(self.designe_label)
designe.add_widget(self.designe_check)
designe.add_widget(Label())
ec = BoxLayout()
self.ec_check = CheckBox(active=False,group='majors')
self.ec_label = Label(text='E:C')
ec.add_widget(Label())
ec.add_widget(self.ec_label)
ec.add_widget(self.ec_check)
ec.add_widget(Label())
syse= BoxLayout()
self.syse_check = CheckBox(active=False,group='majors')
self.syse_label = Label(text='E:Sys')
syse.add_widget(Label())
syse.add_widget(self.syse_label)
syse.add_widget(self.syse_check)
syse.add_widget(Label())
matscie = BoxLayout()
self.matscie_check = CheckBox(active=False,group='majors')
self.matscie_label = Label(text='E:MatSci')
matscie.add_widget(Label())
matscie.add_widget(self.matscie_label)
matscie.add_widget(self.matscie_check)
matscie.add_widget(Label())
other = BoxLayout()
self.other_check = CheckBox(active=False,group='majors')
self.other_label = Label(text='Other')
other.add_widget(Label())
other.add_widget(self.other_label)
other.add_widget(self.other_check)
other.add_widget(Label())
options=[ece, meche, roboe, bioe, designe, ec, syse, matscie, other]
for choice in options:
self.majors.add_widget(choice)
# Export and Save Buttons #
self.options_bar = BoxLayout(size_hint=(1.0,0.05))
self.export_button = Button(text='Export to Spreadsheet',on_press=self.export_user_info)
self.save_button = Button(text='Save User Information',on_press=self.save_user_info)
self.options_bar.add_widget(self.export_button)
self.options_bar.add_widget(self.save_button)
# Add Widgets to User Information Half #
self.info.add_widget(Label(text='Your Information',font_size = 17,size_hint=(1.0,0.1)))
self.info.add_widget(self.display_name)
self.info.add_widget(self.years)
self.info.add_widget(self.majors)
self.info.add_widget(self.options_bar)
## STATS AND NOTES HALF ##
self.stats_and_notes = BoxLayout(orientation='vertical',size_hint=(0.5,1.0))
# STATS QUADRANT #
self.stats = BoxLayout(orientation='vertical',size_hint=(1.0,0.5))
# Stats #
self.information = GridLayout(rows = 3, size_hint = (1.0,0.8))
self.grad = Label(text='Enough credits to graduate?: ' + will_grad,size_hint=(1.0,0.4))
self.credits = GridLayout(cols=4,rows=2,size_hint=(1.0,0.6))
self.credits.add_widget (Label())
self.credits.add_widget(Label(text = 'AHSE: '+str(self.ahse_cred)))
self.credits.add_widget(Label(text = 'ENGR: '+str(self.engr_cred)))
self.credits.add_widget (Label())
self.credits.add_widget (Label())
self.credits.add_widget(Label(text = 'MTH: '+str(self.mth_cred)))
self.credits.add_widget(Label(text = 'SCI: '+str(self.sci_cred)))
self.credits.add_widget (Label())
self.information.add_widget(self.credits)
self.information.add_widget(self.grad)
# Add Widgets to Quadrant #
self.stats.add_widget(Label(text = 'Credits',font_size = 17,size_hint =(1.0,0.2)))
self.stats.add_widget(self.information)
# NOTES QUADRANT #
self.notes = GridLayout(cols=1,size_hint =(1.0,0.5))
self.n_label = Label(text='Notes',font_size = 17,size_hint = (1.0,0.15))
self.n_entry = TextInput(multiline=True,padding=15,size_hint=(1.0,0.85))
self.notes.add_widget(self.n_label)
self.notes.add_widget(self.n_entry)
# Add Stats and Notes to Half #
self.stats_and_notes.add_widget(self.stats)
self.stats_and_notes.add_widget(self.notes)
## Add Halves to Home Tab ##
self.add_widget(self.info)
self.add_widget(self.stats_and_notes)
Clock.schedule_interval(self.update_stats,0.1)
def update_stats(self,instance):
"""Updates the information displayed on the Home tab and saves info to the user file"""
if self.sm.tabs.tabspanel.current_tab == self.sm.tabs.tabspanel.tab1:
ahse_cred = all_globals.user.credits['AHSE']
engr_cred = all_globals.user.credits['ENGR']
mth_cred = all_globals.user.credits['MTH']
sci_cred = all_globals.user.credits['SCI']
ahse_req = 28
engr_req = 28
mth_req = 28
sci_req = 28
## Add major to user file ##
if self.ece_check.active == True:
all_globals.user.major = self.ece_label.text
if self.meche_check.active == True:
all_globals.user.major = self.meche_label.text
if self.roboe_check.active == True:
all_globals.user.major = self.roboe_label.text
if self.bioe_check.active == True:
all_globals.user.major = self.bioe_label.text
if self.designe_check.active == True:
all_globals.user.major = self.designe_label.text
if self.ec_check.active == True:
all_globals.user.major = self.ec_label.text
if self.syse_check.active == True:
all_globals.user.major = self.syse_label.text
if self.matscie_check.active == True:
all_globals.user.major = self.matscie_label.text
if self.other_check.active == True:
all_globals.user.major = self.other_label.text
## Determine if user has enough credits to graduate ##
if ahse_cred+engr_cred+mth_cred+sci_cred >= 128:
will_grad = 'Yes'
else:
will_grad = 'No'
## Update the displayed credits & name ##
self.grad.clear_widgets()
self.grad = Label(text='Enough credits to graduate?: ' + will_grad)
self.credits.clear_widgets()
self.credits.add_widget (Label())
self.credits.add_widget (Label(text = 'AHSE: '+str(ahse_cred)+' / '+str(ahse_req)))
self.credits.add_widget (Label(text = 'ENGR: '+str(engr_cred)+' / '+str(engr_req)))
self.credits.add_widget (Label())
self.credits.add_widget (Label())
self.credits.add_widget (Label(text = 'MTH: '+str(mth_cred)+' / '+str(mth_req)))
self.credits.add_widget (Label(text = 'SCI: '+str(sci_cred)+' / '+str(sci_req)))
self.credits.add_widget (Label())
self.display_name.text = all_globals.user.name
## Add grad year to user file ##
if self.year1_check.active == True:
all_globals.user.grad_year = int(self.year1_label.text)
elif self.year2_check.active == True:
all_globals.user.grad_year = int(self.year2_label.text)
elif self.year3_check.active == True:
all_globals.user.grad_year = int(self.year3_label.text)
elif self.year4_check.active == True:
all_globals.user.grad_year = int(self.year4_label.text)
## Add notes to user file ##
all_globals.user.notes=self.n_entry.text
def save_user_info(self,instance):
#print 'User info saved!'
all_globals.fm.save_user(all_globals.user)
def export_user_info(self,instance):
#print 'User info exported!'
all_globals.fm.export_user(all_globals.user)
class Catalog(BoxLayout):
"""Tab that displays available courses and allows user to search for, see details about, and add courses to planner tab"""
def __init__(self,sm,**kwargs):
super(Catalog,self).__init__(**kwargs)
self.orientation = 'vertical'
self.sm = sm
## Search Bar ##
self.search_bar = BoxLayout(size_hint=(1.0,0.05))
self.search_text = TextInput(multiline=False,size_hint =(0.6,1.0))
self.create_course_popup = Build_Course(self.sm)
self.create_course_button = Button(text='Create a Course',size_hint=(0.2,1.0),on_press=self.create_course_popup.open_pop_up)
self.search_bar.add_widget(Label(text='Search',size_hint=(0.2,1.0)))
self.search_bar.add_widget(self.search_text)
self.search_bar.add_widget(self.create_course_button)
## Filter Buttons ##
self.filter_bar = BoxLayout(size_hint=(1.0,0.05))
self.AHSE = ToggleButton(text='AHSE',size_hint=(0.25,1.0))
self.ENGR = ToggleButton(text='ENGR',size_hint=(0.25,1.0))
self.MTH = ToggleButton(text='MTH',size_hint=(0.25,1.0))
self.SCI = ToggleButton(text='SCI',size_hint=(0.25,1.0))
self.filter_bar.add_widget(self.AHSE)
self.filter_bar.add_widget(self.ENGR)
self.filter_bar.add_widget(self.MTH)
self.filter_bar.add_widget(self.SCI)
## Scrollview of Courses ##
self.scrollview = ScrollView(size_hint=(1.0,0.9),size=(400,400),scroll_timeout=5)
self.courses = StackLayout(spacing=5,size_hint_y=None)
self.courses.bind(minimum_height=self.courses.setter('height'))
self.scrollview.add_widget(self.courses)
## Add Widgets to Tab ##
self.add_widget(self.search_bar)
self.add_widget(self.filter_bar)
self.add_widget(self.scrollview)
Clock.schedule_interval(self.search_function,0.1)
def search_function(self,instance):
"""Allows user to search for courses by name, keyword, professor, or course code and filter courses by type"""
query = self.search_text.text.lower()
searched_items = []
filtered_items = []
#fills up the temp list the first time the function is called (copy of list of all courses)
if len(search_temp_list) == 0:
for course_item in self.courses.children:
search_temp_list.append(course_item)
#if the query is not empty, does term search first
if query != "":
for course_item in search_temp_list:
if query == course_item.course.name.lower() or query == course_item.course.code or query == course_item.course.prof.lower():
searched_items.append(course_item)
for keyword in course_item.course.keywords:
if query == keyword.lower():
searched_items.append(course_item)
#if the query is empty, searched courses = all courses
else:
searched_items = search_temp_list
#if none of the buttons are down, keep all searched courses
if self.AHSE.state == 'normal' and self.ENGR.state == 'normal' and self.MTH.state == 'normal' and self.SCI.state == 'normal':
filtered_items = searched_items
#if a button is down, shows only courses in that category (holding multiple buttons shows more courses)
else:
if self.AHSE.state == 'down':
for course_item in searched_items:
if course_item.course.credits['AHSE'] > 0:
filtered_items.append(course_item)
if self.ENGR.state == 'down':
for course_item in searched_items:
if course_item.course.credits['ENGR'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if self.MTH.state == 'down':
for course_item in searched_items:
if course_item.course.credits['MTH'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if self.SCI.state == 'down':
for course_item in searched_items:
if course_item.course.credits['SCI'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if len(self.courses.children) != len(filtered_items):
self.courses.clear_widgets()
for course_item in filtered_items:
self.courses.add_widget(course_item)
class Planner(DragTab):
"""Tab that allows user to arrange courses in semesters and plan their four years at Olin"""
def __init__(self,**kwargs):
super(Planner, self).__init__(**kwargs)
class TabsPanel(TabbedPanel):
"""Panel that holds the tab widgets"""
def __init__(self,sm,**kwargs):
super(TabsPanel, self).__init__(**kwargs)
self.sm = sm
self.last_tab = None
self.strip_image = 'strip_logo2.png' #Logo in the top right of the tabs
## Define the Tabs ##
self.tab1 = TabbedPanelHeader(text='Home')
self.tab1.content = Dashboard(self.sm)
self.tab2 = TabbedPanelHeader(text='Catalog')
self.tab2.content = Catalog(self.sm)
self.tab3 = TabbedPanelHeader(text='Planner')
self.tab3.content = Planner()
## Add the Tabs to the Panel ##
self.add_widget(self.tab1)
self.add_widget(self.tab2)
self.add_widget(self.tab3)
Clock.schedule_interval(self.load,0.5)
def load(self,instance):
"""Fills the App with Information from the user file and loads the courses"""
## Loads the Courses into Catalog Tab ##
if self.current_tab != self.last_tab and self.current_tab == self.tab2:
self.tab2.content.courses.clear_widgets()
for course_object in all_globals.catalog:
course_item = Course_Item(course=course_object,size_hint=(0.245,None),height=200)
self.tab2.content.courses.add_widget(course_item)
# Loads User Information into the Home Tab ##
if self.current_tab == self.tab1:
# Loads Notes #
self.tab1.content.n_entry.text = all_globals.user.notes
# Loads Credits #
self.tab1.content.ahse_cred = all_globals.user.credits['AHSE']
self.tab1.content.engr_cred = all_globals.user.credits['ENGR']
self.tab1.content.mth_cred = all_globals.user.credits['MTH']
self.tab1.content.sci_cred = all_globals.user.credits['SCI']
# Loads Grad Year #
if str(all_globals.user.grad_year) == '2014':
self.tab1.content.year1_check.active = True
if str(all_globals.user.grad_year) == '2015':
self.tab1.content.year2_check.active = True
if str(all_globals.user.grad_year) == '2016':
self.tab1.content.year3_check.active = True
if str(all_globals.user.grad_year) == '2017':
self.tab1.content.year4_check.active = True
# Loads Major #
if str(all_globals.user.major) == 'ECE':
self.tab1.content.ece_check.active = True
if str(all_globals.user.major) == 'MechE':
self.tab1.content.meche_check.active = True
if str(all_globals.user.major) == 'E:Robo':
self.tab1.content.roboe_check.active = True
if str(all_globals.user.major) == 'E:Design':
self.tab1.content.designe_check.active = True
if str(all_globals.user.major) == 'E:C':
self.tab1.content.ec_check.active = True
if str(all_globals.user.major) == 'E:Sys':
self.tab1.content.syse_check.active = True
if str(all_globals.user.major) == 'E:Bio':
self.tab1.content.bioe_check.active = True
if str(all_globals.user.major) == 'E:Matsci':
self.tab1.content.matscie_check.active = True
if str(all_globals.user.major) == 'Other':
self.tab1.content.other_check.active = True
##Loads User info on Planner Tab
self.tab3.content.Load_Users_Plan()
self.last_tab = self.current_tab
class TabsScreen(Screen):
"""Screen that holds the Tabs Panel"""
def __init__(self,sm,**kwargs):
super(TabsScreen, self).__init__(**kwargs)
self.sm = sm
self.tabspanel = TabsPanel(sm,do_default_tab=False)
self.add_widget(self.tabspanel)
class CrashCourseApp(App):
"""The entire CrashCourse app"""
def build(self):
"""Builds the app when the app is run"""
## Define the screen manager (base of the app) ##
sm = ScreenManager(transition = WipeTransition())
## Add screens to the screen manager ##
sm.startup=StartUpScreen(sm,name='startup')
sm.add_widget(sm.startup)
sm.login=LogInScreen(sm,name='login')
sm.add_widget(sm.login)
sm.newuser=NewUserScreen(sm,name='newuser')
sm.add_widget(sm.newuser)
sm.tabs=TabsScreen(sm,name='tabs')
sm.add_widget(sm.tabs)
return sm
if __name__ == '__main__':
CrashCourseApp().run()