feat: courseTable接上GUI,修改部份錯誤
This commit is contained in:
parent
689ac1eb95
commit
f7d5fa801c
@ -95,7 +95,10 @@ class CourseTable():
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def conflict(self, course):
|
def conflict(self, course):
|
||||||
timeList = getTime(course['time'])
|
if course['time'] != None:
|
||||||
|
timeList = getTime(course['time'])
|
||||||
|
else:
|
||||||
|
return False
|
||||||
status = True
|
status = True
|
||||||
for time in timeList:
|
for time in timeList:
|
||||||
if time in self.table:
|
if time in self.table:
|
||||||
@ -107,28 +110,10 @@ class CourseTable():
|
|||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
def filter(self, department):
|
def courseFilter(self, department):
|
||||||
ans = []
|
ans = []
|
||||||
for course in self.courseData:
|
for course in self.courseData:
|
||||||
if course['department'] == department:
|
if course['department'] == department:
|
||||||
if self.conflict(course):
|
if self.conflict(course):
|
||||||
ans.append(course)
|
ans.append(course)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
table = CourseTable()
|
|
||||||
table.showTableStatus()
|
|
||||||
print( table.add('240034') )
|
|
||||||
table.showTableStatus()
|
|
||||||
print( table.add('240057') )
|
|
||||||
table.showTableStatus()
|
|
||||||
print( table.add('240034') )
|
|
||||||
table.showTableStatus()
|
|
||||||
print( table.add('902048') )
|
|
||||||
table.showTableStatus()
|
|
||||||
|
|
||||||
departments = table.getDepartmentList()
|
|
||||||
print(departments)
|
|
||||||
|
|
||||||
courses = table.filter('21, 資工系')
|
|
||||||
for course in courses:
|
|
||||||
print(course)
|
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
|
from api.courseTable.courseTable import *
|
||||||
|
|
||||||
url = 'https://raw.githubusercontent.com/snsd0805/NCNU_Course/master/%E6%AD%B7%E5%B9%B4%E8%AA%B2%E7%A8%8B%E8%B3%87%E6%96%99/1092_output.json'
|
url = 'https://raw.githubusercontent.com/snsd0805/NCNU_Course/master/%E6%AD%B7%E5%B9%B4%E8%AA%B2%E7%A8%8B%E8%B3%87%E6%96%99/1092_output.json'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
@ -8,21 +9,56 @@ response = requests.get(url)
|
|||||||
data = json.loads(response.text)
|
data = json.loads(response.text)
|
||||||
|
|
||||||
class Choose():
|
class Choose():
|
||||||
def __init__(self,root,name):
|
def __init__(self,root,name,typeS):
|
||||||
self.frame=Frame(root)
|
self.frame=Frame(root)
|
||||||
self.classname = Label(self.frame, font="10", width="10", text=name)
|
self.classname = Label(self.frame, font="10", width="10", text=name)
|
||||||
self.listbox = Listbox(self.frame)
|
self.listbox = Listbox(self.frame)
|
||||||
self.scrollbar=Scrollbar(self.frame)
|
self.scrollbar=Scrollbar(self.frame)
|
||||||
|
self.checkBtn = Button(self.frame, text="選取")
|
||||||
|
self.checkBtn.config(
|
||||||
|
command=lambda: self.setDepartment() if self.type=="department" else self.setCourse()
|
||||||
|
)
|
||||||
|
self.type = typeS
|
||||||
|
|
||||||
|
def setDepartment(self):
|
||||||
|
# print("set department")
|
||||||
|
# print(self.listbox.get(ACTIVE))
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def setCourse(self):
|
||||||
|
# print("set course")
|
||||||
|
# print(self.listbox.get(ACTIVE).split(' ')[0])
|
||||||
|
courseTable.add(
|
||||||
|
self.listbox.get(ACTIVE).split(' ')[0]
|
||||||
|
)
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
courses = courseTable.courseFilter(box[0].listbox.get(ACTIVE))
|
||||||
|
courses = ["{} {}({})".format(course['number'], course['name'], course['time']) for course in courses]
|
||||||
|
box[1].listbox.delete(0, END)
|
||||||
|
box[1].insert(courses)
|
||||||
|
|
||||||
|
# update table draw
|
||||||
|
for j in range(5):
|
||||||
|
for i in range(13):
|
||||||
|
if courseTable.table[str(j+1) + tmp[i]] != None:
|
||||||
|
table[18 + (13*j+i)].classname.config(text=
|
||||||
|
courseTable.table[str(j+1) + tmp[i]]['name']
|
||||||
|
)
|
||||||
|
table[18 + (13*j+i)].removeBtn.grid()
|
||||||
|
|
||||||
def insert(self,LIST):
|
def insert(self,LIST):
|
||||||
self.listbox.insert(END,*LIST)
|
self.listbox.insert(END,*LIST)
|
||||||
|
|
||||||
def grid(self,Row,Column,span):
|
def grid(self,Row,Column,span):
|
||||||
|
self.listbox.selection_set(15)
|
||||||
self.frame.grid(row=Row,column=Column,rowspan=span,padx=10,sticky="n"+"s")
|
self.frame.grid(row=Row,column=Column,rowspan=span,padx=10,sticky="n"+"s")
|
||||||
self.classname.pack()
|
self.classname.pack()
|
||||||
self.scrollbar.pack(fill=Y,side=RIGHT)
|
self.scrollbar.pack(fill=Y,side=RIGHT)
|
||||||
self.listbox.pack()
|
self.listbox.pack()
|
||||||
self.listbox.config(yscrollcommand=self.scrollbar.set)
|
self.listbox.config(yscrollcommand=self.scrollbar.set)
|
||||||
|
self.checkBtn.pack()
|
||||||
|
|
||||||
class Space():
|
class Space():
|
||||||
def __init__(self, root, name=None):
|
def __init__(self, root, name=None):
|
||||||
@ -31,28 +67,33 @@ class Space():
|
|||||||
self.removeBtn = Button(self.frame, font="10", text="刪")
|
self.removeBtn = Button(self.frame, font="10", text="刪")
|
||||||
self.classname.config(relief=RIDGE)
|
self.classname.config(relief=RIDGE)
|
||||||
|
|
||||||
def pack(self):
|
|
||||||
self.classname.pack()
|
|
||||||
self.removeBtn.pack_forget()
|
|
||||||
self.frame.pack()
|
|
||||||
|
|
||||||
def grid(self,Row,Column):
|
def grid(self,Row,Column):
|
||||||
if Row==5:
|
if Row==5:
|
||||||
self.classname.config(bg="green")
|
self.classname.config(bg="green")
|
||||||
self.frame.grid(row=Row,column=Column,padx=20)
|
self.frame.grid(row=Row,column=Column,padx=20)
|
||||||
self.classname.grid(row=0,column=0)
|
self.classname.grid(row=0,column=0)
|
||||||
self.removeBtn.grid(row=0,column=1)
|
self.removeBtn.grid(row=0,column=1)
|
||||||
|
self.removeBtn.grid_forget()
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.geometry('800x600')
|
root.geometry('800x600')
|
||||||
|
|
||||||
|
courseTable = CourseTable()
|
||||||
|
|
||||||
box=[]
|
box=[]
|
||||||
box.append(Choose(root,name="科系"))
|
box.append(Choose(root,name="科系",typeS='department'))
|
||||||
box[0].insert(["a","b","c"])
|
departments = courseTable.getDepartmentList()
|
||||||
|
box[0].insert(departments)
|
||||||
|
box[0].listbox.select_set(0)
|
||||||
box[0].grid(0,0,5)
|
box[0].grid(0,0,5)
|
||||||
|
|
||||||
box.append(Choose(root,name="課程"))
|
box.append(Choose(root,name="課程",typeS='courses'))
|
||||||
|
courses = courseTable.courseFilter("21, 資工系")
|
||||||
|
|
||||||
|
box[1].insert(["{} {}({})".format(course['number'], course['name'], course['time']) for course in courses])
|
||||||
box[1].grid(5,0,5)
|
box[1].grid(5,0,5)
|
||||||
|
|
||||||
|
|
||||||
table = []
|
table = []
|
||||||
k=0
|
k=0
|
||||||
|
|
||||||
@ -71,12 +112,13 @@ for i in range(13):
|
|||||||
|
|
||||||
table[9].config(bg="green")
|
table[9].config(bg="green")
|
||||||
|
|
||||||
|
# 18~
|
||||||
for j in range(5):
|
for j in range(5):
|
||||||
for i in range(13):
|
for i in range(13):
|
||||||
table.append(Space(root, name=i))
|
table.append(Space(root))
|
||||||
table[k].grid(i+1,j+3)
|
table[k].grid(i+1,j+3)
|
||||||
k+=1
|
k+=1
|
||||||
|
print(len(table))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user