-
Notifications
You must be signed in to change notification settings - Fork 0
/
hack112finalproject.py
267 lines (228 loc) · 9.9 KB
/
hack112finalproject.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
from cmu_graphics import *
def onAppStart(app):
app.isAssignmentPage = True
app.tasks = []
app.color = 'red'
app.colorlist = []
app.colorListInInputSection = [rgb(255,0,0),rgb(0,112,60),rgb(14,76,146)]
app.dueDate = []
app.drawXList = []
app.completedTasks = []
app.showDates = [True, False, False, False, False]
app.classes = {'monday':[], 'tuesday':[], 'wednesday':[], 'thursday':[], 'friday':[]}
app.rows = 6
app.cols = 1
app.boardLeft = 0
app.boardTop = 0
app.boardWidth = app.width
app.boardHeight = 90.5*6
app.cellBorderWidth = 2
app.addtask = 'Click to add tasks here!'
def activateAssignments(app):
drawTaskSection(app)
drawInputSection(app)
def drawTaskSection(app):
drawBoard(app)
drawBoardBorder(app)
drawTask(app)
def drawInputSection(app):
drawLabel('Add tasks',0,550,align = 'left')
drawLine(0,557,550,557)
drawRect(290,557,100/3,43,fill = app.colorListInInputSection[0])
drawRect(323,557,100/3,43,fill = app.colorListInInputSection[1])
drawRect(356,557,100/3,43,fill = app.colorListInInputSection[2])
drawRect(290,557,100,43,fill = None, border = 'black')
drawLine(290+100/3,557,290+100/3,600)
drawLine(290+100*2/3,557,290+100*2/3,600)
drawLabel('CMURed',290+100/6,557+43/2,size = 7,bold = True)
drawLabel('DartGreen',290+100*3/6,557+43/2,size = 7,bold = True)
drawLabel('YaleBlue',290+100*5/6,557+43/2,size = 7,bold = True)
drawLabel(app.addtask,10,600-43/2,align = 'left')
drawRect(7,560,130,40,fill = None,border = 'black')
# Activates schedule page
def activateSchedule(app):
drawDates()
drawScheduler()
# Draws top button dates
def drawDates():
dates = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
drawRect(0, 0, 550, 50, fill=rgb(211,211,211))
for i in range(50, 456, 100):
drawRect(i, 25, 90, 30, fill=None, align='center', border=rgb(69, 115, 115), borderWidth=5)
centerX = 50
for day in dates:
drawLabel(day, centerX, 25, align='center')
centerX += 100
def drawScheduler():
drawLabel('+', 525, 25, align='center', size=20)
drawRect(525, 25, 30, 30, fill=None, border=rgb(69, 115, 115), borderWidth=5, align='center')
def scheduleInterface(app):
newClass = app.getTextInput("What class would you like to add?")
day = app.getTextInput("What day do you have that class? (only input one day)")
newStartTime = app.getTextInput("What time does that class start?")
newEndTime = app.getTextInput("What time does that class end?")
location = app.getTextInput("Where does your class take place?")
app.classes[day.lower()].append([newClass, newStartTime, newEndTime, location])
def onMousePress(app,mouseX,mouseY):
if clickingAssignmentPage(app,mouseX,mouseY,app.isAssignmentPage):
app.isAssignmentPage = True
if clickingSchedulePage(app,mouseX,mouseY,app.isAssignmentPage):
app.isAssignmentPage = False
if(app.isAssignmentPage):
if clickingAddTask(app,mouseX,mouseY):
app.tasks.append(app.getTextInput("Click to add tasks here!"))
app.dueDate.append(app.getTextInput("Put Due Date here!"))
if len(app.tasks) >= len(app.colorlist):
if clickingRed(app,mouseX,mouseY):
app.colorlist.append(app.colorListInInputSection[0])
if clickingGreen(app,mouseX,mouseY):
app.colorlist.append(app.colorListInInputSection[1])
if clickingBlue(app,mouseX,mouseY):
app.colorlist.append(app.colorListInInputSection[2])
clickingcheckbox(app,mouseX,mouseY)
elif(app.isAssignmentPage == False):
if clickingMonday(app,mouseX,mouseY):
app.showDates = [False]*5
app.showDates[0] = True
elif clickingTuesday(app,mouseX,mouseY):
app.showDates = [False]*5
app.showDates[1] = True
elif clickingWednesday(app,mouseX,mouseY):
app.showDates = [False]*5
app.showDates[2] = True
elif clickingThursday(app,mouseX,mouseY):
app.showDates = [False]*5
app.showDates[3] = True
elif clickingFriday(app,mouseX,mouseY):
app.showDates = [False]*5
app.showDates[4] = True
elif clickingPlus(app,mouseX,mouseY):
scheduleInterface(app)
def onKeyPress(app,key):
if(app.isAssignmentPage):
if key == 'down' or key == 'right':
length = len(app.tasks)
if length > 6:
app.tasks = app.tasks[6:] + app.tasks[:6]
app.dueDate = app.dueDate[6:] + app.dueDate[:6]
if key == 'up' or key == 'left':
length = len(app.tasks)
if length > 6:
app.tasks = app.tasks[-6:] + app.tasks[:-6]
app.dueDate = app.dueDate[-6:] + app.dueDate[:-6]
def clickingRed(app,mouseX,mouseY):
return buttonPress(mouseX,mouseY,290,557,323,600)
def clickingGreen(app,mouseX,mouseY):
return buttonPress(mouseX,mouseY,323,557,357,600)
def clickingBlue(app,mouseX,mouseY):
return buttonPress(mouseX,mouseY,357,557,389,600)
def clickingcheckbox(app,mouseX,mouseY):
for i in range(6):
if buttonPress(mouseX,mouseY,10,35+i*90.5,30,55+i*90.5):
if i not in app.completedTasks:
app.completedTasks.append(i)
print(app.drawXList)
else:
app.completedTasks.remove(i)
def drawTask(app):
halflength = 90.5/2
for i in range(len(app.tasks)):
drawLabel(app.tasks[i],40,90*i+halflength,align = 'left',fill = app.colorlist[i],size = 25,font = 'monospace')
drawLabel(app.dueDate[i],380,90*i+halflength,align = 'left',fill = app.colorlist[i],size = 25,font = 'monospace')
drawRect(10,90.5*i+halflength-10,20,20,fill = None,border = 'black')
if i == 5:
return
for i in range(len(app.completedTasks)):
drawLabel('X', 15, 45 + 90.5 * app.completedTasks[i],align = 'left' )
def clickingAddTask(app,mouseX,mouseY):
return buttonPress(mouseX, mouseY,7,560,137,600)
# cited from CMU CS academy
# the method to create a cell for our input section
def drawBoard(app):
for row in range(app.rows):
for col in range(app.cols):
drawCell(app, row, col)
def drawBoardBorder(app):
# draw the board outline (with double-thickness):
drawRect(app.boardLeft, app.boardTop, app.boardWidth, app.boardHeight,
fill=None, border='black',
borderWidth=2*app.cellBorderWidth)
def drawCell(app, row, col):
cellLeft, cellTop = getCellLeftTop(app, row, col)
cellWidth, cellHeight = getCellSize(app)
drawRect(cellLeft, cellTop, cellWidth, cellHeight,
fill=None, border='black',
borderWidth=app.cellBorderWidth)
def getCellLeftTop(app, row, col):
cellWidth, cellHeight = getCellSize(app)
cellLeft = app.boardLeft + col * cellWidth
cellTop = app.boardTop + row * cellHeight
return (cellLeft, cellTop)
def getCellSize(app):
cellWidth = app.boardWidth / app.cols
cellHeight = app.boardHeight / app.rows
return (cellWidth, cellHeight)
# return a boolean to check if the mouse is clicking on the button
def buttonPress(mouseX, mouseY,x1,y1,x2,y2):
if x1<= mouseX <=x2 and y1<= mouseY <=y2:
return True
return False
# return a boolean if we are clicking assignment page
def clickingAssignmentPage(app,mouseX,mouseY,isAssignmentPage):
if buttonPress(mouseX, mouseY,20,615,260,685):
return True
# return a boolean if we are clicking schedule page
def clickingSchedulePage(app,mouseX,mouseY,isAssignmentPage):
if buttonPress(mouseX, mouseY,290,615,530,685):
return True
### DAY FUNCTIONS ###
def clickingMonday(app, mouseX, mouseY):
if buttonPress(mouseX,mouseY,5,10,95,40):
return True
def clickingTuesday(app, mouseX, mouseY):
if buttonPress(mouseX,mouseY,105,10,195,40):
return True
def clickingWednesday(app,mouseX,mouseY):
if buttonPress(mouseX,mouseY,205,10,295,40):
return True
def clickingThursday(app,mouseX,mouseY):
if buttonPress(mouseX,mouseY,305,10,395,40):
return True
def clickingFriday(app,mouseX,mouseY):
if buttonPress(mouseX,mouseY,405,10,495,50):
return True
##########################
def clickingPlus(app,mouseX,mouseY):
if buttonPress(mouseX,mouseY,510,10,540,40):
return True
def redrawAll(app):
drawBottomButtons()
if(app.isAssignmentPage):
activateAssignments(app)
else:
activateSchedule(app)
dates = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
for i in range(len(app.showDates)):
currentBottom = -60
if(app.showDates[i]):
for lists in app.classes[dates[i]]:
currentBottom += 110
newClass = lists[0]
newStartTime = lists[1]
newEndTime = lists[2]
location = lists[3]
drawRect(10, currentBottom+10, 530, 100, fill=rgb(69, 115, 115))
drawLabel(newClass, 20, currentBottom+30, fill='white', size=25, align='left', bold=True)
drawLabel('TIME', 20, currentBottom+50, fill='white', align='left', opacity=70, size=10)
drawLabel(f'{newStartTime} to {newEndTime}', 20, currentBottom+65, size=15, align='left', fill='white')
drawLabel('LOCATION', 20, currentBottom+80, align='left', opacity=70, size=10, fill='white')
drawLabel(location, 20, currentBottom+95, align='left', size=15, fill='white')
def drawBottomButtons():
drawRect(0, 600, 550, 350, fill=rgb(211, 211, 211))
drawRect(20, 615, 240, 70, fill=rgb(205, 126, 89))
drawRect(290, 615, 240, 70, fill=rgb(69, 115, 115))
drawLabel('Assignments', 140, 650, fill='white', size=20)
drawLabel('Schedule', 410, 650, fill='white', size=20)
def main():
runApp(width=550, height=700)
main()