-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubsi_sheduler.py
363 lines (268 loc) · 16 KB
/
subsi_sheduler.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
import PySimpleGUI as sg
from pyxl import *
from unavlb_cls_sel import unavalible_cls_selector
from ShowTT import *
import shutil
from sys import exit
from os import name,system
import PySimpleGUI as sg
import pyperclip
from load_data import read_data_popup
empty_img = image_data = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\rIDATx\x9cc````\x00\x00\x00\x05\x00\x01\xa5\xf6E@\x00\x00\x00\x00IEND\xaeB`\x82'
data = read_data_popup()
if data == None:
error = "No data source selected"
else:
error = False
data = tuple(data) #make data immutatable
font_installed = False
for font in sg.Text.fonts_installed_list():
if str(font).lower() == "roboto mono":
font_installed = True
if name == 'nt':
win_os = True
from os import startfile
starting_size = (860,900)
starting_size_1 = (630,400)
else:
win_os = False
starting_size = (980,700)
starting_size_1 = (727,380)
sg.set_options(font='Calibri 11')
if not font_installed:
sg.popup('Please Install roboto mono font')
if win_os:
startfile('RobotoMono.ttf')
exit()
else:
sg.popup('Linux Detected ; Please install calibri font olso')
system('xdg-open "CalibriRegular.ttf"')
system('xdg-open "RobotoMono.ttf"')
sg.set_options(font='Helvetica 7')
info_icon = b'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB+0lEQVRIia3Wv2tTURQH8E9DBgcpAbWEDCWISCni4KCOUjAGNx1FioODqw4dHPwHHKSDiIiCi9XBTUWIoAiiCCIKFkGdtT/E34ikosO98T3jfS9a84VwX84753vOvff8eCPKMY4W9mALxlDBMubRwU28HMDzB+o4jSX8GPB7h4topohGErIWzuYMVnAXD/E67mADtmEX1kS9NziKy2WRH8TXGNknnESjRH89TuBttPmGY0XKU/gSFV9ge4y2HynZJB5H2y4O9CvU8SpHvilB0sAcrkfnqfePIsdCP8es7Fh2JozhvOxinxTsZEKWGHN5zwtROFtgSMiUnoNnqBboHY86H6JD01HwXUGq5aK7LZx1u0SvJrvLmXxk90qM/hVXI2enKmQAIc/LsBdb4/MiLpTo3sd+TFaF8ifkchn24XB8fjrAwfu4jhZd6NDQa1ywboi8tbh+rAhdkXTxrBY74jpfEVouocCaQyCvydK4U8EtISsqQjf833s5grX4jGs94SmDW8U5v7eKFDbLWsWVfLBjBje7tlCZMziUeF+XNbulFEdLNgvK2nUKEznyrjBXkpi2uoHTO5auvoGTGpltYWSOx/8ruIMHsmofFVJxSjYyF4UkuVQS0C80cEY2Cv9m6G9MEaV2kEdTuJvdwmdLPcqX8VyooRtKPlt+Aq3Ck3SHsl/0AAAAAElFTkSuQmCC'
try:
config_f = open("ss.config")
config = config_f.read().split(',')
config_f.close()
except:
config = None
update_s = False
if not error:
dep_found=find_departments(data)+['All']
out = []
out1 = []
window = None
Day = ['Monday','Tuesday','Wednesday','Thursday','Friday']
period = ['1','2','3','4','5','6','7','8']
selected_color = ('red', 'white')
active_day,active_period,department_ = 'Monday',1,'all'
teachers = []
teacher_selected = None
my_width, my_height = 1920,1080 # #
width, height = sg.Window.get_screen_size() # -------> Set optimal program scaling w.r.t. the screen
scaling_delta = min(width / my_width, height / my_height)
def make_window(scaling = 2.3 , theme = 'SandyBeach'):
global scale_var
global window
global scaling_delta
scale_var = scaling_delta*scaling/2.3
print(scaling_delta,scaling,scale_var)
if window != None:
window.close()
sg.theme(theme)
bg = sg.theme_background_color()
bg_b = sg.theme_element_background_color()
R_click_m = ['&Right',['Select unavailable classes','Preferences','Exit',]]
layout = [
[sg.Combo(values=dep_found,readonly=True,expand_x=True,key='department',auto_size_text=True,enable_events=True,default_value='All')],
[sg.Button(name,size = (9,1),expand_x=True) for name in Day],
[sg.Button(name,size=(1,1),expand_x=True) for name in period],
[
sg.Input(do_not_clear=True, size=(20,1),enable_events=True, key='_INPUT_FIND_TEACH_',expand_x=True),
sg.Button(image_data=info_icon,border_width=0, button_color=(bg, bg),key = 'Info_s')
],
[sg.HorizontalSeparator()],
[sg.Text('Available Faculty',expand_x=True,justification='center',text_color='green',background_color=bg_b),
sg.Text('Engaged Faculty',expand_x=True,justification='center',text_color='red',background_color=bg_b)],
[sg.Listbox(values=teachers,font = ('roboto mono',9),key = 'free_list',text_color='Green',expand_x=True,expand_y=True,size = (40,20), enable_events=True,auto_size_text=True),sg.VSep(),
sg.Listbox(values=teachers,font = ('roboto mono',9),key = 'busy_list',text_color='Red',expand_x=True,expand_y=True,size = (40,20), enable_events=True,auto_size_text=True)],
[sg.Text(' ',key='status',border_width = 0,expand_x=True),sg.Button(image_data=info_icon,border_width=0, button_color=(bg, bg),key = 'Info')]
]
window = sg.Window('Substitution Schedule Assistant',layout,auto_size_text=True,element_padding=0,scaling=scaling_delta*scaling,icon='icon.ico',margins=(1,1),resizable=True,right_click_menu=R_click_m)
window.finalize()
window.set_min_size(window.size)
#
window['Monday'].update(button_color=selected_color) # ------> Set defalt day,prd to monday,first prd and update the lists
window['1'].update(button_color=selected_color) #
active_day_index = int(Day.index(active_day)) #
active_period_num = int(active_period) #
total_teach = len(find_teach(data))
window['status'].update(f'Loaded {len(dep_found)} departments with {total_teach} teachers')
print('Window Made')
return(window)
scale_conf = None
theme = None
if config:
scale_conf = float(config[0])
theme = config[1]
print(theme)
window = make_window(scale_conf,theme)
window2 = popup_table_layout(scaling_delta*scale_conf,theme,starting_size_1,scale_var)
else:
window = make_window()
window2 = popup_table_layout(scaling_delta*2.3,'kayak',starting_size_1,scale_var)
counter = 0
old_search = ''
exec_class = []
exec_teach_raw = {}
out,table_data = [],[]
# event, values = window.read()
while True: # Event Loop
counter += 1 #
if counter > 1: #
x = None # ------> Initial one run to refresh lists
else: #
x= 0 #
win , event, values = sg.read_all_windows(x)
print(win , event,values,sep='\n#######################################################################\n',end='\n#######################################################################\n')
if event in (None, 'Exit'):
break
if event == 'Info':
sg.popup('Substitution Schedule Assistant(v4) \nMade with <3 by Parth Sahni\n\[email protected]')
try:
if win_os:
startfile("https://github.com/P-rth/Subtitution-scheduler")
else:
print("hello")
system('xdg-open "https://github.com/P-rth/Subtitution-scheduler"')
except:
sg.popup_error('error while opening github\nPlease open:https://github.com/P-rth/Subtitution-scheduler')
if event == 'Info_s':
sg.popup('This is the search bar \nIt can search for names,classes,number of free periods\nTo search unavailabe classes or teachers insted of cross use "!"')
if event == 'Edit Data':
if win_os:
window.start_thread(lambda: system('Teacher_data.xlsx'), ('-THREAD-', '-THEAD ENDED-'))
else:
window.start_thread(lambda: system('xdg-open Teacher_data.xlsx'), ('-THREAD-', '-THEAD ENDED-'))
if event == 'Select unavailable classes':
mylist = find_classes(data)
if exec_class != None:
old_exec = exec_class
exec_class = unavalible_cls_selector(mylist,old_exec)
else:
exec_class = unavalible_cls_selector(mylist)
if event in Day:
update_s = True
for k in Day:
window[k].update(button_color=sg.theme_button_color())
window[event].update(button_color=selected_color)
active_day = event
if event in period:
update_s = True
for k in period:
window[k].update(button_color=sg.theme_button_color())
window[event].update(button_color=selected_color)
active_period = event
if win == window:
if values['department']:
department_ = values['department']
else:
department_= None
if event in Day or event in period or counter == 1 or event in ['Select unavalible classes','department','Preferences','✘']:
update = True
else:
update = False
if active_period != None and active_day != None and department_ != None and update:
print(active_day,active_period,department_)
active_day_index = int(Day.index(active_day))
active_period_num = int(active_period)
f_b_teach = is_free(data,active_period_num,active_day_index,department_,exec_class,exec_teach_raw)
free_teach = f_b_teach[0]
busy_teach = f_b_teach[-1]
window['free_list'].update(values=free_teach)
window['busy_list'].update(values=busy_teach)
if event == 'free_list' and len(values['free_list']):
teacher_selected = values['free_list'][0]
teacher_selected = teacher_selected.split(':')[0].split('(')[0].strip() #split has been done so that unavalible prompt dosent mess it up
num_free_prd = find_free_periods_num(data,active_day_index,teacher_selected,exec_class)[0]
pyperclip.copy(teacher_selected)
window['status'].update(teacher_selected+' has '+str(num_free_prd)+' free period(s) on '+active_day)
print(teacher_selected+' has '+str(num_free_prd)+' free period(s) on '+active_day)
# f_teach_name = unformat_list(list(free_teach.keys()))
# window['free_list'].set_vscroll_position(f_teach_name.index(teacher_selected)/len(free_teach))
window.Element('busy_list').Update(busy_teach) #remove background from other list (intentional)
out,table_data = popup_table_update(teacher_selected,active_day,data,exec_class,window2,exec_teach_raw)
if event == 'busy_list' and len(values['busy_list']):
teacher_selected = values['busy_list'][0].split(':')[0].strip()
teacher_selected = teacher_selected.split(':')[0].split('(')[0].strip()
num_free_prd = find_free_periods_num(data,active_day_index,teacher_selected,exec_class)[0]
pyperclip.copy(teacher_selected)
window['status'].update(teacher_selected+' has '+str(num_free_prd)+' free period(s) on '+active_day)
print(teacher_selected+' has '+str(num_free_prd)+' free period(s) on '+active_day)
# b_teach_name = unformat_list(list(busy_teach.keys()))
# window['busy_list'].set_vscroll_position(b_teach_name.index(teacher_selected)/len(busy_teach))
window.Element('free_list').Update(free_teach) #remove background from other list (intentional)
out,table_data = popup_table_update(teacher_selected,active_day,data,exec_class,window2,exec_teach_raw)
if event == 'More Info':
if teacher_selected != None:
continue
else:
sg.popup('Select a teacher first')
if event in range(5):
unvlb_selected = [values[0],values[1],values[2],values[3],values[4]]
exec_teach_raw[teacher_selected] = unvlb_selected
counter = 0
if isinstance(event, tuple):
if event[0] == 'table':
if table_data != []:
if event[2][0] == -1 and event[2][1] != -1: # Header was clicked and wasn't the "row" column
col_num_clicked = event[2][1]
if col_num_clicked > 0:
asd = ''
for i in out[col_num_clicked-1]:
asd = asd+i+' '
print(asd)
pyperclip.copy(asd)
elif event[2][0] != None:
print(event)
print(table_data[event[2][0]])
asd = ''
for i in table_data[event[2][0]]:
asd = asd+i+' '
print(asd)
pyperclip.copy(asd)
if event == '?_tt':
sg.popup("Check the teacher's time Table. Crossed out classes mean the class is unavailable\nset unavailable to make teacher not show up in free list\nTo copy the time table for a day click the respective name of the day\nTo copy time table by period click on the respected row")
if event == 'Preferences':
if scale_conf and theme:
scale1,theme1 = pref_popup(scale_conf,theme)
if scale1 != scale_conf or theme1 != theme:
scale_conf = scale1
theme = theme1
window.close()
window2.close()
window = make_window(scale1,theme1)
window2 = popup_table_layout(scale1,theme1,starting_size_1,scale_var)
counter = 0
else:
scale_conf,Theme = pref_popup()
make_window(scale_conf,Theme)
if win == window:
if values['_INPUT_FIND_TEACH_'] not in ('',old_search,None) or event == "_INPUT_FIND_TEACH_" or update_s == True:
update_s = False # if a keystroke entered in search field
search = values['_INPUT_FIND_TEACH_']
lower_free_list = [y.lower().replace('✘','!') for y in free_teach]
new_values_free = [x for x in lower_free_list if search.lower() in x] # do the filtering
window.Element('free_list').Update([y.title().replace('!','✘') for y in new_values_free]) # display in the listbox
lower_busy_list = [y.lower().replace('✘','!') for y in busy_teach]
new_values_busy = [x for x in lower_busy_list if search.lower() in x] # do the filtering
window.Element('busy_list').Update([y.title().replace('!','✘') for y in new_values_busy]) # display in the listbox
elif values['_INPUT_FIND_TEACH_'] != old_search:
window.Element('free_list').Update(free_teach) # display original unfiltered list
window.Element('busy_list').Update(busy_teach)
continue
print(old_search)
old_search = values['_INPUT_FIND_TEACH_']
window.close()
else:
sg.popup(error)