-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.py
204 lines (184 loc) · 6.73 KB
/
controllers.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
#Event controllers for tkinter
import string
from changeDB import *
from models import *
from image_util import *
def mouseSelect(event, data):
unitW = data.unitW
unitH = data.unitH
if unitW * 2 <= event.x <= unitW * 9 and unitH * 5 <= event.y <= unitH * 15:
data.mode = "create"
elif unitW * 11 <= event.x <= unitW * 18 and unitH * 5 <= event.y <= unitH * 15:
data.curUsers = retrieveUsers(data)
data.mode = "login"
def mouseLogin(event, data):
unitW = data.unitW
unitH = data.unitH
selected = int((event.y // (2*unitH)))
if selected <= len(data.curUsers) - 1:
data.id = data.curUsers[selected][0]
data.name = data.curUsers[selected][1]
data.mode = "view"
data.currentPage = 0
def mouseView(event, data):
unitW = data.unitW
unitH = data.unitH
if unitW * 7 <= event.x <= unitW * 13 and unitH * 18 <= event.y <= unitH * 20:
data.files = retrieveFiles(data)
data.mode = "addGPX"
elif unitW * 1 <= event.x <= unitW * 8 and unitH * 7 <= event.y <= unitH * 13:
retrieveGPXMiles(data)
data.mode = "progress"
elif unitW * 12 <= event.x <= unitW * 19 and unitH * 7 <= event.y <= unitH * 13:
data.curRides = retrieveRides(data)
data.mode = "pickRecommend"
def mouseAddGPX(event, data):
unitW = data.unitW
unitH = data.unitH
selected = int((event.y // (2*unitH)))
if selected <= len(data.files) - 1:
if "." not in data.files[selected]:
if data.path == ".":
data.path = data.files[selected] + "/"
else:
data.path += data.files[selected] + "/"
else:
addGPX(data, selected)
data.files = retrieveFiles(data)
def mouseProgress(event, data):
unitW = data.unitW
unitH = data.unitH
if unitW * 12 <= event.x <= unitW * 19 and unitH * 7 <= event.y <= unitH * 13:
data.curRides = retrieveRides(data)
data.mode = "pickRide"
data.viewSeg = False
elif unitW * 1 <= event.x <= unitW * 8 and unitH * 7 <= event.y <= unitH * 13:
data.curRides = retrieveRides(data)
data.mode = "pickRide"
data.viewSeg = True
def mouseRides(event, data):
unitW = data.unitW
unitH = data.unitH
selected = int((event.y // (2*unitH)))
if selected <= len(data.curRides) - 1:
data.plot = data.curRides[selected]
if data.viewSeg == False:
data.mode = "plot"
else:
data.mode = "viewSeg"
(_,_,gpxFile,_, min_lat, min_lon, max_lat, max_lon,_) = data.plot
data.sections = findSections(data.plot)
def mousePickRecommend(event, data):
unitW = data.unitW
unitH = data.unitH
selected = int((event.y // (2*unitH)))
if selected <= len(data.curRides) - 1:
data.picked = data.curRides[selected]
data.mode = "recommend"
data.trailType = 0
data.sections = findSections(data.picked)
data.colors = {0:"red", 1:"white", 2:"white"}
def mouseCreate(event, data):
unitW = data.unitW
unitH = data.unitH
if unitW * 7 <= event.x <= unitW * 13 and unitH * 18 <= event.y <= unitH * 20:
data.newUser = ""
data.mode = "select"
def keyCreate(event, data):
unitW = data.unitW
unitH = data.unitH
if event.keysym in string.ascii_uppercase or event.keysym in string.ascii_lowercase:
data.newUser += event.keysym
elif event.keysym == "BackSpace" and data.newUser != "":
data.newUser = data.newUser[:-1]
elif event.keysym == "Return" and data.newUser != '':
data.id = add_user(data.conn, data.newUser)
data.users = select_users(data.conn)
data.name = data.newUser
data.newUser = ""
data.mode = "view"
def keyAddGPX(event, data):
unitW = data.unitW
unitH = data.unitH
if event.keysym == "BackSpace":
data.mode = "view"
data.currentPage = 0
data.path = "."
elif event.keysym == "Left":
if data.currentPage > 0:
data.currentPage -= 1
data.files = retrieveFiles(data)
elif event.keysym == "Right":
if data.currentPage < data.totalPages:
data.currentPage += 1
data.files = retrieveFiles(data)
def keyLogin(event, data):
unitW = data.unitW
unitH = data.unitH
if event.keysym == "BackSpace":
data.mode = "select"
data.currentPage = 0
elif event.keysym == "Left":
if data.currentPage > 0:
data.currentPage -= 1
data.curUsers = retrieveUsers(data)
elif event.keysym == "Right":
if data.currentPage < data.totalPages:
data.currentPage += 1
data.curUsers = retrieveUsers(data)
def keyRides(event, data):
unitW = data.unitW
unitH = data.unitH
if event.keysym == "BackSpace":
data.mode = "progress"
data.currentPage = 0
elif event.keysym == "Left":
if data.currentPage > 0:
data.currentPage -= 1
data.curRides = retrieveRides(data)
elif event.keysym == "Right":
if data.currentPage < data.totalPages:
data.currentPage += 1
data.curRides = retrieveRides(data)
def keyPickReccomend(event, data):
unitW = data.unitW
unitH = data.unitH
if event.keysym == "BackSpace":
data.mode = "view"
data.currentPage = 0
elif event.keysym == "Left":
if data.currentPage > 0:
data.currentPage -= 1
data.curRides = retrieveRides(data)
elif event.keysym == "Right":
if data.currentPage < data.totalPages:
data.currentPage += 1
data.curRides = retrieveRides(data)
def keyProgress(event, data):
if event.keysym == "BackSpace":
data.mode = "view"
def keyPlot(event, data):
if event.keysym == "BackSpace":
data.mode = "pickRide"
def keyReccomend(event, data):
if event.keysym == "BackSpace":
data.mode = "pickRecommend"
elif event.keysym == "Left":
if data.trailType > 0:
data.colors[data.trailType] = "white"
data.trailType -= 1
data.colors[data.trailType] = "red"
elif event.keysym == "Right":
if data.trailType < 2:
data.colors[data.trailType] = "white"
data.trailType += 1
data.colors[data.trailType] = "red"
def keyViewSeg(event, data):
if event.keysym == "BackSpace":
data.mode = "pickRide"
def keyView(event, data):
if event.keysym == "BackSpace":
data.mode = "select"
data.id = 0
data.name = ""
data.newUser = ""