blob: fad635f4d40d50e2877085938199ec876c60a2e0 [file] [log] [blame]
John Park91e69732019-03-03 13:12:43 -08001#!/usr/bin/python3
Ravago Jones6d460fe2021-07-03 16:59:55 -07002
3# matplotlib overrides fontconfig locations, so has to be imported before gtk
4import matplotlib
John Park91e69732019-03-03 13:12:43 -08005import gi
Ravago Jones6d460fe2021-07-03 16:59:55 -07006from path_edit import FieldWidget
7from basic_window import RunApp
8from constants import FIELDS, FIELD, SCREEN_SIZE
John Park91e69732019-03-03 13:12:43 -08009gi.require_version('Gtk', '3.0')
10from gi.repository import Gdk, Gtk, GLib
11import cairo
vlad56329f42020-06-12 21:41:08 -070012import basic_window
Ravago Jones6d460fe2021-07-03 16:59:55 -070013import os
Ravago Jones26f7ad02021-02-05 15:45:59 -080014
Ravago Jones36c92f02021-07-24 16:35:33 -070015
John Park91e69732019-03-03 13:12:43 -080016class GridWindow(Gtk.Window):
17 def method_connect(self, event, cb):
18 def handler(obj, *args):
19 cb(*args)
20
John Park91e69732019-03-03 13:12:43 -080021 self.connect(event, handler)
22
Ryan Yin85f861f2021-09-16 17:55:11 -070023 def clear_clicked(self, button):
Ravago Jonesfa8da562022-07-02 18:10:22 -070024 self.field.clear()
Ryan Yin85f861f2021-09-16 17:55:11 -070025
John Park909c0392020-03-05 23:56:30 -080026 def output_json_clicked(self, button):
Ravago Jones6d460fe2021-07-03 16:59:55 -070027 self.field.export_json(self.file_name_box.get_text())
John Park909c0392020-03-05 23:56:30 -080028
29 def input_json_clicked(self, button):
Ravago Jones6d460fe2021-07-03 16:59:55 -070030 self.field.import_json(self.file_name_box.get_text())
kyle96e46e12021-02-10 21:47:55 -080031 self.long_input.set_value(
Ravago Jonesfa8da562022-07-02 18:10:22 -070032 self.field.active_multispline.getConstraint(
33 "LONGITUDINAL_ACCELERATION"))
kyle96e46e12021-02-10 21:47:55 -080034 self.lat_input.set_value(
Ravago Jonesfa8da562022-07-02 18:10:22 -070035 self.field.active_multispline.getConstraint(
36 "LATERAL_ACCELERATION"))
37 self.vol_input.set_value(
38 self.field.active_multispline.getConstraint("VOLTAGE"))
John Park91e69732019-03-03 13:12:43 -080039
Ryan Yind8be3882021-10-13 20:59:41 -070040 def undo_func(self, *args):
41 self.field.undo()
Ravago Jones8da89c42022-07-17 19:34:06 -070042
kyle0e5a9f32021-01-23 15:02:19 -080043 def long_changed(self, button):
kyle96e46e12021-02-10 21:47:55 -080044 value = self.long_input.get_value()
Ravago Jonesfa8da562022-07-02 18:10:22 -070045 self.field.active_multispline.setConstraint(
46 "LONGITUDINAL_ACCELERATION", value)
47 self.field.graph.schedule_recalculate(self.field.multisplines)
kyle0e5a9f32021-01-23 15:02:19 -080048
49 def lat_changed(self, button):
kyle96e46e12021-02-10 21:47:55 -080050 value = self.lat_input.get_value()
Ravago Jonesfa8da562022-07-02 18:10:22 -070051 self.field.active_multispline.setConstraint("LATERAL_ACCELERATION",
52 value)
53 self.field.graph.schedule_recalculate(self.field.multisplines)
kyle0e5a9f32021-01-23 15:02:19 -080054
kyle96e46e12021-02-10 21:47:55 -080055 def vel_changed(self, button):
56 value = self.vel_input.get_value()
kyle0e5a9f32021-01-23 15:02:19 -080057
58 def vol_changed(self, button):
kyle96e46e12021-02-10 21:47:55 -080059 value = self.vol_input.get_value()
Ravago Jonesfa8da562022-07-02 18:10:22 -070060 self.field.active_multispline.setConstraint("VOLTAGE", value)
61 self.field.graph.schedule_recalculate(self.field.multisplines)
kyle0e5a9f32021-01-23 15:02:19 -080062
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -080063 def input_combobox_choice(self, combo):
64 text = combo.get_active_text()
65 if text is not None:
66 print("Combo Clicked on: " + text)
Ravago Jones086a8872021-08-07 15:49:40 -070067 self.field.set_field(FIELDS[text])
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -080068
John Park91e69732019-03-03 13:12:43 -080069 def __init__(self):
70 Gtk.Window.__init__(self)
71
72 self.set_default_size(1.5 * SCREEN_SIZE, SCREEN_SIZE)
73
Ravago Jones6d460fe2021-07-03 16:59:55 -070074 container = Gtk.Grid()
75 container.set_vexpand(True)
76 self.add(container)
John Park91e69732019-03-03 13:12:43 -080077
Ravago Jones6d460fe2021-07-03 16:59:55 -070078 self.field = FieldWidget()
John Park91e69732019-03-03 13:12:43 -080079
vlad56329f42020-06-12 21:41:08 -070080 self.method_connect("delete-event", basic_window.quit_main_loop)
Ravago Jones76ecec82021-08-07 14:37:08 -070081 self.method_connect("key-release-event", self.field.do_key_press_event)
John Park91e69732019-03-03 13:12:43 -080082
83 self.file_name_box = Gtk.Entry()
84 self.file_name_box.set_size_request(200, 40)
Ravago Jonesc26b9162021-06-30 20:12:48 -070085 self.file_name_box.set_text(FIELD.field_id + ".json")
John Park91e69732019-03-03 13:12:43 -080086 self.file_name_box.set_editable(True)
87
kyle0e5a9f32021-01-23 15:02:19 -080088 self.long_input = Gtk.SpinButton()
89 self.long_input.set_size_request(100, 20)
90 self.long_input.set_numeric(True)
Austin Schuhb9dc3f62021-03-31 20:06:49 -070091 self.long_input.set_range(0, 20)
kyle96e46e12021-02-10 21:47:55 -080092 self.long_input.set_digits(3)
93 self.long_input.set_increments(0.1, 100)
kyle0e5a9f32021-01-23 15:02:19 -080094 self.long_input.connect("value-changed", self.long_changed)
95 self.long_label = Gtk.Label()
kyle96e46e12021-02-10 21:47:55 -080096 self.long_label.set_text("Longitudinal Acceleration Restriction")
97 self.long_input.set_value(
Ravago Jonesfa8da562022-07-02 18:10:22 -070098 self.field.active_multispline.getConstraint(
99 "LONGITUDINAL_ACCELERATION"))
kyle0e5a9f32021-01-23 15:02:19 -0800100
101 self.lat_input = Gtk.SpinButton()
102 self.lat_input.set_size_request(100, 20)
103 self.lat_input.set_numeric(True)
Austin Schuhb9dc3f62021-03-31 20:06:49 -0700104 self.lat_input.set_range(0, 20)
kyle96e46e12021-02-10 21:47:55 -0800105 self.lat_input.set_digits(3)
106 self.lat_input.set_increments(0.1, 100)
kyle0e5a9f32021-01-23 15:02:19 -0800107 self.lat_input.connect("value-changed", self.lat_changed)
108 self.lat_label = Gtk.Label()
kyle96e46e12021-02-10 21:47:55 -0800109 self.lat_label.set_text("Lateral Acceleration Restriction")
110 self.lat_input.set_value(
Ravago Jonesfa8da562022-07-02 18:10:22 -0700111 self.field.active_multispline.getConstraint(
112 "LATERAL_ACCELERATION"))
kyle0e5a9f32021-01-23 15:02:19 -0800113
kyle96e46e12021-02-10 21:47:55 -0800114 self.vel_input = Gtk.SpinButton()
115 self.vel_input.set_size_request(100, 20)
116 self.vel_input.set_numeric(True)
117 self.vel_input.set_range(0, 10)
118 self.vel_input.set_digits(3)
119 self.vel_input.set_increments(0.1, 100)
120 self.vel_input.connect("value-changed", self.vel_changed)
121 self.vel_label = Gtk.Label()
122 self.vel_label.set_text(
123 "Velocity Restriction"
124 ) #note: the velocity restrictions are not yet working, they need to be hooked up later
kyle0e5a9f32021-01-23 15:02:19 -0800125
126 self.vol_input = Gtk.SpinButton()
127 self.vol_input.set_size_request(100, 20)
128 self.vol_input.set_numeric(True)
kyle96e46e12021-02-10 21:47:55 -0800129 self.vol_input.set_range(0, 12)
130 self.vol_input.set_digits(3)
131 self.vol_input.set_increments(0.1, 100)
kyle0e5a9f32021-01-23 15:02:19 -0800132 self.vol_input.connect("value-changed", self.vol_changed)
kyle0e5a9f32021-01-23 15:02:19 -0800133 self.vol_label = Gtk.Label()
134 self.vol_label.set_text("Voltage Restriction")
Ravago Jonesfa8da562022-07-02 18:10:22 -0700135 self.vol_input.set_value(
136 self.field.active_multispline.getConstraint("VOLTAGE"))
kyle0e5a9f32021-01-23 15:02:19 -0800137
Ravago Jones6d460fe2021-07-03 16:59:55 -0700138 self.output_json = Gtk.Button.new_with_label("Export")
John Park909c0392020-03-05 23:56:30 -0800139 self.output_json.set_size_request(100, 40)
140 self.output_json.connect("clicked", self.output_json_clicked)
141
142 self.input_json = Gtk.Button.new_with_label("Import")
143 self.input_json.set_size_request(100, 40)
144 self.input_json.connect("clicked", self.input_json_clicked)
145
Ryan Yin85f861f2021-09-16 17:55:11 -0700146 self.clear = Gtk.Button.new_with_label("Clear")
147 self.clear.set_size_request(100, 40)
148 self.clear.connect("clicked", self.clear_clicked)
Ryan Yind8be3882021-10-13 20:59:41 -0700149
150 self.undo = Gtk.Button.new_with_label("Undo (Ctrl + Z)")
151 self.undo.set_size_request(100, 40)
152 self.undo.connect("clicked", self.undo_func)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800153 #Dropdown feature
Ravago Jones6d460fe2021-07-03 16:59:55 -0700154 self.label = Gtk.Label()
155 self.label.set_text("Change Field:")
156 self.label.set_size_request(100, 40)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800157
158 game_store = Gtk.ListStore(str)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800159
160 self.game_combo = Gtk.ComboBoxText()
161 self.game_combo.set_entry_text_column(0)
162 self.game_combo.connect("changed", self.input_combobox_choice)
163
Ravago Jones6d460fe2021-07-03 16:59:55 -0700164 for game in FIELDS.keys():
165 self.game_combo.append_text(game)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800166
Ravago Jones76ecec82021-08-07 14:37:08 -0700167 if FIELD in FIELDS.values():
168 self.game_combo.set_active(list(FIELDS.values()).index(FIELD))
Ravago Jones6d460fe2021-07-03 16:59:55 -0700169 self.game_combo.set_size_request(100, 40)
170
171 limitControls = Gtk.FlowBox()
172 limitControls.set_min_children_per_line(1)
173 limitControls.set_max_children_per_line(2)
174 limitControls.add(self.long_label)
175 limitControls.add(self.long_input)
176
177 limitControls.add(self.lat_label)
178 limitControls.add(self.lat_input)
179
180 limitControls.add(self.vel_label)
181 limitControls.add(self.vel_input)
182
183 limitControls.add(self.vol_label)
184 limitControls.add(self.vol_input)
185
186 container.attach(limitControls, 5, 1, 1, 1)
187
188 jsonControls = Gtk.FlowBox()
Ryan Yind8be3882021-10-13 20:59:41 -0700189 jsonControls.set_min_children_per_line(5)
Ravago Jones6d460fe2021-07-03 16:59:55 -0700190 jsonControls.add(self.file_name_box)
191 jsonControls.add(self.output_json)
192 jsonControls.add(self.input_json)
Ryan Yin85f861f2021-09-16 17:55:11 -0700193 jsonControls.add(self.clear)
Ryan Yind8be3882021-10-13 20:59:41 -0700194 jsonControls.add(self.undo)
Ravago Jones6d460fe2021-07-03 16:59:55 -0700195 container.attach(jsonControls, 1, 0, 1, 1)
196
197 container.attach(self.label, 4, 0, 1, 1)
198 container.attach(self.game_combo, 5, 0, 1, 1)
199
Ravago Jones76ecec82021-08-07 14:37:08 -0700200 container.attach(self.field, 1, 1, 4, 4)
Ravago Jones6d460fe2021-07-03 16:59:55 -0700201
202 container.attach(self.field.graph, 0, 10, 10, 1)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800203
204 self.show_all()
John Park91e69732019-03-03 13:12:43 -0800205
Ravago Jones6d460fe2021-07-03 16:59:55 -0700206
John Park91e69732019-03-03 13:12:43 -0800207window = GridWindow()
208RunApp()