-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathui_controller.py
2337 lines (2129 loc) · 93.7 KB
/
ui_controller.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
#Copyright (C) 2017 Nihal Rao I, Sanjan S Poojari, Shishir Upadhya
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QStackedLayout
from PyQt5.QtWidgets import QWidget, QApplication, QDesktopWidget, QDialog, QMessageBox
from PyQt5.Qt import QSystemTrayIcon, QIcon
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import pickle
import tt
import os
from collections import OrderedDict
import json
import time
import traceback
import worddoc
import xlrd
import logging
from window import Ui_window
from window2 import Ui_window2
from window3 import Ui_window3
from window4 import Ui_window4
from window5 import Ui_window5
from elective_window import Ui_elective_window
from year_window import Ui_year_window
from about_window import Ui_aboutWindow
from license_window import Ui_licenseWindow
class subject:
def __init__(self, name, short_name = '', credits = 0, lab = False, subcode = ''):
if short_name == '': # if both names are provided together in name
both_names = name
self.name, self.short_name = both_names.split(' - ')
else: # short name is provided separately
self.name = name
self.short_name = short_name
self.credits = credits
self.lab = lab
self.subcode = subcode
@property
def both_names(self):
both_names = self.name + ' - ' + self.short_name
return both_names
def __eq__(self, obj):
return self.name == obj.name and self.short_name == obj.short_name
def __repr__(self):
return 'subject({}, {}, {}, {}, {})'.format(self.name.__repr__(), self.short_name.__repr__(), self.credits, self.lab, self.subcode.__repr__())
def __hash__(self):
return self.name.__hash__()
titles_list = ['Mr.', 'Ms.', 'Mrs.', 'Dr.', 'Prof.' ]
class faculty_class:
def __init__(self, name, title = '', designation = ''):
if title == '':
for t in titles_list:
if name.startswith(t):
name = name[len(t):].strip()
title = t
break
self.name = name
self.title = title
self.designation = designation
def __repr__(self):
return 'faculty_class({}, {}, {})'.format(self.name.__repr__(), self.title.__repr__(), self.designation.__repr__())
def __str__(self):
return self.title + ' ' + self.name
def __eq__(self, string):
if str(string) == str(self) or string == self.name:
return True
else:
return False
def __lt__(self, obj):
return self.name < obj.name
def __hash__(self):
return self.name.__hash__()
#new singular class implementing QStackedLayout
class ParentWindow(QMainWindow):
def __init__(self, parent = None):
super(ParentWindow,self).__init__(parent)
self.layered_windows = QStackedLayout()
logger.info('********************************************************************************************************************')
logger.info('* TIMETABLE GENERATOR *')
logger.info('* *')
logger.info('* BY: *')
logger.info('* Nihal Rao I *')
logger.info('* Sanjan S Poojari *')
logger.info('* Shishir Upadhya *')
logger.info('* Department of Computer Science & Engineering *')
logger.info('* *')
logger.info('* FOR: *')
logger.info('* NMAM Institute of Technology, Nitte *')
logger.info('********************************************************************************************************************')
logger.info('Current Directory: %s', os.path.realpath(os.curdir))
#code to resize the main window ...does NOT resize the widgets !
self.screen_width = QDesktopWidget().screenGeometry().width()
self.screen_height = QDesktopWidget().screenGeometry().height()
logger.info('Current screen resolution: %s %s', self.screen_width, self.screen_height)
self.resize_ratio = 0.7 #70% resizing
logger.info('Resize ratio: %s', self.resize_ratio)
self.setup_year_window()
self.setup_first_window()
self.setup_second_window()
self.setup_third_window()
self.setup_fourth_window()
self.setup_fifth_window()
self.layered_windows.addWidget(self.YearWindow)
self.layered_windows.addWidget(self.FirstWindow)
self.layered_windows.addWidget(self.SecondWindow)
self.layered_windows.addWidget(self.ThirdWindow)
self.layered_windows.addWidget(self.FourthWindow)
self.layered_windows.addWidget(self.FifthWindow)
self.systemtray_icon = QSystemTrayIcon(QIcon('icons/favicon.ico'))
self.systemtray_icon.show()
app.aboutToQuit.connect(lambda: self.systemtray_icon.hide())
self.YearWindow.closeEvent = self.finish_btn_event
self.FirstWindow.closeEvent = self.finish_btn_event
self.SecondWindow.closeEvent = self.finish_btn_event
self.ThirdWindow.closeEvent = self.finish_btn_event
self.FourthWindow.closeEvent = self.finish_btn_event
self.FifthWindow.closeEvent = self.finish_btn_event
self.current_window = ''
# setup year input window
def setup_year_window(self):
#YEAR WINDOW - ACADEMIC YEAR INPUT
logger.debug('Initializing and setting up year window')
self.YearWindow = QDialog()
self.ui_year = Ui_year_window()
self.ui_year.setupUi(self.YearWindow)
months = ['January','February','March','April','May','June','July','August','September','October','November','December']
for m in months:
self.ui_year.startMonth_combobox.addItem(m)
self.ui_year.endMonth_combobox.addItem(m)
depts = ['Biotechnology', 'Civil Engineering', 'Computer Science & Engineering', 'Electronics & Communications Engineering',\
'Electrical & Electronics Engineering', 'Information Science & Engineering', 'Mechanical Engineering']
for d in depts:
self.ui_year.dept_combobox.addItem(d)
self.ui_year.startYear_dateedit.setDate(QtCore.QDate.currentDate())
self.ui_year.endYear_dateedit.setDate(QtCore.QDate.currentDate())
self.ui_year.continueBtn.clicked.connect(self.continue_btn_event)
self.ui_year.skipBtn.clicked.connect(self.next_btn_event)
self.startMonth = ''
self.startYear = ''
self.endMonth = ''
self.endYear = ''
self.department = ''
# setup first input window
def setup_first_window(self):
#FIRST WINDOW - List Entry
logger.debug('Initializing and setting up first window')
self.FirstWindow = QMainWindow()
self.ui = Ui_window()
self.ui.setupUi(self.FirstWindow)
self.ui.semester_combobox.setEnabled(False)
self.ui.label_3.setEnabled(False)
self.ui.sections_spinbox.setEnabled(False)
self.ui.label_4.setEnabled(False)
self.ui.input_textbox.setEnabled(False)
self.ui.label_5.setEnabled(False)
self.ui.title_combobox.setEnabled(False)
self.ui.desig_combobox.setEnabled(False)
self.ui.label_9.setEnabled(False)
self.ui.subject_code_input.setEnabled(False)
self.ui.label_8.setEnabled(False)
self.ui.subject_short_input.setEnabled(False)
self.ui.label_6.setEnabled(False)
self.ui.lab_checkbox.setEnabled(False)
self.ui.credits_spinbox.setEnabled(False)
self.ui.label_7.setEnabled(False)
self.ui.electiveBtn.setEnabled(False)
self.ui.line.setEnabled(False)
self.ui.line_2.setEnabled(False)
self.ui.addBtn.clicked.connect(self.add_btn_event)
self.ui.electiveBtn.clicked.connect(self.elective_btn_event)
self.ui.removeBtn.clicked.connect(self.remove_btn_event)
self.ui.nextBtn.clicked.connect(self.next_btn_event)
self.ui.sections_spinbox.valueChanged.connect(self.section_spinbox_event)
self.ui.inputType_combobox.addItem("Faculty")
self.ui.inputType_combobox.addItem("Subjects")
self.ui.inputType_combobox.setCurrentIndex(-1)
self.ui.desig_combobox.setCurrentIndex(-1)
self.ui.title_combobox.setCurrentIndex(-1)
self.ui.inputType_combobox.activated[str].connect(self.inputType_combobox_event)
self.ui.semester_combobox.activated[str].connect(self.semester_combobox_event)
self.ui.input_textbox.returnPressed.connect(self.ui.addBtn.click)
self.ui.subject_short_input.returnPressed.connect(self.ui.addBtn.click)
self.ui.input_list.itemClicked.connect(self.handle_listclick_event)
self.ui.addBtn.setAutoDefault(True)
self.sem_list = ['III', 'IV', 'V', 'VI', 'VII', 'VIII']
for sem in self.sem_list:
self.ui.semester_combobox.addItem(sem)
self.ui.semester_combobox.setCurrentIndex(-1)
self.cur_open_filename = ''
self.faculty_list_value = []
self.subjects = OrderedDict()
self.subs = dict() # store link between subject short name and its object
self.num_sections = OrderedDict()
for sem in self.sem_list:
self.subjects[sem] = []
self.num_sections[sem] = 0
self.inputType = ""
self.text = ""
self.sem = ""
self.row = self.ui.input_list.selectedItems()
for value in titles_list:
self.ui.title_combobox.addItem(value)
self.desig_list = ['Assistant Professor', 'Professor', 'Associate Professor', 'Head of Department', 'Principal']
for val in self.desig_list:
self.ui.desig_combobox.addItem(val)
self.FirstWindow.resize(self.screen_width*self.resize_ratio, self.screen_height*self.resize_ratio)
self.FirstWindow.updateGeometry()
self.ui.menubar.triggered[QtWidgets.QAction].connect(self.filemenuevent)
#setting up elective window, about window and license window during first window setup
self.setup_elective_window()
self.setup_about_window()
self.setup_license_window()
#setup elective input window
def setup_elective_window(self):
#ELECTIVE WINDOW - Elective Entry
logger.debug('Initializing and setting up elective window')
self.ElectiveWindow = QWidget()
self.ui_elec = Ui_elective_window()
self.ui_elec.setupUi(self.ElectiveWindow)
self.ui_elec.semester_combobox.setEnabled(True)
self.ui_elec.elective_spinbox.setEnabled(False)
self.ui_elec.elective_spinbox.setValue(0)
self.ui_elec.label_4.setEnabled(False)
self.ui_elec.electiveGroup_combobox.setEnabled(False)
self.ui_elec.label_3.setEnabled(False)
self.ui_elec.elective_input_textbox.setEnabled(False)
self.ui_elec.label_5.setEnabled(False)
self.ui_elec.elective_code_input.setEnabled(False)
self.ui_elec.label_8.setEnabled(False)
self.ui_elec.elective_short_input.setEnabled(False)
self.ui_elec.label_6.setEnabled(False)
self.ui_elec.credits_spinbox.setEnabled(False)
self.ui_elec.label_7.setEnabled(False)
self.ui_elec.lab_checkbox.setEnabled(False)
self.ui_elec.line.setEnabled(False)
self.ui_elec.line_2.setEnabled(False)
self.electives = dict()
for sem in self.sem_list:
self.ui_elec.semester_combobox.addItem(sem)
self.electives[sem] = dict()
self.ui_elec.semester_combobox.setCurrentIndex(-1)
self.ui_elec.semester_combobox.activated[str].connect(self.semester_combobox_elective_event)
self.ui_elec.elective_spinbox.valueChanged.connect(self.elective_spinbox_event)
self.ui_elec.elective_short_input.returnPressed.connect(self.ui_elec.addBtn.click)
self.ui_elec.elective_input_textbox.returnPressed.connect(self.ui_elec.addBtn.click)
self.ui_elec.backBtn.clicked.connect(self.elective_btn_event)
self.ui_elec.addBtn.setAutoDefault(True)
self.ui_elec.addBtn.clicked.connect(self.add_btn_elective_event)
self.ui_elec.elective_list.itemClicked.connect(self.handle_listclick_elective_event)
self.ui_elec.removeBtn.clicked.connect(self.remove_btn_elective_event)
self.ui_elec.electiveGroup_combobox.activated[str].connect(self.electivegroup_combobox_event)
self.ui_elec.resetBtn.clicked.connect(self.reset_Btn_event)
#setup assignment input window
def setup_second_window(self):
#SECOND WINDOW - Faculty assignment
logger.debug('Initializing and setting up second window')
self.SecondWindow = QMainWindow()
self.ui2 = Ui_window2()
self.ui2.setupUi(self.SecondWindow)
self.ui2.faculty_combobox.setCurrentIndex(-1)
self.ui2.semester_combobox.setCurrentIndex(-1)
self.ui2.section_combobox.setCurrentIndex(-1)
self.ui2.subject_combobox.setCurrentIndex(-1)
self.ui2.nextBtn.clicked.connect(self.next_btn_event)
self.ui2.backBtn.clicked.connect(self.back_btn_event)
self.ui2.semester_combobox.activated[str].connect(self.semester_combobox2_event)
self.ui2.assignBtn.clicked.connect(self.assign_btn_event)
self.ui2.undoBtn.clicked.connect(self.undo_btn_event)
self.ui2.section_combobox.activated[str].connect(self.section_combobox2_event)
self.ui2.faculty_combobox.activated[str].connect(self.faculty_combobox2_event)
self.sections = OrderedDict()
self.subjects_assigned = OrderedDict() # this dict will be like {'III': {'A': [subjects], 'B': [subjects]}, 'IV': {} ..etc}
self.faculty_subjects = dict() # stores subjects assigned to each faculty
self.SecondWindow.resize(self.screen_width*self.resize_ratio, self.screen_height*self.resize_ratio)
self.SecondWindow.updateGeometry()
self.ui2.menubar.triggered[QtWidgets.QAction].connect(self.filemenuevent)
#setup subject constraint window
def setup_third_window(self):
#THIRD WINDOW - Subject Constraints
logger.debug('Initializing and setting up third window')
self.ThirdWindow = QMainWindow()
self.ui3 = Ui_window3()
self.ui3.setupUi(self.ThirdWindow)
self.ui3.section_combobox.setCurrentIndex(-1)
self.ui3.slotType_combobox.setCurrentIndex(-1)
self.ui3.nextBtn.clicked.connect(self.next_btn_event)
self.ui3.backBtn.clicked.connect(self.back_btn_event)
self.ui3.semester_combobox.activated[str].connect(self.semester_combobox3_event)
self.ui3.section_combobox.activated[str].connect(self.section_combobox3_event)
self.ui3.slotType_combobox.activated[str].connect(self.slotType_combobox3_event)
self.ui3.subject_table.cellClicked.connect(self.cellClick3_event)
for sem in self.sem_list:
self.ui3.semester_combobox.addItem(sem)
self.ui3.semester_combobox.setCurrentIndex(-1)
self.section_fixed_slots = dict()
self.ThirdWindow.resize(self.screen_width*self.resize_ratio, self.screen_height*self.resize_ratio)
self.ThirdWindow.updateGeometry()
self.ui3.menubar.triggered[QtWidgets.QAction].connect(self.filemenuevent)
#setup faculty constraint window
def setup_fourth_window(self):
#FOURTH WINDOW - Faculty Constraints
logger.debug('Initializing and setting up fourth window')
self.FourthWindow = QMainWindow()
self.ui4 = Ui_window4()
self.ui4.setupUi(self.FourthWindow)
self.ui4.faculty_combobox.activated[str].connect(self.faculty_combobox4_event)
self.ui4.faculty_table.cellClicked.connect(self.cellClick4_event)
self.ui4.generateBtn.clicked.connect(self.next_btn_event)
self.ui4.backBtn.clicked.connect(self.back_btn_event)
self.ui4.generateBtn.clicked.connect(self.generate_event)
self.faculty_fixed_slots = dict()
self.ui4.faculty_combobox.setCurrentIndex(-1)
self.FourthWindow.resize(self.screen_width*self.resize_ratio, self.screen_height*self.resize_ratio)
self.FourthWindow.updateGeometry()
self.ui4.menubar.triggered[QtWidgets.QAction].connect(self.filemenuevent)
#setup timetable display window
def setup_fifth_window(self):
#FIFTH WINDOW - Generated timetable
logger.debug('Initializing and setting up fifth window')
self.FifthWindow = QMainWindow()
self.ui5 = Ui_window5()
self.ui5.setupUi(self.FifthWindow)
self.ui5.finishBtn.clicked.connect(lambda: self.FifthWindow.close())
self.ui5.backBtn.clicked.connect(self.back_btn_event)
self.ui5.printBtn.clicked.connect(self.print_btn_event)
self.ui5.inputType_combobox.activated[str].connect(self.inputType_combobox_event)
self.ui5.semester_combobox.activated[str].connect(self.semester_combobox5_event)
self.ui5.section_combobox.activated[str].connect(self.section_combobox5_event)
self.ui5.faculty_combobox.activated[str].connect(self.faculty_combobox5_event)
self.ui5.generated_table.cellClicked.connect(self.cellClick5_event)
self.ui5.roomno_textbox.textEdited.connect(self.roomno_textbox_event)
self.ui5.roomno_textbox.returnPressed.connect(self.roomno_textbox_event)
self.ui5.faculty_combobox.setEnabled(False)
self.ui5.label_5.setEnabled(False)
self.ui5.inputType_combobox.addItem('Students')
self.ui5.inputType_combobox.addItem('Faculty')
self.ui5.inputType_combobox.setCurrentIndex(-1)
self.ui5.semester_combobox.setCurrentIndex(-1)
self.ui5.section_combobox.setCurrentIndex(-1)
self.ui5.faculty_combobox.setCurrentIndex(-1)
self.timetables = ''
self.faculty_timetables = ''
self.selected_cell = ()
self.FifthWindow.resize(self.screen_width*self.resize_ratio, self.screen_height*self.resize_ratio)
self.FifthWindow.updateGeometry()
self.ui5.menubar.triggered[QtWidgets.QAction].connect(self.filemenuevent)
#setup about window
def setup_about_window(self):
# ABOUT WINDOW
logger.debug('Initializing and setting up about window')
self.AboutWindow = QDialog()
self.ui_about = Ui_aboutWindow()
self.ui_about.setupUi(self.AboutWindow)
self.ui_about.logoLabel.setPixmap(QtGui.QPixmap('icons/nittelogo.png'))
self.ui_about.closeBtn.clicked.connect(self.AboutWindow.hide)
#setup license window
def setup_license_window(self):
# LICENSE WINDOW
logger.debug('Initializing and setting up license window')
self.LicenseWindow = QDialog()
self.ui_license = Ui_licenseWindow()
self.ui_license.setupUi(self.LicenseWindow)
self.ui_license.logoLabel.setPixmap(QtGui.QPixmap('icons/nittelogo.png'))
self.ui_license.licenseBtn.clicked.connect(self.license_btn_event)
self.ui_license.closeBtn.clicked.connect(self.LicenseWindow.hide)
#license window function
def license_btn_event(self):
try:
l = os.path.realpath(os.curdir) + '\\license.txt'
os.startfile(l)
logger.debug('%s opened', l)
except Exception as err:
self.file_error_dialog(err)
logger.exception(err)
# year window functions
def continue_btn_event(self):
self.startMonth = self.ui_year.startMonth_combobox.currentText()
self.startYear = self.ui_year.startYear_dateedit.date().year()
self.endMonth = self.ui_year.endMonth_combobox.currentText()
self.endYear = self.ui_year.endYear_dateedit.date().year()
self.department = self.ui_year.dept_combobox.currentText()
logger.info('Academic year: %s %s %s %s Department: %s', self.startMonth, self.startYear, self.endMonth, self.endYear, self.department)
#print(self.startMonth, self.startYear, self.endMonth, self.endYear, self.department)
self.next_btn_event()
def reset_year_window(self):
logger.debug('Resetting Year Window')
self.ui_year.startYear_dateedit.setDate(QtCore.QDate.fromString(str(self.startYear), 'yyyy'))
self.ui_year.endYear_dateedit.setDate(QtCore.QDate.fromString(str(self.endYear), 'yyyy'))
i = self.ui_year.startMonth_combobox.findText(self.startMonth)
if i >= 0:
self.ui_year.startMonth_combobox.setCurrentIndex(i)
i = self.ui_year.endMonth_combobox.findText(self.endMonth)
if i >= 0:
self.ui_year.endMonth_combobox.setCurrentIndex(i)
i = self.ui_year.dept_combobox.findText(self.department)
if i >= 0:
self.ui_year.dept_combobox.setCurrentIndex(i)
# first form functions
def inputType_combobox_event(self): #function for input type combobox in first form
if self.FirstWindow.isVisible():
self.row = []
self.inputType = self.ui.inputType_combobox.currentText()
logger.info('Input type: %s', self.inputType)
if self.row:
del self.row[0]
logger.info('Selected row in list: %s', self.row)
if self.inputType == "Faculty":
self.ui.semester_combobox.setEnabled(False)
self.ui.label_3.setEnabled(False)
self.ui.sections_spinbox.setEnabled(False)
self.ui.label_4.setEnabled(False)
self.ui.title_combobox.setEnabled(True)
self.ui.input_textbox.setEnabled(True)
self.ui.label_5.setEnabled(True)
self.ui.desig_combobox.setEnabled(True)
self.ui.label_9.setEnabled(True)
self.ui.subject_code_input.setEnabled(False)
self.ui.label_8.setEnabled(False)
self.ui.subject_short_input.setEnabled(False)
self.ui.label_6.setEnabled(False)
self.ui.credits_spinbox.setEnabled(False)
self.ui.label_7.setEnabled(False)
self.ui.lab_checkbox.setEnabled(False)
self.ui.line.setEnabled(True)
self.ui.line_2.setEnabled(False)
self.ui.electiveBtn.setEnabled(False)
self.ui.desig_combobox.setCurrentIndex(-1)
self.ui.title_combobox.setCurrentIndex(-1)
self.ui.input_textbox.clear()
self.ui.input_textbox.setPlaceholderText("Please enter faculty name")
self.ui.input_list.clear()
for values in self.faculty_list_value:
self.ui.input_list.addItem(values.name)
else: # input type subjects
self.ui.semester_combobox.setEnabled(True)
self.ui.label_3.setEnabled(True)
self.ui.sections_spinbox.setEnabled(True)
self.ui.label_4.setEnabled(True)
self.ui.title_combobox.setEnabled(False)
self.ui.input_textbox.setEnabled(True)
self.ui.label_5.setEnabled(True)
self.ui.desig_combobox.setEnabled(False)
self.ui.label_9.setEnabled(False)
self.ui.subject_code_input.setEnabled(True)
self.ui.subject_code_input.clear()
self.ui.label_8.setEnabled(True)
self.ui.subject_short_input.setEnabled(True)
self.ui.subject_short_input.clear()
self.ui.label_6.setEnabled(True)
self.ui.credits_spinbox.setEnabled(True)
self.ui.credits_spinbox.setValue(1)
self.ui.label_7.setEnabled(True)
self.ui.lab_checkbox.setEnabled(True)
self.ui.lab_checkbox.setChecked(False)
self.ui.line.setEnabled(True)
self.ui.line_2.setEnabled(True)
self.ui.input_textbox.clear()
self.ui.input_textbox.setPlaceholderText("Please enter subject name")
self.ui.electiveBtn.setEnabled(True)
sem = self.ui.semester_combobox.currentText()
self.ui.input_list.clear()
if sem in self.subjects:
for subject in self.subjects[sem]:
self.ui.input_list.addItem(subject.both_names)
#same method is used for fifth window. Do This in other combobox for other windows
if self.FifthWindow.isVisible():
self.inputType = self.ui5.inputType_combobox.currentText()
logger.info(self.inputType)
if self.inputType == "Faculty":
self.ui5.semester_combobox.setCurrentIndex(-1)
self.ui5.section_combobox.setCurrentIndex(-1)
self.ui5.semester_combobox.setEnabled(False)
self.ui5.label_3.setEnabled(False)
self.ui5.section_combobox.setEnabled(False)
self.ui5.label_4.setEnabled(False)
self.ui5.faculty_combobox.setEnabled(True)
self.ui5.label_5.setEnabled(True)
self.ui5.roomno_textbox.setEnabled(False)
self.ui5.label_6.setEnabled(False)
self.ui5.faculty_combobox.setCurrentIndex(-1)
self.ui5.generated_table.clearContents()
else: #input type subjects
self.ui5.semester_combobox.clear()
for sem in self.sem_list:
self.ui5.semester_combobox.addItem(sem)
self.ui5.semester_combobox.setEnabled(True)
self.ui5.label_3.setEnabled(True)
self.ui5.semester_combobox.setCurrentIndex(-1)
self.ui5.section_combobox.setEnabled(True)
self.ui5.label_4.setEnabled(True)
self.ui5.section_combobox.setCurrentIndex(-1)
self.ui5.faculty_combobox.setCurrentIndex(-1)
self.ui5.faculty_combobox.setEnabled(False)
self.ui5.label_5.setEnabled(False)
self.ui5.roomno_textbox.setEnabled(True)
self.ui5.label_6.setEnabled(True)
self.ui5.generated_table.clearContents()
def semester_combobox_event(self): #function for semester combobox
self.row = []
if self.sem != '' and self.sem not in self.num_sections:
self.num_sections[self.sem] = self.ui.sections_spinbox.value()
logger.info('No. of sections in %s: %s', self.sem, self.num_sections[self.sem])
self.sem = self.ui.semester_combobox.currentText()
if self.sem in self.num_sections:
self.ui.sections_spinbox.setValue(self.num_sections[self.sem])
else:
self.ui.sections_spinbox.setValue(0)
self.ui.input_list.clear()
if self.sem in self.subjects:
for sub in self.subjects[self.sem]:
self.ui.input_list.addItem(sub.both_names)
self.ui.input_list.clearSelection()
if self.row:
del self.row[0]
self.ui.input_textbox.clear()
self.ui.input_textbox.setPlaceholderText("Please enter subject name")
self.ui.subject_short_input.clear()
self.ui.credits_spinbox.setValue(1)
logger.info('Selected row in list: %s', self.row)
def section_spinbox_event(self): #function for sections spinbox
if self.sem != '':
self.num_sections[self.sem] = self.ui.sections_spinbox.value() #saves the number of sections when "add" button is clicked
logger.info('%s %s', self.sem, self.num_sections[self.sem])
def add_btn_event(self): #function for add button
logger.debug('Add button first form')
text = self.ui.input_textbox.text()
if self.row: #when editing a currently selected value in list
logger.debug('Editing selected item')
logger.debug('Input type: %s', self.inputType)
if self.inputType == "Subjects":
for x in self.row:
subj = subject(x.text())
sem = self.ui.semester_combobox.currentText()
for y in self.subjects[sem]:
if subj == y:
if not sem:
self.systemtray_icon.showMessage('Input', 'Please select the semester.')
self.systemtray_icon.hide()
logger.debug('Input-Please select the semester.')
return
if text != '':
short_sub = self.ui.subject_short_input.text()
if not short_sub:
self.systemtray_icon.showMessage('Input', 'Please enter the subject short form.')
self.systemtray_icon.hide()
logger.debug('Input-Please enter the subject short form.')
return
subcode = self.ui.subject_code_input.text()
credits = self.ui.credits_spinbox.value()
lab = self.ui.lab_checkbox.isChecked()
y.name = text
y.short_name = short_sub
y.credits = credits
y.lab = lab
y.subcode = subcode
logger.info('Subject details(name, shortname, credits, lab) :%s %s %s %s', text, short_sub, credits, lab)
t = text + " - " + short_sub
self.ui.input_list.takeItem(self.ui.input_list.row(x))
self.ui.input_list.addItem(t)
if y.name != text or y.short_name != short_sub:
self.update_subject_changes(subj, y)
self.ui.credits_spinbox.setValue(1)
break
else: #input type is faculty
for x in self.row:
fac = x.text()
for y in self.faculty_list_value:
if fac == y.name:
y.title = self.ui.title_combobox.currentText()
y.name = text
y.designation = self.ui.desig_combobox.currentText()
self.ui.input_list.takeItem(self.ui.input_list.row(x))
self.ui.input_list.addItem(text)
self.update_faculty_changes(fac, y)
logger.debug('Faculty details(title, name, designation): %s %s %s', y.title, y.name, y.designation)
break
self.ui.input_list.clearSelection()
self.row = []
logger.info('Selected row in list: %s', self.row)
self.ui.input_list.repaint()
else: #when adding a new item
logger.debug('Adding new item')
logger.debug('Input type: %s', self.inputType)
if self.inputType == "Subjects":
sem = self.ui.semester_combobox.currentText()
if not sem:
self.systemtray_icon.showMessage('Input', 'Please select the semester.')
self.systemtray_icon.hide()
logger.debug('Input-Please select the semester.')
return
if text != '':
short_sub = self.ui.subject_short_input.text()
if not short_sub:
self.systemtray_icon.showMessage('Input', 'Please enter the subject short form.')
self.systemtray_icon.hide()
logger.debug('Input-Please enter the subject short form.')
return
subcode = self.ui.subject_code_input.text()
credits = self.ui.credits_spinbox.value()
lab = self.ui.lab_checkbox.isChecked()
sub = subject(text, short_sub, credits, lab, subcode)
logger.info('Subject details(name, shortname, credits, lab) :%s %s %s %s', text, short_sub, credits, lab)
t = text + " - " + short_sub
for x in self.subjects[sem]:
if sub == x:
self.systemtray_icon.showMessage('Warning!', 'Duplicate value entered.')
self.systemtray_icon.hide()
logger.debug('Warning! Duplicate value entered.')
break
else: # loop completed without finding duplicates
self.ui.input_list.addItem(t)
self.subjects[sem].append(sub)
self.subs[sub.short_name] = sub
self.ui.credits_spinbox.setValue(1)
else:
self.systemtray_icon.showMessage('Input', 'Please enter the subject name.')
self.systemtray_icon.hide()
logger.debug('Input-Please enter the subject name.')
elif self.inputType == "Faculty": # input type is Faculty
if text != '':
title = self.ui.title_combobox.currentText()
t = title + " " + text
if t not in self.faculty_list_value:
f = faculty_class(t)
f.designation = self.ui.desig_combobox.currentText()
self.faculty_list_value.append(f)
self.ui.input_list.addItem(text)
logger.debug('Faculty details(title, name, designation): %s %s', t, f.designation)
else:
self.systemtray_icon.showMessage('Warning!', 'Duplicate value entered.')
self.systemtray_icon.hide()
logger.debug('Warning! Duplicate value entered.')
else:
self.systemtray_icon.showMessage('Input', 'Please enter the faculty name.')
self.systemtray_icon.hide()
logger.debug('Input-Please enter the faculty name.')
self.ui.title_combobox.setCurrentIndex(0)
else:
self.systemtray_icon.showMessage('Input', 'Please select the input type.')
self.systemtray_icon.hide()
logger.debug('Input-Please enter the input type.')
self.ui.input_list.sortItems()
self.ui.desig_combobox.setCurrentIndex(-1)
self.ui.title_combobox.setCurrentIndex(-1)
self.ui.subject_short_input.clear()
self.ui.input_textbox.clear()
self.ui.subject_code_input.clear()
self.ui.lab_checkbox.setChecked(False)
self.ui.input_textbox.setFocus()
logger.info('Faculty list: %s', self.faculty_list_value)
logger.info('Subjects list: %s', self.subjects)
def update_subject_changes(self, old_sub, new_sub):
# changes in subs, section_fixed_slots, subjects_assigned, faculty_subjects
if old_sub.short_name != new_sub.short_name:
del self.subs[old_sub.short_name]
self.subs[new_sub.short_name] = new_sub
for sem in self.section_fixed_slots:
for section in self.section_fixed_slots[sem]:
for row in self.section_fixed_slots[sem][section]:
for col in self.section_fixed_slots[sem][section][row]:
if self.section_fixed_slots[sem][section][row][col] == old_sub.short_name:
self.section_fixed_slots[sem][section][row][col] = new_sub.short_name
self.subs[old_sub.short_name] = new_sub
for sem in self.subjects_assigned:
for section in self.subjects_assigned[sem]:
for i, sub in enumerate(self.subjects_assigned[sem][section]):
sub = sub.split(' - ')
if sub[0] == old_sub.name and sub[1] == old_sub.short_name:
self.subjects_assigned[sem][section][i] = new_sub.both_names + ' - ' + sub[2]
teachers = sub[2].split(', ')
for teacher in teachers:
for i, sub in enumerate(self.faculty_subjects[teacher]):
sub = sub.split(' - ')
if sub[0] == old_sub.name and sub[1] == old_sub.short_name:
self.faculty_subjects[teacher][i] = new_sub.both_names + ' - ' + sub[2]
break # move to next section
pass
def update_faculty_changes(self, old_fac, new_fac):
# changes in subjects_assigned, faculty_subjects, faculty_fixed_slots
if old_fac != new_fac:
for sem in self.subjects_assigned:
for section in self.subjects_assigned[sem]:
for i, sub in enumerate(self.subjects_assigned[sem][section]):
sub = sub.split(' - ')
if sub[2] == old_fac:
self.subjects_assigned[sem][section][i] = ' - '.join(sub[:2]) + ' - ' + new_fac.name
if old_fac in self.faculty_subjects:
self.faculty_subjects[new_fac] = self.faculty_subjects.pop(old_fac)
if old_fac in self.faculty_fixed_slots:
self.faculty_fixed_slots[new_fac] = self.faculty_fixed_slots.pop(old_fac)
pass
def handle_listclick_event(self):
self.row = self.ui.input_list.selectedItems()
sem = self.ui.semester_combobox.currentText()
if self.inputType == "Subjects":
for x in self.row:
subj = subject(x.text())
for y in self.subjects[sem]:
if subj.name == y.name:
self.ui.input_textbox.setText(subj.name)
self.ui.subject_short_input.setText(subj.short_name)
self.ui.credits_spinbox.setValue(y.credits)
self.ui.subject_code_input.setText(y.subcode)
if y.lab == True:
self.ui.lab_checkbox.setChecked(True)
else:
self.ui.lab_checkbox.setChecked(False)
break
else:
for x in self.row:
fac = x.text()
for y in self.faculty_list_value:
if fac == y.name:
self.ui.input_textbox.setText(y.name)
index = self.ui.title_combobox.findText(y.title)
if index >= 0:
self.ui.title_combobox.setCurrentIndex(index)
else:
self.ui.title_combobox.setCurrentIndex(-1)
index = self.ui.desig_combobox.findText(y.designation)
if index >= 0:
self.ui.desig_combobox.setCurrentIndex(index)
else:
self.ui.desig_combobox.setCurrentIndex(-1)
break
def elective_btn_event(self):
logger.debug('Elective button first form')
if self.ElectiveWindow.isVisible():
self.ElectiveWindow.hide()
else:
logger.info('Elective Window')
self.ElectiveWindow.show()
self.reset_Btn_event()
def remove_btn_event(self): #function for remove button
logger.debug('Remove button first form')
row = self.ui.input_list.selectedItems()
self.row = []
if not row:
self.systemtray_icon.showMessage('Warning!', 'Select item to remove.')
self.systemtray_icon.hide()
logger.debug('Warning! Select item to remove.')
else:
for x in row:
self.ui.input_list.takeItem(self.ui.input_list.row(x))
try:
if self.inputType == "Subjects":
self.systemtray_icon.showMessage('Subjects', x.text() + ' removed from the subject list')
self.systemtray_icon.hide()
logger.debug('Subjects-%s removed from the subject list.', x.text())
self.subjects[self.sem].remove(subject(x.text()))
else:
self.faculty_list_value.remove(x.text())
self.systemtray_icon.showMessage('Faculty', x.text() + ' removed from the faculty list')
self.systemtray_icon.hide()
logger.debug('Faculty-%s removed from the faculty list.', x.text())
finally: # not catching exceptions, we want to see the error
pass
self.ui.input_list.clearSelection()
self.ui.input_list.repaint()
logger.info('Faculty list: %s', self.faculty_list_value)
logger.info('Subjects list: %s', self.subjects)
def reset_first_window(self):
logger.debug('Resetting First Window')
self.ui.semester_combobox.setEnabled(False)
self.ui.sections_spinbox.setEnabled(False)
self.ui.input_textbox.setEnabled(False)
self.ui.title_combobox.setEnabled(False)
self.ui.subject_code_input.setEnabled(False)
self.ui.subject_short_input.setEnabled(False)
self.ui.lab_checkbox.setEnabled(False)
self.ui.desig_combobox.setEnabled(False)
self.ui.credits_spinbox.setEnabled(False)
self.ui.label_3.setEnabled(False)
self.ui.label_4.setEnabled(False)
self.ui.label_5.setEnabled(False)
self.ui.label_6.setEnabled(False)
self.ui.label_7.setEnabled(False)
self.ui.label_8.setEnabled(False)
self.ui.label_9.setEnabled(False)
self.ui.line.setEnabled(False)
self.ui.line_2.setEnabled(False)
self.ui.electiveBtn.setEnabled(False)
self.ui.input_textbox.setPlaceholderText("")
self.ui.inputType_combobox.setCurrentIndex(-1)
self.ui.semester_combobox.setCurrentIndex(-1)
self.ui.input_list.clear()
#elective form functions
def semester_combobox_elective_event(self):
self.ui_elec.electiveGroup_combobox.setCurrentIndex(-1)
self.ui_elec.electiveGroup_combobox.clear()
sem = self.ui_elec.semester_combobox.currentText()
self.ui_elec.electiveGroup_combobox.setEnabled(False)
self.ui_elec.label_3.setEnabled(False)
for group in self.electives[sem]:
self.ui_elec.electiveGroup_combobox.addItem(group)
self.ui_elec.electiveGroup_combobox.setEnabled(True)
self.ui_elec.label_3.setEnabled(True)
self.ui_elec.elective_input_textbox.clear()
self.ui_elec.elective_input_textbox.setPlaceholderText("")
self.ui_elec.elective_input_textbox.setEnabled(False)
self.ui_elec.label_5.setEnabled(False)
self.ui_elec.elective_spinbox.setEnabled(True)
self.ui_elec.elective_spinbox.setValue(len(self.electives[sem]))
self.ui_elec.label_4.setEnabled(True)
self.ui_elec.elective_code_input.clear()
self.ui_elec.elective_code_input.setEnabled(False)
self.ui_elec.label_8.setEnabled(False)
self.ui_elec.elective_short_input.clear()
self.ui_elec.elective_short_input.setEnabled(False)
self.ui_elec.label_6.setEnabled(False)
self.ui_elec.credits_spinbox.setValue(1)
self.ui_elec.credits_spinbox.setEnabled(False)
self.ui_elec.label_7.setEnabled(False)
self.ui_elec.lab_checkbox.setChecked(False)
self.ui_elec.lab_checkbox.setEnabled(False)
self.ui_elec.line.setEnabled(True)
self.ui_elec.line_2.setEnabled(False)
self.ui_elec.elective_list.clear()
def electivegroup_combobox_event(self):
self.ui_elec.elective_input_textbox.setPlaceholderText("Please enter elective name")
self.ui_elec.elective_input_textbox.setEnabled(True)
self.ui_elec.label_5.setEnabled(True)
self.ui_elec.elective_code_input.setEnabled(True)
self.ui_elec.label_8.setEnabled(True)
self.ui_elec.elective_short_input.setEnabled(True)
self.ui_elec.label_6.setEnabled(True)
self.ui_elec.credits_spinbox.setEnabled(True)
self.ui_elec.label_7.setEnabled(True)
self.ui_elec.lab_checkbox.setEnabled(True)
self.ui_elec.line_2.setEnabled(True)
self.ui_elec.elective_list.clear()
sem = self.ui_elec.semester_combobox.currentText()
electivegroup = self.ui_elec.electiveGroup_combobox.currentText()
if electivegroup in self.electives[sem]:
for sub in self.electives[sem][electivegroup]:
self.ui_elec.elective_list.addItem(sub.both_names)
self.ui_elec.elective_list.clearSelection()
def elective_spinbox_event(self):
no_of_ele_grp = self.ui_elec.elective_spinbox.value()
logger.info('No of elective groups %s',no_of_ele_grp)
self.ui_elec.electiveGroup_combobox.setEnabled(True)
self.ui_elec.label_3.setEnabled(True)
self.ui_elec.electiveGroup_combobox.clear()
for i in range(0, no_of_ele_grp):
s = 'Elective ' + str(i+1)
self.ui_elec.electiveGroup_combobox.addItem(s)
self.ui_elec.electiveGroup_combobox.setCurrentIndex(-1)
def add_btn_elective_event(self):
logger.debug('Add button elective form')
text = self.ui_elec.elective_input_textbox.text()
sem = self.ui_elec.semester_combobox.currentText()
row = self.ui_elec.elective_list.selectedItems()
elective_group = self.ui_elec.electiveGroup_combobox.currentText()
short_sub = self.ui_elec.elective_short_input.text()
subcode = self.ui_elec.elective_code_input.text()
logger.debug('Adding %s elective to %s in %s', text, sem, elective_group)
if not sem:
self.systemtray_icon.showMessage('Input', 'Please select the semester.')
self.systemtray_icon.hide()
logger.debug('Input-Please select the semester.')
return
if not short_sub:
self.systemtray_icon.showMessage('Input', 'Please enter the elective short form.')
self.systemtray_icon.hide()
logger.debug('Input-Please enter the subject short form.')
return
if not elective_group:
self.systemtray_icon.showMessage('Input', 'Please select the elective group.')
self.systemtray_icon.hide()
logger.debug('Input-Please select the elective group.')
return
if row: #when editing a currently selected value in list
for x in row:
subj = subject(x.text())
sem = self.ui_elec.semester_combobox.currentText()
for y in self.electives[sem][elective_group]:
if subj == y:
if text != '':
credits = self.ui_elec.credits_spinbox.value()
lab = self.ui_elec.lab_checkbox.isChecked()
y.name = text
y.short_name = short_sub
y.credits = credits
y.lab = lab
y.subcode = subcode
logger.info('Elective details(name, shortname, credits, lab) :%s %s %s %s', text, short_sub, credits, lab)
t = text + " - " + short_sub
self.ui_elec.elective_list.takeItem(self.ui_elec.elective_list.row(x))
self.ui_elec.elective_list.addItem(t)
self.update_subject_changes(subj, y)