blob: a8e5c78d6b52ebe160de1facb94cfc4a0936becf [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
John Park91e69732019-03-03 13:12:43 -080023 def configure(self, event):
Ravago Jones6d460fe2021-07-03 16:59:55 -070024 self.field.window_shape = (event.width, event.height)
John Park91e69732019-03-03 13:12:43 -080025
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 Jones6d460fe2021-07-03 16:59:55 -070032 self.field.points.getConstraint("LONGITUDINAL_ACCELERATION"))
kyle96e46e12021-02-10 21:47:55 -080033 self.lat_input.set_value(
Ravago Jones6d460fe2021-07-03 16:59:55 -070034 self.field.points.getConstraint("LATERAL_ACCELERATION"))
35 self.vol_input.set_value(self.field.points.getConstraint("VOLTAGE"))
John Park91e69732019-03-03 13:12:43 -080036
kyle0e5a9f32021-01-23 15:02:19 -080037 def long_changed(self, button):
kyle96e46e12021-02-10 21:47:55 -080038 value = self.long_input.get_value()
Ravago Jones6d460fe2021-07-03 16:59:55 -070039 self.field.points.setConstraint("LONGITUDINAL_ACCELERATION", value)
kyle0e5a9f32021-01-23 15:02:19 -080040
41 def lat_changed(self, button):
kyle96e46e12021-02-10 21:47:55 -080042 value = self.lat_input.get_value()
Ravago Jones6d460fe2021-07-03 16:59:55 -070043 self.field.points.setConstraint("LATERAL_ACCELERATION", value)
kyle0e5a9f32021-01-23 15:02:19 -080044
kyle96e46e12021-02-10 21:47:55 -080045 def vel_changed(self, button):
46 value = self.vel_input.get_value()
kyle0e5a9f32021-01-23 15:02:19 -080047
48 def vol_changed(self, button):
kyle96e46e12021-02-10 21:47:55 -080049 value = self.vol_input.get_value()
Ravago Jones6d460fe2021-07-03 16:59:55 -070050 self.field.points.setConstraint("VOLTAGE", value)
kyle0e5a9f32021-01-23 15:02:19 -080051
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -080052 def input_combobox_choice(self, combo):
53 text = combo.get_active_text()
54 if text is not None:
55 print("Combo Clicked on: " + text)
Ravago Jones6d460fe2021-07-03 16:59:55 -070056 #set_field(text)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -080057
John Park91e69732019-03-03 13:12:43 -080058 def __init__(self):
59 Gtk.Window.__init__(self)
60
61 self.set_default_size(1.5 * SCREEN_SIZE, SCREEN_SIZE)
62
Ravago Jones6d460fe2021-07-03 16:59:55 -070063 container = Gtk.Grid()
64 container.set_vexpand(True)
65 self.add(container)
John Park91e69732019-03-03 13:12:43 -080066
67 self.eventBox = Gtk.EventBox()
John Park91e69732019-03-03 13:12:43 -080068 self.eventBox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK
Ravago Jones128fb992021-07-31 13:56:58 -070069 | Gdk.EventMask.BUTTON_PRESS_MASK
John Park91e69732019-03-03 13:12:43 -080070 | Gdk.EventMask.BUTTON_RELEASE_MASK
71 | Gdk.EventMask.POINTER_MOTION_MASK
72 | Gdk.EventMask.SCROLL_MASK
73 | Gdk.EventMask.KEY_PRESS_MASK)
74
Ravago Jones6d460fe2021-07-03 16:59:55 -070075 self.field = FieldWidget()
John Park91e69732019-03-03 13:12:43 -080076
vlad56329f42020-06-12 21:41:08 -070077 self.method_connect("delete-event", basic_window.quit_main_loop)
Ravago Jones128fb992021-07-31 13:56:58 -070078 self.method_connect("key-release-event", self.field.key_press)
79 self.method_connect("button-press-event", self.field.button_press)
80 self.method_connect("button-release-event", self.field.button_release)
John Park91e69732019-03-03 13:12:43 -080081 self.method_connect("configure-event", self.configure)
Ravago Jones128fb992021-07-31 13:56:58 -070082 self.method_connect("motion_notify_event", self.field.mouse_move)
Ravago Jones01781202021-08-01 15:25:11 -070083 self.method_connect("scroll_event", self.field.mouse_scroll)
John Park91e69732019-03-03 13:12:43 -080084
85 self.file_name_box = Gtk.Entry()
86 self.file_name_box.set_size_request(200, 40)
Ravago Jonesc26b9162021-06-30 20:12:48 -070087 self.file_name_box.set_text(FIELD.field_id + ".json")
John Park91e69732019-03-03 13:12:43 -080088 self.file_name_box.set_editable(True)
89
kyle0e5a9f32021-01-23 15:02:19 -080090 self.long_input = Gtk.SpinButton()
91 self.long_input.set_size_request(100, 20)
92 self.long_input.set_numeric(True)
Austin Schuhb9dc3f62021-03-31 20:06:49 -070093 self.long_input.set_range(0, 20)
kyle96e46e12021-02-10 21:47:55 -080094 self.long_input.set_digits(3)
95 self.long_input.set_increments(0.1, 100)
kyle0e5a9f32021-01-23 15:02:19 -080096 self.long_input.connect("value-changed", self.long_changed)
97 self.long_label = Gtk.Label()
kyle96e46e12021-02-10 21:47:55 -080098 self.long_label.set_text("Longitudinal Acceleration Restriction")
99 self.long_input.set_value(
Ravago Jones6d460fe2021-07-03 16:59:55 -0700100 self.field.points.getConstraint("LONGITUDINAL_ACCELERATION"))
kyle0e5a9f32021-01-23 15:02:19 -0800101
102 self.lat_input = Gtk.SpinButton()
103 self.lat_input.set_size_request(100, 20)
104 self.lat_input.set_numeric(True)
Austin Schuhb9dc3f62021-03-31 20:06:49 -0700105 self.lat_input.set_range(0, 20)
kyle96e46e12021-02-10 21:47:55 -0800106 self.lat_input.set_digits(3)
107 self.lat_input.set_increments(0.1, 100)
kyle0e5a9f32021-01-23 15:02:19 -0800108 self.lat_input.connect("value-changed", self.lat_changed)
109 self.lat_label = Gtk.Label()
kyle96e46e12021-02-10 21:47:55 -0800110 self.lat_label.set_text("Lateral Acceleration Restriction")
111 self.lat_input.set_value(
Ravago Jones6d460fe2021-07-03 16:59:55 -0700112 self.field.points.getConstraint("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 Jones6d460fe2021-07-03 16:59:55 -0700135 self.vol_input.set_value(self.field.points.getConstraint("VOLTAGE"))
kyle0e5a9f32021-01-23 15:02:19 -0800136
Ravago Jones6d460fe2021-07-03 16:59:55 -0700137 self.output_json = Gtk.Button.new_with_label("Export")
John Park909c0392020-03-05 23:56:30 -0800138 self.output_json.set_size_request(100, 40)
139 self.output_json.connect("clicked", self.output_json_clicked)
140
141 self.input_json = Gtk.Button.new_with_label("Import")
142 self.input_json.set_size_request(100, 40)
143 self.input_json.connect("clicked", self.input_json_clicked)
144
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800145 #Dropdown feature
Ravago Jones6d460fe2021-07-03 16:59:55 -0700146 self.label = Gtk.Label()
147 self.label.set_text("Change Field:")
148 self.label.set_size_request(100, 40)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800149
150 game_store = Gtk.ListStore(str)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800151
152 self.game_combo = Gtk.ComboBoxText()
153 self.game_combo.set_entry_text_column(0)
154 self.game_combo.connect("changed", self.input_combobox_choice)
155
Ravago Jones6d460fe2021-07-03 16:59:55 -0700156 for game in FIELDS.keys():
157 self.game_combo.append_text(game)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800158
159 self.game_combo.set_active(0)
Ravago Jones6d460fe2021-07-03 16:59:55 -0700160 self.game_combo.set_size_request(100, 40)
161
162 limitControls = Gtk.FlowBox()
163 limitControls.set_min_children_per_line(1)
164 limitControls.set_max_children_per_line(2)
165 limitControls.add(self.long_label)
166 limitControls.add(self.long_input)
167
168 limitControls.add(self.lat_label)
169 limitControls.add(self.lat_input)
170
171 limitControls.add(self.vel_label)
172 limitControls.add(self.vel_input)
173
174 limitControls.add(self.vol_label)
175 limitControls.add(self.vol_input)
176
177 container.attach(limitControls, 5, 1, 1, 1)
178
179 jsonControls = Gtk.FlowBox()
180 jsonControls.set_min_children_per_line(3)
181 jsonControls.add(self.file_name_box)
182 jsonControls.add(self.output_json)
183 jsonControls.add(self.input_json)
184 container.attach(jsonControls, 1, 0, 1, 1)
185
186 container.attach(self.label, 4, 0, 1, 1)
187 container.attach(self.game_combo, 5, 0, 1, 1)
188
189 self.eventBox.add(self.field)
190 container.attach(self.eventBox, 1, 1, 4, 4)
191
192 container.attach(self.field.graph, 0, 10, 10, 1)
Kenneth Nishiyamab45b7ba2021-01-27 21:45:34 -0800193
194 self.show_all()
John Park91e69732019-03-03 13:12:43 -0800195
Ravago Jones6d460fe2021-07-03 16:59:55 -0700196
John Park91e69732019-03-03 13:12:43 -0800197window = GridWindow()
198RunApp()