-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
137 lines (126 loc) · 4.04 KB
/
__init__.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
#Main File
import gpxpy
import os
import sqlite3
from sqlite3 import Error
from tkinter import *
from createDB import *
from views import *
from controllers import *
from models import *
from tkinter import *
def init(data):
data.mode = "select"
data.unitW = data.width/20
data.unitH = data.height/20
data.newUser = ""
data.conn = create_connection("db/user.db")
data.path = "."
data.pageLength = 10
data.currentPage = 0
data.users = select_users(data.conn)
def mousePressed(event, data):
if data.mode == "select":
mouseSelect(event, data)
elif data.mode == "view":
mouseView(event, data)
elif data.mode == "login":
mouseLogin(event, data)
elif data.mode == "addGPX":
mouseAddGPX(event, data)
elif data.mode == "progress":
mouseProgress(event, data)
elif data.mode == "pickRide":
mouseRides(event, data)
elif data.mode == "pickRecommend":
mousePickRecommend(event, data)
elif data.mode == "create":
mouseCreate(event, data)
def keyPressed(event, data):
if data.mode == "create":
keyCreate(event, data)
elif data.mode == "addGPX":
keyAddGPX(event, data)
elif data.mode == "login":
keyLogin(event, data)
elif data.mode == "pickRide":
keyRides(event, data)
elif data.mode == "progress":
keyProgress(event, data)
elif data.mode == "plot":
keyPlot(event, data)
elif data.mode == "pickRecommend":
keyPickReccomend(event, data)
elif data.mode == "recommend":
keyReccomend(event, data)
elif data.mode == "viewSeg":
keyViewSeg(event, data)
elif data.mode == "view":
keyView(event, data)
def timerFired(data):
pass
def redrawAll(canvas, data):
if data.mode == "select":
selectScreen(canvas, data)
elif data.mode == "create":
createScreen(canvas, data)
elif data.mode == "login":
viewLogin(canvas, data)
elif data.mode == "view":
viewScreen(canvas, data)
elif data.mode == "addGPX":
viewAddGPX(canvas, data)
elif data.mode == "progress":
viewProgress(canvas, data)
elif data.mode == "pickRide":
viewRides(canvas, data)
elif data.mode == "plot":
plotPoints(canvas, data)
elif data.mode == "pickRecommend":
viewPickRecommend(canvas,data)
elif data.mode == "recommend":
viewRecommend(canvas, data)
elif data.mode == "viewSeg":
viewSections(canvas, data)
#Run function from tkinter notes
def run(width=300, height=300):
def redrawAllWrapper(canvas, data):
canvas.delete(ALL)
canvas.create_rectangle(0, 0, data.width, data.height,
fill='black', width=0)
redrawAll(canvas, data)
canvas.update()
def mousePressedWrapper(event, canvas, data):
mousePressed(event, data)
redrawAllWrapper(canvas, data)
def keyPressedWrapper(event, canvas, data):
keyPressed(event, data)
redrawAllWrapper(canvas, data)
def timerFiredWrapper(canvas, data):
timerFired(data)
redrawAllWrapper(canvas, data)
# pause, then call timerFired again
canvas.after(data.timerDelay, timerFiredWrapper, canvas, data)
# Set up data and call init
class Struct(object): pass
data = Struct()
data.width = width
data.height = height
data.timerDelay = 100 # milliseconds
root = Tk()
root.resizable(width=False, height=False) # prevents resizing window
init(data)
# create the root and the canvas
canvas = Canvas(root, width=data.width, height=data.height)
canvas.configure(bd=0, highlightthickness=0)
canvas.pack()
# set up events
root.bind("<Button-1>", lambda event:
mousePressedWrapper(event, canvas, data))
root.bind("<Key>", lambda event:
keyPressedWrapper(event, canvas, data))
timerFiredWrapper(canvas, data)
# and launch the app
root.mainloop() # blocks until window is closed
print("bye!")
run(1000, 750)