-
Notifications
You must be signed in to change notification settings - Fork 0
/
ele_gui.py
408 lines (364 loc) · 19.6 KB
/
ele_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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.24.1
# in conjunction with Tcl version 8.6
import os
import sys
from PIL import Image, ImageTk
try:
import Tkinter as tk
import Tkinter.filedialog as filedialog
import Tkinter.messagebox as messagebox
except ImportError:
import tkinter as tk
import tkinter.filedialog as filedialog
import tkinter.messagebox as messagebox
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import ele_support
import ele_program
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
ele_support.set_Tk_var()
top = Toplevel(root)
ele_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel(root)
ele_support.set_Tk_var()
top = Toplevel(w)
ele_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel():
global w
w.destroy()
w = None
# unfortunately I need these as global...
# it's the only way so far to pass data for handling previews
program = None
canvas = None
preview = None
class Toplevel:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.configure('.',font="TkDefaultFont")
self.style.map('.',background=[('selected', _compcolor), ('active',_ana2color)])
top.geometry("970x500+180+100")
top.title("Extended Liftoff Editor")
top.configure(background="#d9d9d9")
top.configure(highlightbackground="#d9d9d9")
top.configure(highlightcolor="black")
top.protocol("WM_DELETE_WINDOW", onclose)
self.main_frame = tk.Frame(top)
self.main_frame.place(relx=0.01, rely=0.02, relheight=0.96, relwidth=0.98)
self.main_frame.configure(relief='groove')
self.main_frame.configure(borderwidth="2")
self.main_frame.configure(relief="groove")
self.main_frame.configure(background="#d9d9d9")
self.main_frame.configure(highlightbackground="#d9d9d9")
self.main_frame.configure(highlightcolor="black")
self.main_frame.configure(width=945)
self.blueprint_combo = ttk.Combobox(self.main_frame)
self.blueprint_combo.place(relx=0.042, rely=0.147, relheight=0.044, relwidth=0.247)
self.blueprint_combo.configure(textvariable=ele_support.combobox)
self.blueprint_combo.configure(takefocus="")
self.blueprint_combo.bind('<<ComboboxSelected>>', onselect)
self.blueprint_canvas = tk.Canvas(self.main_frame)
self.blueprint_canvas.place(relx=0.011, rely=0.211, relheight=0.427, relwidth=0.299)
self.blueprint_canvas.configure(background="#d9d9d9")
self.blueprint_canvas.configure(borderwidth="2")
self.blueprint_canvas.configure(highlightbackground="#d9d9d9")
self.blueprint_canvas.configure(highlightcolor="black")
self.blueprint_canvas.configure(insertbackground="black")
self.blueprint_canvas.configure(relief="ridge")
self.blueprint_canvas.configure(selectbackground="#c4c4c4")
self.blueprint_canvas.configure(selectforeground="black")
self.blueprint_canvas.configure(width=283)
self.x_label = tk.Label(self.main_frame)
self.x_label.place(relx=0.032, rely=0.695, height=21, width=54)
self.x_label.configure(activebackground="#f9f9f9")
self.x_label.configure(activeforeground="black")
self.x_label.configure(background="#d9d9d9")
self.x_label.configure(disabledforeground="#a3a3a3")
self.x_label.configure(foreground="#000000")
self.x_label.configure(highlightbackground="#d9d9d9")
self.x_label.configure(highlightcolor="black")
self.x_label.configure(text='''X''')
self.y_label = tk.Label(self.main_frame)
self.y_label.place(relx=0.032, rely=0.758, height=21, width=54)
self.y_label.configure(activebackground="#f9f9f9")
self.y_label.configure(activeforeground="black")
self.y_label.configure(background="#d9d9d9")
self.y_label.configure(disabledforeground="#a3a3a3")
self.y_label.configure(foreground="#000000")
self.y_label.configure(highlightbackground="#d9d9d9")
self.y_label.configure(highlightcolor="black")
self.y_label.configure(text='''Y''')
self.z_label = tk.Label(self.main_frame)
self.z_label.place(relx=0.032, rely=0.821, height=21, width=54)
self.z_label.configure(activebackground="#f9f9f9")
self.z_label.configure(activeforeground="black")
self.z_label.configure(background="#d9d9d9")
self.z_label.configure(disabledforeground="#a3a3a3")
self.z_label.configure(foreground="#000000")
self.z_label.configure(highlightbackground="#d9d9d9")
self.z_label.configure(highlightcolor="black")
self.z_label.configure(text='''Z''')
self.x_spin = tk.Spinbox(self.main_frame, from_=-1000, to=1000)
self.x_spin.place(relx=0.075, rely=0.695, relheight=0.04, relwidth=0.067)
self.x_spin.configure(activebackground="#f9f9f9")
self.x_spin.configure(background="white")
self.x_spin.configure(buttonbackground="#d9d9d9")
self.x_spin.configure(disabledforeground="#a3a3a3")
self.x_spin.configure(foreground="black")
self.x_spin.configure(highlightbackground="black")
self.x_spin.configure(highlightcolor="black")
self.x_spin.configure(insertbackground="black")
self.x_spin.configure(selectbackground="#c4c4c4")
self.x_spin.configure(selectforeground="black")
self.x_spin.configure(textvariable=tk.StringVar(root, '0'))
self.y_spin = tk.Spinbox(self.main_frame, from_=-1000, to=1000)
self.y_spin.place(relx=0.075, rely=0.758, relheight=0.04, relwidth=0.067)
self.y_spin.configure(activebackground="#f9f9f9")
self.y_spin.configure(background="white")
self.y_spin.configure(buttonbackground="#d9d9d9")
self.y_spin.configure(disabledforeground="#a3a3a3")
self.y_spin.configure(foreground="black")
self.y_spin.configure(highlightbackground="black")
self.y_spin.configure(highlightcolor="black")
self.y_spin.configure(insertbackground="black")
self.y_spin.configure(selectbackground="#c4c4c4")
self.y_spin.configure(selectforeground="black")
self.y_spin.configure(textvariable=tk.StringVar(root, '0'))
self.z_spin = tk.Spinbox(self.main_frame, from_=-1000, to=1000)
self.z_spin.place(relx=0.075, rely=0.821, relheight=0.04, relwidth=0.067)
self.z_spin.configure(activebackground="#f9f9f9")
self.z_spin.configure(background="white")
self.z_spin.configure(buttonbackground="#d9d9d9")
self.z_spin.configure(disabledforeground="#a3a3a3")
self.z_spin.configure(foreground="black")
self.z_spin.configure(highlightbackground="black")
self.z_spin.configure(highlightcolor="black")
self.z_spin.configure(insertbackground="black")
self.z_spin.configure(selectbackground="#c4c4c4")
self.z_spin.configure(selectforeground="black")
self.z_spin.configure(textvariable=tk.StringVar(root, '0'))
self.pitch_label = tk.Label(self.main_frame)
self.pitch_label.place(relx=0.148, rely=0.695, height=21, width=34)
self.pitch_label.configure(activebackground="#f9f9f9")
self.pitch_label.configure(activeforeground="black")
self.pitch_label.configure(background="#d9d9d9")
self.pitch_label.configure(disabledforeground="#a3a3a3")
self.pitch_label.configure(foreground="#000000")
self.pitch_label.configure(highlightbackground="#d9d9d9")
self.pitch_label.configure(highlightcolor="black")
self.pitch_label.configure(text='''Pitch''')
self.yaw_label = tk.Label(self.main_frame)
self.yaw_label.place(relx=0.148, rely=0.758, height=21, width=34)
self.yaw_label.configure(activebackground="#f9f9f9")
self.yaw_label.configure(activeforeground="black")
self.yaw_label.configure(background="#d9d9d9")
self.yaw_label.configure(disabledforeground="#a3a3a3")
self.yaw_label.configure(foreground="#000000")
self.yaw_label.configure(highlightbackground="#d9d9d9")
self.yaw_label.configure(highlightcolor="black")
self.yaw_label.configure(text='''Yaw''')
self.roll_label = tk.Label(self.main_frame)
self.roll_label.place(relx=0.148, rely=0.821, height=21, width=34)
self.roll_label.configure(activebackground="#f9f9f9")
self.roll_label.configure(activeforeground="black")
self.roll_label.configure(background="#d9d9d9")
self.roll_label.configure(disabledforeground="#a3a3a3")
self.roll_label.configure(foreground="#000000")
self.roll_label.configure(highlightbackground="#d9d9d9")
self.roll_label.configure(highlightcolor="black")
self.roll_label.configure(text='''Roll''')
self.pitch_spin = tk.Spinbox(self.main_frame, from_=0, to=360)
self.pitch_spin.place(relx=0.19, rely=0.695, relheight=0.04, relwidth=0.048)
self.pitch_spin.configure(activebackground="#f9f9f9")
self.pitch_spin.configure(background="white")
self.pitch_spin.configure(buttonbackground="#d9d9d9")
self.pitch_spin.configure(disabledforeground="#a3a3a3")
self.pitch_spin.configure(foreground="black")
self.pitch_spin.configure(highlightbackground="black")
self.pitch_spin.configure(highlightcolor="black")
self.pitch_spin.configure(insertbackground="black")
self.pitch_spin.configure(selectbackground="#c4c4c4")
self.pitch_spin.configure(selectforeground="black")
self.yaw_spin = tk.Spinbox(self.main_frame, from_=0, to=360)
self.yaw_spin.place(relx=0.19, rely=0.758, relheight=0.04, relwidth=0.048)
self.yaw_spin.configure(activebackground="#f9f9f9")
self.yaw_spin.configure(background="white")
self.yaw_spin.configure(buttonbackground="#d9d9d9")
self.yaw_spin.configure(disabledforeground="#a3a3a3")
self.yaw_spin.configure(foreground="black")
self.yaw_spin.configure(highlightbackground="black")
self.yaw_spin.configure(highlightcolor="black")
self.yaw_spin.configure(insertbackground="black")
self.yaw_spin.configure(selectbackground="#c4c4c4")
self.yaw_spin.configure(selectforeground="black")
self.roll_spin = tk.Spinbox(self.main_frame, from_=0, to=360)
self.roll_spin.place(relx=0.19, rely=0.821, relheight=0.04, relwidth=0.048)
self.roll_spin.configure(activebackground="#f9f9f9")
self.roll_spin.configure(background="white")
self.roll_spin.configure(buttonbackground="#d9d9d9")
self.roll_spin.configure(disabledforeground="#a3a3a3")
self.roll_spin.configure(foreground="black")
self.roll_spin.configure(highlightbackground="black")
self.roll_spin.configure(highlightcolor="black")
self.roll_spin.configure(insertbackground="black")
self.roll_spin.configure(selectbackground="#c4c4c4")
self.roll_spin.configure(selectforeground="black")
self.add_instance_button = tk.Button(self.main_frame)
self.add_instance_button.place(relx=0.085, rely=0.926, height=24, width=123)
self.add_instance_button.configure(activebackground="#ececec")
self.add_instance_button.configure(activeforeground="#000000")
self.add_instance_button.configure(background="#d9d9d9")
self.add_instance_button.configure(disabledforeground="#a3a3a3")
self.add_instance_button.configure(foreground="#000000")
self.add_instance_button.configure(highlightbackground="#d9d9d9")
self.add_instance_button.configure(highlightcolor="black")
self.add_instance_button.configure(pady="0")
self.add_instance_button.configure(text='''Add instance''')
self.add_instance_button.configure(command=self.add_instance_handler)
self.remove_instance_button = tk.Button(self.main_frame)
self.remove_instance_button.place(relx=0.603, rely=0.926, height=24, width=110)
self.remove_instance_button.configure(activebackground="#ececec")
self.remove_instance_button.configure(activeforeground="#000000")
self.remove_instance_button.configure(background="#d9d9d9")
self.remove_instance_button.configure(disabledforeground="#a3a3a3")
self.remove_instance_button.configure(foreground="#000000")
self.remove_instance_button.configure(highlightbackground="#d9d9d9")
self.remove_instance_button.configure(highlightcolor="black")
self.remove_instance_button.configure(pady="0")
self.remove_instance_button.configure(text='''Remove instance''')
self.remove_instance_button.configure(width=110)
self.remove_instance_button.configure(command=self.remove_instance_handler)
self.instance_list = tk.Listbox(self.main_frame)
self.instance_list.place(relx=0.328, rely=0.126, relheight=0.762, relwidth=0.66)
self.instance_list.configure(background="white")
self.instance_list.configure(disabledforeground="#a3a3a3")
self.instance_list.configure(font="TkFixedFont")
self.instance_list.configure(foreground="#000000")
self.instance_list.configure(highlightbackground="#d9d9d9")
self.instance_list.configure(highlightcolor="black")
self.instance_list.configure(selectbackground="#c4c4c4")
self.instance_list.configure(selectforeground="black")
self.instance_list.configure(width=624)
self.load_project_button = tk.Button(self.main_frame)
self.load_project_button.place(relx=0.021, rely=0.042, height=24, width=110)
self.load_project_button.configure(activebackground="#ececec")
self.load_project_button.configure(activeforeground="#000000")
self.load_project_button.configure(background="#d9d9d9")
self.load_project_button.configure(disabledforeground="#a3a3a3")
self.load_project_button.configure(foreground="#000000")
self.load_project_button.configure(highlightbackground="#d9d9d9")
self.load_project_button.configure(highlightcolor="black")
self.load_project_button.configure(pady="0")
self.load_project_button.configure(text='''Load project''')
self.load_project_button.configure(width=110)
self.load_project_button.configure(command=self.load_project_handler)
self.save_project_button = tk.Button(self.main_frame)
self.save_project_button.place(relx=0.18, rely=0.042, height=24, width=110)
self.save_project_button.configure(activebackground="#ececec")
self.save_project_button.configure(activeforeground="#000000")
self.save_project_button.configure(background="#d9d9d9")
self.save_project_button.configure(disabledforeground="#a3a3a3")
self.save_project_button.configure(foreground="#000000")
self.save_project_button.configure(highlightbackground="#d9d9d9")
self.save_project_button.configure(highlightcolor="black")
self.save_project_button.configure(pady="0")
self.save_project_button.configure(text='''Save project''')
self.save_project_button.configure(width=110)
self.save_project_button.configure(command=self.save_project_handler)
self.generate_xml_button = tk.Button(self.main_frame)
self.generate_xml_button.place(relx=0.328, rely=0.042, height=24, width=110)
self.generate_xml_button.configure(activebackground="#ececec")
self.generate_xml_button.configure(activeforeground="#000000")
self.generate_xml_button.configure(background="#d9d9d9")
self.generate_xml_button.configure(disabledforeground="#a3a3a3")
self.generate_xml_button.configure(foreground="#000000")
self.generate_xml_button.configure(highlightbackground="#d9d9d9")
self.generate_xml_button.configure(highlightcolor="black")
self.generate_xml_button.configure(pady="0")
self.generate_xml_button.configure(text='''Generate XML''')
self.generate_xml_button.configure(width=110)
self.generate_xml_button.configure(command=self.generate_xml_handler)
'''Initialize program'''
self.program = ele_program.Program()
self.blueprint_combo['values'] = self.program.init()
# assign global variables for handling previews
global program, canvas
program = self.program
canvas = self.blueprint_canvas
def add_instance_handler(self):
name = self.blueprint_combo.get()
x = float(self.x_spin.get())
y = float(self.y_spin.get())
z = float(self.z_spin.get())
pitch = float(self.pitch_spin.get())
yaw = float(self.yaw_spin.get())
roll = float(self.roll_spin.get())
new_instance = self.program.add_instance(name, x, y, z, pitch, yaw, roll)
self.instance_list.insert(tk.END, new_instance)
def remove_instance_handler(self):
index = self.instance_list.curselection()[0]
self.program.remove_instance(index)
self.instance_list.delete(tk.ACTIVE)
def load_project_handler(self):
file = filedialog.askopenfilename(initialdir=os.path.dirname(__file__), filetypes=(("Project files", "*.dat"), ("All files", "*.*")))
if file == "":
return
instances = self.program.load_project(file)
self.instance_list.delete(0, tk.END)
for instance in instances:
self.instance_list.insert(tk.END, instance)
def save_project_handler(self):
file = filedialog.asksaveasfile(initialdir=os.path.dirname(__file__), mode='w', defaultextension=".dat", filetypes=(("Project file", "*.dat"),))
if file is None:
return
self.program.save_project(file)
def generate_xml_handler(self):
file = filedialog.asksaveasfile(initialdir=os.path.dirname(__file__), mode='w', defaultextension=".xml", filetypes=(("XML file", "*.xml"),))
if file is None:
return
self.program.generate_xml(file)
# handler for canvas
def onselect(evt):
global preview
value = evt.widget.get()
canvas.delete("all")
try:
img = program.previews[value].resize((canvas.winfo_width(), canvas.winfo_height()), Image.ANTIALIAS)
preview = ImageTk.PhotoImage(img)
canvas.create_image(0, 0, image=preview, anchor=tk.NW)
except:
pass
# handler for quitting
def onclose():
if tk.messagebox.askokcancel("Quit", "Are you sure you want to quit?"):
root.destroy()
if __name__ == '__main__':
vp_start_gui()