-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
215 lines (183 loc) · 5.51 KB
/
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
from tkinter import *
from tkinter import messagebox
import traceback
import accesstoken as init
import course_reset as rst_module
from canvasapi import Canvas
from tkinter import Canvas as ui
# Create the base window for the GUI
window = Tk()
window.title("Canvas Course Reset")
window.geometry("400x570")
window.configure(bg = "#6829C2")
# Create the graphical user interface
interface = ui(window,
bg = "#6829C2",
height = 600,
width = 400,
bd = 0,
highlightthickness = 0,
relief = "ridge")
interface.place(x = 0, y = 0)
# Create white box
interface.create_rectangle(
0.0,
275,
400,
570,
fill="#FFFFFF",
outline="")
# Add Reset Graphic
rst_icon = PhotoImage(
file=rst_module.relative_to_assets("refresh_img.png"))
rst_icon_img = interface.create_image(
200.0,
149.0,
image=rst_icon
)
# Add text
interface.create_text(
200,
307.0,
justify = "center",
text="Canvas Access Token",
fill="#623593",
font=("Arial", 18 * -1)
)
# Create the background for the prompts
entry_img = PhotoImage(
file=rst_module.relative_to_assets("entrybox.png"))
token_entry_bg = interface.create_image(
201.0,
346.27464294433594,
image=entry_img
)
# Create a Access Token Field
token_entry = Entry(
bd=0,
highlightthickness=0,
show="*"
)
token_entry.place(
x=85.77464294433594,
y=329.0,
width=230.45071411132812,
height=33.0
)
# Display Access token if it exists in accesstoken.py
token_entry.insert(0, init.access_token)
"""
Function that controls the Show Token checkbox
"""
def toggle():
global token_entry, showPW
if showPW.var.get():
token_entry.config(show = "*")
else:
token_entry.config(show = "")
# Create Show Token checkbox
showPW = Checkbutton(window, text="Show Token", bg="#FFFFFF", onvalue=False, offvalue=True, command=toggle)
showPW.var = BooleanVar(value=True)
showPW['variable'] = showPW.var
showPW.place(
x=145.75,
y=373.0,
width=108.5,
height=27
)
interface.create_text(
200,
420.0,
justify = "center",
text="Course ID",
fill="#623593",
font=("Arial", 18 * -1)
)
courseID_entry_bg = interface.create_image(
200.0,
458.27464294433594,
image=entry_img
)
courseID_entry = Entry(
bd=0,
highlightthickness=0
)
courseID_entry.place(
x=84.77464294433594,
y=443.0,
width=230.45071411132812,
height=33.0
)
"""
Function that confirms that the correct course ID
and access token was provided
"""
def confirmation_window():
try:
global window
# Record course_ids
init.course_id = courseID_entry.get()
# If access token is not added in the init.py file, retrieve it from Window prompt
if token_entry.get():
init.access_token = token_entry.get()
API_URL = init.base_url
API_KEY = init.access_token
# Get Canvas course information
canvas = Canvas(API_URL, API_KEY)
course = canvas.get_course(init.course_id)
global short_course_name
short_course_name = course.id
global course_name
course_name = course.name
global course_code
course_code = course.course_code
except Exception as e:
# remove the hashtag below to see where the error occurs
# traceback.print_exc()
print('The Course ID or Access Token is incorrect.\n If any problem still persists, restart the program, and try again.')
messagebox.showinfo("Error","The Course ID, Access Token, or base URL is incorrect.",icon="error")
# Display confirmation window
delete_confirmation = messagebox.askquestion(
"Delete All Content",
"Course Name: %s \nCourse Code: %s \nPlease note that the course you chose is currently %s to students\n\nAre you sure you want to delete ALL course content for this course?"
%(course_name, course_code, course.workflow_state),
icon='warning')
try:
if delete_confirmation == 'yes':
# Delete previous window
window.destroy()
# Delete the course contents
rst_module.delete_course()
except Exception as e:
# Remove the hashtag below to see where the error occurs
# traceback.print_exc()
print('Unable to proceed with course reset.\n If any problem still persists, restart the program, delete the deets file, and try again.')
messagebox.showinfo("Error","Course Reset Unsuccessful.",icon="error")
"""
Function that changes the style of the button when the cursor is over it
"""
def on_enter(e):
submit_btn.config(image = submit_btn_img_hover)
def on_leave(e):
submit_btn.config(image = submit_btn_img)
# Create a "Submit" Button
submit_btn_img = PhotoImage(
file=rst_module.relative_to_assets("submit_btn.png"))
submit_btn_img_hover = PhotoImage(
file=rst_module.relative_to_assets("submit_btn_hover.png"))
submit_btn = Button(
image=submit_btn_img,
borderwidth=0,
highlightthickness=0,
command=confirmation_window
)
submit_btn.place(
x=109.84,
y=497.36,
width=180.32,
height=42.04
)
submit_btn.bind('<Enter>', on_enter)
submit_btn.bind('<Leave>', on_leave)
window.resizable(False, False)
window.mainloop()