| #!/usr/bin/python3 |
| |
| # matplotlib overrides fontconfig locations, so has to be imported before gtk |
| import matplotlib |
| import gi |
| from path_edit import FieldWidget |
| from basic_window import RunApp |
| from constants import FIELDS, FIELD, SCREEN_SIZE |
| gi.require_version('Gtk', '3.0') |
| from gi.repository import Gdk, Gtk, GLib |
| import cairo |
| import basic_window |
| import os |
| |
| |
| class GridWindow(Gtk.Window): |
| def method_connect(self, event, cb): |
| def handler(obj, *args): |
| cb(*args) |
| |
| self.connect(event, handler) |
| |
| def configure(self, event): |
| self.field.window_shape = (event.width, event.height) |
| |
| def output_json_clicked(self, button): |
| self.field.export_json(self.file_name_box.get_text()) |
| |
| def input_json_clicked(self, button): |
| self.field.import_json(self.file_name_box.get_text()) |
| self.long_input.set_value( |
| self.field.points.getConstraint("LONGITUDINAL_ACCELERATION")) |
| self.lat_input.set_value( |
| self.field.points.getConstraint("LATERAL_ACCELERATION")) |
| self.vol_input.set_value(self.field.points.getConstraint("VOLTAGE")) |
| |
| def long_changed(self, button): |
| value = self.long_input.get_value() |
| self.field.points.setConstraint("LONGITUDINAL_ACCELERATION", value) |
| |
| def lat_changed(self, button): |
| value = self.lat_input.get_value() |
| self.field.points.setConstraint("LATERAL_ACCELERATION", value) |
| |
| def vel_changed(self, button): |
| value = self.vel_input.get_value() |
| |
| def vol_changed(self, button): |
| value = self.vol_input.get_value() |
| self.field.points.setConstraint("VOLTAGE", value) |
| |
| def input_combobox_choice(self, combo): |
| text = combo.get_active_text() |
| if text is not None: |
| print("Combo Clicked on: " + text) |
| #set_field(text) |
| |
| def __init__(self): |
| Gtk.Window.__init__(self) |
| |
| self.set_default_size(1.5 * SCREEN_SIZE, SCREEN_SIZE) |
| |
| container = Gtk.Grid() |
| container.set_vexpand(True) |
| self.add(container) |
| |
| self.eventBox = Gtk.EventBox() |
| self.eventBox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK |
| | Gdk.EventMask.BUTTON_PRESS_MASK |
| | Gdk.EventMask.BUTTON_RELEASE_MASK |
| | Gdk.EventMask.POINTER_MOTION_MASK |
| | Gdk.EventMask.SCROLL_MASK |
| | Gdk.EventMask.KEY_PRESS_MASK) |
| |
| self.field = FieldWidget() |
| |
| self.method_connect("delete-event", basic_window.quit_main_loop) |
| self.method_connect("key-release-event", self.field.key_press) |
| self.method_connect("button-press-event", self.field.button_press) |
| self.method_connect("button-release-event", self.field.button_release) |
| self.method_connect("configure-event", self.configure) |
| self.method_connect("motion_notify_event", self.field.mouse_move) |
| self.method_connect("scroll_event", self.field.mouse_scroll) |
| |
| self.file_name_box = Gtk.Entry() |
| self.file_name_box.set_size_request(200, 40) |
| self.file_name_box.set_text(FIELD.field_id + ".json") |
| self.file_name_box.set_editable(True) |
| |
| self.long_input = Gtk.SpinButton() |
| self.long_input.set_size_request(100, 20) |
| self.long_input.set_numeric(True) |
| self.long_input.set_range(0, 20) |
| self.long_input.set_digits(3) |
| self.long_input.set_increments(0.1, 100) |
| self.long_input.connect("value-changed", self.long_changed) |
| self.long_label = Gtk.Label() |
| self.long_label.set_text("Longitudinal Acceleration Restriction") |
| self.long_input.set_value( |
| self.field.points.getConstraint("LONGITUDINAL_ACCELERATION")) |
| |
| self.lat_input = Gtk.SpinButton() |
| self.lat_input.set_size_request(100, 20) |
| self.lat_input.set_numeric(True) |
| self.lat_input.set_range(0, 20) |
| self.lat_input.set_digits(3) |
| self.lat_input.set_increments(0.1, 100) |
| self.lat_input.connect("value-changed", self.lat_changed) |
| self.lat_label = Gtk.Label() |
| self.lat_label.set_text("Lateral Acceleration Restriction") |
| self.lat_input.set_value( |
| self.field.points.getConstraint("LATERAL_ACCELERATION")) |
| |
| self.vel_input = Gtk.SpinButton() |
| self.vel_input.set_size_request(100, 20) |
| self.vel_input.set_numeric(True) |
| self.vel_input.set_range(0, 10) |
| self.vel_input.set_digits(3) |
| self.vel_input.set_increments(0.1, 100) |
| self.vel_input.connect("value-changed", self.vel_changed) |
| self.vel_label = Gtk.Label() |
| self.vel_label.set_text( |
| "Velocity Restriction" |
| ) #note: the velocity restrictions are not yet working, they need to be hooked up later |
| |
| self.vol_input = Gtk.SpinButton() |
| self.vol_input.set_size_request(100, 20) |
| self.vol_input.set_numeric(True) |
| self.vol_input.set_range(0, 12) |
| self.vol_input.set_digits(3) |
| self.vol_input.set_increments(0.1, 100) |
| self.vol_input.connect("value-changed", self.vol_changed) |
| self.vol_label = Gtk.Label() |
| self.vol_label.set_text("Voltage Restriction") |
| self.vol_input.set_value(self.field.points.getConstraint("VOLTAGE")) |
| |
| self.output_json = Gtk.Button.new_with_label("Export") |
| self.output_json.set_size_request(100, 40) |
| self.output_json.connect("clicked", self.output_json_clicked) |
| |
| self.input_json = Gtk.Button.new_with_label("Import") |
| self.input_json.set_size_request(100, 40) |
| self.input_json.connect("clicked", self.input_json_clicked) |
| |
| #Dropdown feature |
| self.label = Gtk.Label() |
| self.label.set_text("Change Field:") |
| self.label.set_size_request(100, 40) |
| |
| game_store = Gtk.ListStore(str) |
| |
| self.game_combo = Gtk.ComboBoxText() |
| self.game_combo.set_entry_text_column(0) |
| self.game_combo.connect("changed", self.input_combobox_choice) |
| |
| for game in FIELDS.keys(): |
| self.game_combo.append_text(game) |
| |
| self.game_combo.set_active(0) |
| self.game_combo.set_size_request(100, 40) |
| |
| limitControls = Gtk.FlowBox() |
| limitControls.set_min_children_per_line(1) |
| limitControls.set_max_children_per_line(2) |
| limitControls.add(self.long_label) |
| limitControls.add(self.long_input) |
| |
| limitControls.add(self.lat_label) |
| limitControls.add(self.lat_input) |
| |
| limitControls.add(self.vel_label) |
| limitControls.add(self.vel_input) |
| |
| limitControls.add(self.vol_label) |
| limitControls.add(self.vol_input) |
| |
| container.attach(limitControls, 5, 1, 1, 1) |
| |
| jsonControls = Gtk.FlowBox() |
| jsonControls.set_min_children_per_line(3) |
| jsonControls.add(self.file_name_box) |
| jsonControls.add(self.output_json) |
| jsonControls.add(self.input_json) |
| container.attach(jsonControls, 1, 0, 1, 1) |
| |
| container.attach(self.label, 4, 0, 1, 1) |
| container.attach(self.game_combo, 5, 0, 1, 1) |
| |
| self.eventBox.add(self.field) |
| container.attach(self.eventBox, 1, 1, 4, 4) |
| |
| container.attach(self.field.graph, 0, 10, 10, 1) |
| |
| self.show_all() |
| |
| |
| window = GridWindow() |
| RunApp() |