def mainButtons(self): row = 0 col = 0 self.buttons = [] mb = Menubutton(self.root, text="Select Application") mb.menu = Menu(mb, tearoff=0) mb["menu"] = mb.menu for app in APPLICATIONS: mb.menu.add_radiobutton(label=app, variable=self.appVar, command=self.onSelectApp) mb.grid(row=row, column=col, sticky="NEW") col += 1 self.buttons.append(mb) otherButtons = ( ("Run %12s" % self.appVar.get(), self.runApp), ("load Config", self.loadCfg), ("Save Config", self.saveCfg), ("Save Config as", self.saveCfgAs), ("Quit", self.root.quit), ) for text, command in otherButtons: self.buttons.append(Button(self.root, text=text, command=command)) self.buttons[-1].grid(row=row, column=col, sticky="NEW") col += 1 return len(self.buttons)
def initialize(self): self.master.title("NENR DZ5 - Miljenko Šuflaj") self.pack(fill="both", expand=True) notebook = Notebook(self) notebook.pack() record_gestures_frame = Frame(self) classify_gestures_frame = Frame(self) notebook.add(record_gestures_frame, text="Zabilježi geste") notebook.add(classify_gestures_frame, text="Klasificiraj geste") notebook.enable_traversal() notebook.select(record_gestures_frame) gesture_classification_frame = Frame(classify_gestures_frame) gesture_record_frame_2 = Frame(classify_gestures_frame) gesture_classification_frame.pack(side="top", fill="x", expand=True) gesture_record_frame_2.pack(fill="both") # region Record gesture tab gesture_info_frame = Frame(record_gestures_frame) gesture_record_frame = Frame(record_gestures_frame) gesture_end_frame = Frame(record_gestures_frame) gesture_info_frame.pack(side="top", fill="x") gesture_record_frame.pack(fill="both") gesture_end_frame.pack(side="bottom", fill="x") gesture_name_menu = Menubutton(gesture_info_frame, text="Odaberi gestu za bilježenje...") gesture_name_menu.menu = Menu(gesture_name_menu, tearoff=0) gesture_name_menu["menu"] = gesture_name_menu.menu for i, label in enumerate(GestureWindow.labels): gesture_name_menu.menu.add_command(label=label, command=self.switch_record(i)) self.__recorded_gesture_label = Label(gesture_info_frame) gesture_record_canvas = Canvas(gesture_record_frame, width=700, height=475, bg="white") gesture_record_canvas.current_coords = None gesture_record_canvas.records = list() gesture_record_save_button = Button(gesture_end_frame, text="Pohrani u .tsv", command=self.save_data) gesture_record_delete_button = Button(gesture_end_frame, text="Zaboravi učitane podatke", command=self.delete_internal) gesture_name_menu.pack(side="left", fill="x", padx=5, pady=5, expand=True) self.__recorded_gesture_label.pack(side="left", fill="x", padx=5, pady=5) gesture_record_canvas.pack(fill="both", padx=5, pady=5, expand=True) gesture_record_delete_button.pack(side="left", fill="x", padx=5, pady=5) gesture_record_save_button.pack(side="right", fill="x", padx=5, pady=5) self.switch_record(self.__recorded_gesture_index)() # endregion # region Classify gesture tab gesture_classification_frame = Frame(classify_gestures_frame) gesture_record_frame_2 = Frame(classify_gestures_frame) gesture_classification_frame.pack(side="top", fill="x", expand=True) gesture_record_frame_2.pack(fill="both") classification_labels = list() self.__classification_outputs = list() for category in GestureWindow.labels: classification_labels.append( Label(gesture_classification_frame, text=category)) self.__classification_outputs.append( Label(gesture_classification_frame, text=f"{0.:.01f}%", font=("helvetica", 8))) classification_blank = Label(gesture_classification_frame) classification_labels[-1].pack(side="left", fill="x", padx=5, pady=5) self.__classification_outputs[-1].pack(side="left", fill="x", padx=5, pady=5) classification_blank.pack(side="left", fill="x", padx=50, pady=5) gesture_record_canvas_2 = Canvas(gesture_record_frame_2, width=700, height=525, bg="white") gesture_record_canvas_2.current_coords = None gesture_record_canvas_2.records = list() gesture_record_canvas_2.pack(side="left", fill="both", padx=5, pady=5, expand=True) # endregion # region Functionality for record_canvas in [gesture_record_canvas, gesture_record_canvas_2]: draw_function = self.get_draw_on_canvas_function(record_canvas) record_canvas.bind("<B1-Motion>", draw_function) record_canvas.bind("<ButtonRelease-1>", draw_function) self.__root_window.bind( "<BackSpace>", self.get_delete_currently_drawn(gesture_record_canvas)) self.__root_window.bind( "<Return>", self.get_record_gesture_function(gesture_record_canvas)) gesture_record_canvas_2.bind( "<Leave>", self.get_evaluate_gesture_function(gesture_record_canvas_2)) self.__root_window.bind( "<Delete>", self.get_delete_currently_drawn(gesture_record_canvas_2))