blob: 86dd0012f2dfa3c09a2f917b6caf47965761edc4 [file] [log] [blame]
John Park91e69732019-03-03 13:12:43 -08001#!/usr/bin/python3
2import gi
3from path_edit import *
4import numpy as np
5gi.require_version('Gtk', '3.0')
6from gi.repository import Gdk, Gtk, GLib
7import cairo
vlad56329f42020-06-12 21:41:08 -07008import basic_window
John Park91e69732019-03-03 13:12:43 -08009
Ravago Jones26f7ad02021-02-05 15:45:59 -080010
John Park91e69732019-03-03 13:12:43 -080011class GridWindow(Gtk.Window):
12 def method_connect(self, event, cb):
13 def handler(obj, *args):
14 cb(*args)
15
John Park91e69732019-03-03 13:12:43 -080016 self.connect(event, handler)
17
18 def mouse_move(self, event):
James Kuszmaulb2b89b22020-02-29 13:27:05 -080019 # Changes event.x and event.y to be relative to the center.
John Park91e69732019-03-03 13:12:43 -080020 x = event.x - self.drawing_area.window_shape[0] / 2
21 y = self.drawing_area.window_shape[1] / 2 - event.y
22 scale = self.drawing_area.get_current_scale()
23 event.x = x / scale + self.drawing_area.center[0]
24 event.y = y / scale + self.drawing_area.center[1]
25 self.drawing_area.mouse_move(event)
26 self.queue_draw()
27
28 def button_press(self, event):
James Kuszmaulb2b89b22020-02-29 13:27:05 -080029 original_x = event.x
30 original_y = event.y
John Park91e69732019-03-03 13:12:43 -080031 x = event.x - self.drawing_area.window_shape[0] / 2
32 y = self.drawing_area.window_shape[1] / 2 - event.y
33 scale = 2 * self.drawing_area.get_current_scale()
34 event.x = x / scale + self.drawing_area.center[0]
35 event.y = y / scale + self.drawing_area.center[1]
36 self.drawing_area.do_button_press(event)
James Kuszmaulb2b89b22020-02-29 13:27:05 -080037 event.x = original_x
38 event.y = original_y
John Park91e69732019-03-03 13:12:43 -080039
40 def key_press(self, event):
John Park91e69732019-03-03 13:12:43 -080041 self.drawing_area.do_key_press(event, self.file_name_box.get_text())
42 self.queue_draw()
43
44 def configure(self, event):
John Park91e69732019-03-03 13:12:43 -080045 self.drawing_area.window_shape = (event.width, event.height)
46
John Park909c0392020-03-05 23:56:30 -080047 def output_json_clicked(self, button):
48 print("OUTPUT JSON CLICKED")
49 self.drawing_area.export_json(self.file_name_box.get_text())
50
51 def input_json_clicked(self, button):
52 print("INPUT JSON CLICKED")
53 self.drawing_area.import_json(self.file_name_box.get_text())
John Park91e69732019-03-03 13:12:43 -080054
kyle0e5a9f32021-01-23 15:02:19 -080055 def long_changed(self, button):
56 print("LONGITUDAL VELOCITY CHANGED")
57
58 def lat_changed(self, button):
59 print("LATITUDAL VELOCITY CHANGED")
60
61 def accel_changed(self, button):
62 print("ACCELERATION CHANGED")
63
64 def vol_changed(self, button):
65 print("VOLTAGE CHANGED")
66
John Park91e69732019-03-03 13:12:43 -080067 def __init__(self):
68 Gtk.Window.__init__(self)
69
70 self.set_default_size(1.5 * SCREEN_SIZE, SCREEN_SIZE)
71
72 flowBox = Gtk.FlowBox()
73 flowBox.set_valign(Gtk.Align.START)
74 flowBox.set_selection_mode(Gtk.SelectionMode.NONE)
75
76 flowBox.set_valign(Gtk.Align.START)
77
78 self.add(flowBox)
79
80 container = Gtk.Fixed()
81 flowBox.add(container)
82
83 self.eventBox = Gtk.EventBox()
84 container.add(self.eventBox)
85
86 self.eventBox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK
87 | Gdk.EventMask.BUTTON_RELEASE_MASK
88 | Gdk.EventMask.POINTER_MOTION_MASK
89 | Gdk.EventMask.SCROLL_MASK
90 | Gdk.EventMask.KEY_PRESS_MASK)
91
92 #add the graph box
93 self.drawing_area = GTK_Widget()
94 self.eventBox.add(self.drawing_area)
95
vlad56329f42020-06-12 21:41:08 -070096 self.method_connect("delete-event", basic_window.quit_main_loop)
John Park91e69732019-03-03 13:12:43 -080097 self.method_connect("key-release-event", self.key_press)
98 self.method_connect("button-release-event", self.button_press)
99 self.method_connect("configure-event", self.configure)
100 self.method_connect("motion_notify_event", self.mouse_move)
101
102 self.file_name_box = Gtk.Entry()
103 self.file_name_box.set_size_request(200, 40)
104
James Kuszmaulb2b89b22020-02-29 13:27:05 -0800105 self.file_name_box.set_text("output_file_name.json")
John Park91e69732019-03-03 13:12:43 -0800106 self.file_name_box.set_editable(True)
107
108 container.put(self.file_name_box, 0, 0)
109
kyle0e5a9f32021-01-23 15:02:19 -0800110 self.long_input = Gtk.SpinButton()
111 self.long_input.set_size_request(100, 20)
112 self.long_input.set_numeric(True)
113 self.long_input.set_range(-100, 100)
114 self.long_input.connect("value-changed", self.long_changed)
115 self.long_label = Gtk.Label()
116 self.long_label.set_text("Longitudal Velocity Restriction")
117
118 self.lat_input = Gtk.SpinButton()
119 self.lat_input.set_size_request(100, 20)
120 self.lat_input.set_numeric(True)
121 self.lat_input.set_range(-100, 100)
122 self.lat_input.connect("value-changed", self.lat_changed)
123 self.lat_label = Gtk.Label()
124 self.lat_label.set_text("Latitudal Velocity Restriction")
125
126 self.accel_input = Gtk.SpinButton()
127 self.accel_input.set_size_request(100, 20)
128 self.accel_input.set_numeric(True)
129 self.accel_input.set_range(-100, 100)
130 self.accel_input.connect("value-changed", self.accel_changed)
131
132 self.accel_label = Gtk.Label()
133 self.accel_label.set_text("Acceleration Restriction")
134
135 self.vol_input = Gtk.SpinButton()
136 self.vol_input.set_size_request(100, 20)
137 self.vol_input.set_numeric(True)
138 self.vol_input.set_range(-12, 12)
139 self.vol_input.connect("value-changed", self.vol_changed)
140
141 self.vol_label = Gtk.Label()
142 self.vol_label.set_text("Voltage Restriction")
143
144 container.put(self.long_input, 0, 60)
145 container.put(self.lat_input, 0, 110)
146 container.put(self.accel_input, 0, 160)
147 container.put(self.vol_input, 0, 210)
148 container.put(self.long_label, 0, 40)
149 container.put(self.lat_label, 0, 90)
150 container.put(self.accel_label, 0, 140)
151 container.put(self.vol_label, 0, 190)
152
John Park909c0392020-03-05 23:56:30 -0800153 self.output_json = Gtk.Button.new_with_label("Output")
154 self.output_json.set_size_request(100, 40)
155 self.output_json.connect("clicked", self.output_json_clicked)
156
157 self.input_json = Gtk.Button.new_with_label("Import")
158 self.input_json.set_size_request(100, 40)
159 self.input_json.connect("clicked", self.input_json_clicked)
160
161 container.put(self.output_json, 210, 0)
162 container.put(self.input_json, 320, 0)
163
John Park91e69732019-03-03 13:12:43 -0800164 self.show_all()
165
166
167window = GridWindow()
168RunApp()