-
Notifications
You must be signed in to change notification settings - Fork 2
/
tkinter_main.py
executable file
·252 lines (220 loc) · 9.95 KB
/
tkinter_main.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
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from Tkinter import *
from ttk import *
import tkMessageBox
import tkFileDialog
import sqlite3
import os
import math
import random
from ITUSIS_Parser import ITUSIS_Parser
class ITU_Programci():
def __init__(self):
if not os.path.isfile('classdb.sqlite'):
self.conn=sqlite3.connect('classdb.sqlite')
self.db=self.conn.cursor()
self.updateDatabase(True)
else:
self.conn=sqlite3.connect('classdb.sqlite')
self.db=self.conn.cursor()
self.initUI()
def initUI(self):
self.root = Tk()
self.initMenu()
self.initFrame()
self.initWidgets()
self.root.mainloop()
def initMenu(self):
self.menuBar = Menu(self.root)
self.root.config(menu=self.menuBar)
#Dosya Menusu
self.fileMenu=Menu(self.menuBar,tearoff=0)
self.fileMenu.add_command(label='Ac',command=self.load)
self.fileMenu.add_command(label='Kaydet',command=self.save)
self.menuBar.add_cascade(label="Dosya", menu=self.fileMenu)
#Program Menusu
self.progMenu=Menu(self.menuBar,tearoff=0)
self.progMenu.add_command(label='Sifirla', command=self.reset)
self.progMenu.add_command(label='Veritabanini guncelle', command=self.updateDatabase)
self.menuBar.add_cascade(label="Program", menu=self.progMenu)
def initFrame(self):
self.frame = Frame(self.root,height=565,width=840)
self.frame.master.title('ITU Programci')
self.frame.pack()
def initWidgets(self):
depCodeList=['']
for code in self.db.execute('select distinct Depcode from classes'):
depCodeList.append(code[0])
#Bolum kodlari sutunu
self.depLabel = Label(self.frame,text='Bolum')
self.depLabel.place(x=15,y=3)
self.depCodeSpinner=[]
for i in range(0,10):
self.depCodeSpinner.append(Combobox(self.frame,width=6,state='readonly'))
self.depCodeSpinner[i]['values']=depCodeList
self.depCodeSpinner[i].place(x=15,y=22*(i+1))
self.depCodeSpinner[i].bind('<<ComboboxSelected>>',self.depCodeSelectedHandler)
#Ders kodu sutunu
self.classCodeLabel = Label(self.frame,text='Ders Kodu')
self.classCodeLabel.place(x=95,y=3)
self.classCodeSpinner=[]
for i in range(0,10):
self.classCodeSpinner.append(Combobox(self.frame,width=10,state='readonly'))
self.classCodeSpinner[i]['values']=['']
self.classCodeSpinner[i].place(x=95,y=22*(i+1))
self.classCodeSpinner[i].bind('<<ComboboxSelected>>',self.classCodeSelectedHandler)
#Acilan dersler sutunu
self.availClassLabel = Label(self.frame,text='Acilan Dersler')
self.availClassLabel.place(x=205,y=3)
self.availClassSpinner=[]
for i in range(0,10):
self.availClassSpinner.append(Combobox(self.frame,width=75,state='readonly'))
self.availClassSpinner[i]['values']=['']
self.availClassSpinner[i].place(x=205,y=22*(i+1))
self.availClassSpinner[i].bind('<<ComboboxSelected>>',self.updateSchedule)
#Haftalik cizelge
self.weekChart = []
for i in range(0,14*5):
self.weekChart.append(Label(self.frame,anchor='center',background='white',width=10))
self.weekChart[i].place(x=(90+85*math.floor(i/14)), y=270+20*(i%14))
self.chartLabels=[]
days=['Pazartesi','Sali','Carsamba','Persembe','Cuma']
for i in range(0,5):
self.chartLabels.append(Label(self.frame,text=days[i],anchor='center',width=10))
self.chartLabels[i].place(x=90+i*85, y=250)
for i in range(0, 14):
self.chartLabels.append(Label(self.frame,text='{0}:30-{1}:29'.format(8+i,9+i),width=10,anchor='center'))
self.chartLabels[i+5].place(x=5, y=270+20*(i%14))
def reset(self):
for index in range(0,10):
self.depCodeSpinner[index].current(0)
self.classCodeSpinner[index]['values'] = ['']
self.availClassSpinner[index]['values'] = ['']
self.classCodeSpinner[index].current(0)
self.availClassSpinner[index].current(0)
self.updateSchedule(None,index)
def updateDatabase(self,firstBoot=False):
if firstBoot:
root = Tk()
root.withdraw()
tkMessageBox.showinfo('Veritabani guncellemesi','Veritabani simdi guncellenecek. Bu islem yaklasik 1-2 dakika surecektir.')
else:
ans= tkMessageBox.askquestion('Veritabani guncellemesi','Veritabanini simdi guncellemek istiyor musunuz?. Bu islem yaklasik 1-2 dakika surecektir.')
if ans=='no':
return
self.db.close()
updater = ITUSIS_Parser()
updater.getClasses()
self.conn=sqlite3.connect('classdb.sqlite')
self.db=self.conn.cursor()
if not firstBoot:
depCodeList=['']
for code in self.db.execute('select distinct Depcode from classes'):
depCodeList.append(code[0])
for i in range(0,10):
self.depCodeSpinner[i]['values']=depCodeList
def depCodeSelectedHandler(self,event,_index=None):
if _index != None:
index = _index
depCode = self.depCodeSpinner[index].get()
else:
index = int(event.widget.winfo_y()/22 -1)
depCode = event.widget.get()
if depCode == '':
self.classCodeSpinner[index]['values'] = ['']
self.availClassSpinner[index]['values'] = ['']
self.classCodeSpinner[index].current(0)
self.availClassSpinner[index].current(0)
if event != None:
self.updateSchedule(None,index)
return
self.db.execute('select distinct Code from classes where Depcode=\'%s\'' % depCode)
classCodeList = ['']
for elem in self.db.fetchall():
classCodeList.append(elem[0])
self.classCodeSpinner[index]['values'] = classCodeList
self.classCodeSpinner[index].current(0)
self.availClassSpinner[index]['values'] = ['']
self.availClassSpinner[index].current(0)
if event != None:
self.updateSchedule(None,index)
def classCodeSelectedHandler(self,event,_index=None):
if _index != None:
index = _index
classCode = self.classCodeSpinner[index].get()
else:
classCode = event.widget.get()
index = int(event.widget.winfo_y()/22 -1)
if classCode == '':
self.availClassSpinner[index]['values'] = ['']
self.availClassSpinner[index].current(0)
if event != None:
self.updateSchedule(None,index)
return
self.db.execute('select CRN , Title , Inst ,Build , Day ,Time from classes where Code=\'%s\'' % classCode)
availClassList =['']
for elem in self.db.fetchall():
availClassList.append('%s :: %s :: %s :: %s :: %s :: %s' % (elem[0],elem[1],elem[2],elem[4],elem[5],elem[3]))
self.availClassSpinner[index]['values'] = availClassList
self.availClassSpinner[index].current(0)
if event != None:
self.updateSchedule(None,index)
def updateSchedule(self,event,index=None):
temp = [0 for x in range(70)]
temp2 = [0 for x in range(70)]
for i in range(0,10):
data = self.availClassSpinner[i].get()
if data == '':
continue
CRN = data[:5]
self.db.execute(('select ClassTime from classes where CRN=\'%s\'' % CRN))
for block in self.db.fetchone()[0].split(','):
start_stop = block.split('-')
for j in range(int(start_stop[0]),int(start_stop[1])):
if temp[j] == 0:
temp[j] = rand_col[i]
temp2[j] = self.classCodeSpinner[i].get()
else:
if event != None:
event.widget.current(0)
else:
self.availClassSpinner[index].current(0)
self.updateSchedule(event,index)
tkMessageBox.showinfo('Hata','Sectiginiz ders baska bir dersinizle cakismaktadir!')
return
for i in range(0,70):
self.weekChart[i]['background']= 'white'
self.weekChart[i]['text']=''
if temp[i] != 0:
self.weekChart[i]['background']=temp[i]
self.weekChart[i]['text']= temp2[i]
def save(self):
fileName=tkFileDialog.asksaveasfilename(defaultextension='.ipsf',filetypes=[('Itu Programci Save File', '.ipsf')])
saveFile = open(fileName,'w')
list =[]
for i in range(0,10):
if self.availClassSpinner[i].get() != '':
list.append(self.availClassSpinner[i].get()[:5])
saveFile.write(','.join(list))
saveFile.close()
def load(self):
fileName=tkFileDialog.askopenfilename(defaultextension='.ipsf',filetypes=[('Itu Programci Save File', '.ipsf')])
saveFile = open(fileName,'r')
CrnList = saveFile.read().replace('\n','').split(',')
i=0
for CRN in CrnList:
self.db.execute('select Depcode,Code from classes where CRN=%s' % CRN)
query = self.db.fetchone()
self.depCodeSpinner[i].set(query[0])
self.depCodeSelectedHandler(None,i)
self.classCodeSpinner[i].set(query[1])
self.classCodeSelectedHandler(None,i)
for class_entry in self.availClassSpinner[i]['values']:
if class_entry[:5] == CRN:
self.availClassSpinner[i].set(class_entry)
break
i+=1
self.updateSchedule(None)
rand_col = ['#CE9090','#CE90CA','#B890CE','#9092CE','#90B9CE','#90CEB5','#90CE92','#C6CE90','#CEBC90','#919191']
programci = ITU_Programci()