-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
219 lines (173 loc) · 6.67 KB
/
gui.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
import tkinter as tk
from tkinter import filedialog, PhotoImage, StringVar
from system_hotkey import SystemHotkey
from pathlib import Path
import config
import track_mouse
import draw_pixels
class MainWindow:
def __init__(self, parent):
self.config = config.Config()
print(self.config.save_folder)
self.mt = track_mouse.MouseTracker("")
# Key bindings
self.hk = SystemHotkey()
self.hk.register(self.config.start_tracking_binding,
callback=self.start_tracking)
self.hk.register(self.config.pause_tracking_binding,
callback=self.pause_tracking)
self.is_tracking = False
self.parent = parent
parent.title("SMT")
parent.resizable(False, False)
self.icon = PhotoImage(file=Path(__file__).parent / "icon.png")
parent.tk.call('wm', 'iconphoto', parent._w, self.icon)
self.screen_size = (parent.winfo_screenwidth(),
parent.winfo_screenheight())
self.status_lbl = tk.Label(parent,
text="● Stopped",
fg="red",
bg="#d9d9d9",
relief=tk.SUNKEN)
self.status_lbl.pack(side=(tk.BOTTOM), fill=tk.X)
self.selected_file = StringVar()
self.selected_file.set("Select file...")
self.track_btn = tk.Button(parent,
text="Start tracking",
command=self.start_tracking,
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF",
width=10)
self.track_btn.grid_propagate(False)
self.track_btn.pack(fill=tk.X)
self.pause_btn = tk.Button(parent,
text="Pause",
command=self.pause_tracking,
state="disabled",
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF",
width=10)
self.pause_btn.pack(fill=tk.X)
self.draw_btn = tk.Button(parent,
text="Export/Show",
command=self.draw_stuff,
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF")
self.draw_btn.pack(fill=tk.X)
self.quit_btn = tk.Button(parent,
text="Quit",
command=self.quit,
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF")
self.quit_btn.pack(fill=tk.X)
def start_tracking(self, event=""):
if not self.is_tracking:
self.is_tracking = True
self.status_lbl.configure(text="● Tracking", fg="green")
self.track_btn.configure(text="Stop tracking")
self.pause_btn.configure(state="normal")
self.mt = track_mouse.MouseTracker(self.config.save_folder)
self.mt.thread.start()
else:
self.is_tracking = False
self.status_lbl.configure(text="● Stopped", fg="red")
self.track_btn.configure(text="Start tracking")
self.pause_btn.configure(state="disabled")
self.mt.terminate()
self.mt.thread.join()
def pause_tracking(self, event=""):
if self.is_tracking:
if not self.mt.paused:
self.mt.paused = True
self.status_lbl.configure(text="● Paused", fg="blue")
self.pause_btn.configure(text="Resume")
else:
self.mt.paused = False
self.pause_btn.configure(state="normal", text="Pause")
if not self.mt.is_last_paused:
self.mt.sf.write("paused\n")
self.mt.is_last_paused = True
self.status_lbl.configure(text="● Tracking", fg="green")
def export_png(self):
draw_pixels.draw(
self.selected_file.get(),
self.screen_size,
self.config.colored_speed,
self.config.default_color,
True)
def show_tracked(self):
draw_pixels.draw(
self.selected_file.get(),
self.screen_size,
self.config.colored_speed,
self.config.default_color,
False)
def select_file(self):
file_path = filedialog.askopenfilename(
initialdir = self.config.save_folder,
title = "Select file",
filetypes = (("Tracked","*.tracked"),))
if file_path:
self.selected_file.set(file_path)
def show_popup(self):
popup = tk.Toplevel(self.parent)
popup.title("Export/Show")
popup.tk.call('wm', 'iconphoto', popup._w, self.icon)
x = self.parent.winfo_x()
y = self.parent.winfo_y()
popup.geometry("+"+str(x-80)+"+"+str(y))
popup.resizable(False, False)
popup_input = tk.Entry(popup, textvariable=self.selected_file)
popup_select_btn = tk.Button(popup,
text="Select file",
command=self.select_file,
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF")
popup_export_btn = tk.Button(popup,
text="Export png",
command=self.export_png,
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF")
popup_show_tracked_btn = tk.Button(popup,
text="Show tracked",
command=self.show_tracked,
bg="#0097A7",
fg="#FFFFFF",
relief=tk.FLAT,
activebackground="#0087A7",
activeforeground="#FFFFFF")
popup_input.grid(row=0, column=0, sticky="news")
popup_select_btn.grid(row=0, column=1, sticky="ew")
popup_export_btn.grid(row=1, column=0, sticky="ew")
popup_show_tracked_btn.grid(row=1, column=1, sticky="ew")
popup.grab_set()
def draw_stuff(self):
self.show_popup()
def quit(self):
if self.is_tracking:
self.is_tracking = False
self.mt.terminate()
self.mt.thread.join()
self.parent.quit()
if __name__ == '__main__':
root = tk.Tk()
main_window = MainWindow(root)
root.mainloop()