def setup_window(self): from tkinter import Canvas self.master.bind('<Destroy>', self.on_destroy) if self.is_test: self.master.bind('<Left>', lambda x: self.cmd_turn_car(self.car_orn - .1)) self.master.bind('<Right>', lambda x: self.cmd_turn_car(self.car_orn + .1)) self.master.bind('<Up>', lambda x: self.cmd_move_car(m2d.add(self.car_pos, m2d.mul(m2d.make_polar(self.car_orn), 5)))) self.master.bind('<Down>', lambda x: self.cmd_move_car(m2d.add(self.car_pos, m2d.mul(m2d.make_polar(self.car_orn), -5)))) self.canvas = Canvas(self.master, width=512, height=512) self.canvas.pack(fill="both", expand=True) self.canvas.bind('<Configure>', self.on_resize) self.width = self.canvas.winfo_width() self.height = self.canvas.winfo_height() return True
def __init__(self, master, send_q, resp_q, floor_file, walls_file, is_test=True): self.master = master master.title("PathfinderSim Display Window") master.geometry("512x600") # Parse the input files self.floors = OBJModel(floor_file) self.walls = OBJModel(walls_file) self.floors.parse() self.walls.parse() self.walls_AABB = self.walls.model_AABB() # cache this self.floors_AABB = self.floors.model_AABB() # cached self.floor_polys = [] self.floors_seen = [False] * self.floors.get_prim_count() self.floors_id = [] # Intercept the destroy event so we can shutdown gracefully master.bind("<Destroy>", self.on_destroy) self.is_test = is_test if is_test: master.bind('<Left>', lambda x: self.cmd_turn_car(self.car_orn - .1)) master.bind('<Right>', lambda x: self.cmd_turn_car(self.car_orn + .1)) master.bind('<Up>', lambda x: self.cmd_move_car(m2d.add(self.car_pos, m2d.mul(m2d.make_polar(self.car_orn), 5)))) master.bind('<Down>', lambda x: self.cmd_move_car(m2d.add(self.car_pos, m2d.mul(m2d.make_polar(self.car_orn), -5)))) self.canvas = Canvas(master, width=512, height=512) self.canvas.pack(fill="both", expand=True) self.canvas.bind('<Configure>', self.on_resize) self.width = self.canvas.winfo_width() self.height = self.canvas.winfo_height() self.car_pos = [100, 100] self.car_orn = 0 self.car_rays = 12 self.ray_dtheta = 2.*math.pi/self.car_rays # Async comms to class in separate thread self.command_q = send_q self.response_q = resp_q self.shutdown_flag = False self.button = Button(master, text="Quit", command=self.shutdown) self.button.pack() self.draw_map() self.car = self.build_car(self.car_pos, 12)