def save_script(self, window, x, y, script_text, open_editor = False, color=None): global colors_to_set script_text = script_text.strip() def open_editor_func(): nonlocal x, y if open_editor: self.script_entry_window(x, y, script_text, color) try: script_validate = scripts.validate_script(script_text) except: self.popup(window, "Script Validation Error", self.error_image, "Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.", "OK", end_command = open_editor_func) raise if script_validate == True: if script_text != "": script_text = files.strip_lines(script_text) scripts.bind(x, y, script_text, colors_to_set[x][y]) self.draw_canvas() lp_colors.updateXY(x, y) window.destroy() else: self.popup(window, "No Script Entered", self.info_image, "Please enter a script to bind.", "OK", end_command = open_editor_func) else: self.popup(window, "(" + str(x) + ", " + str(y) + ") Syntax Error", self.error_image, "Error in line: " + script_validate[1] + "\n" + script_validate[0], "OK", end_command = open_editor_func)
def load_layout_to_lp(name, popups=True, save_converted=True, preload=None): global curr_layout global in_error global layout_changed_since_load converted_to_rg = False scripts.unbind_all() window.app.draw_canvas() if preload == None: layout = load_layout(name, popups=popups, save_converted=save_converted) else: layout = preload for x in range(9): for y in range(9): button = layout["buttons"][x][y] color = button["color"] script_text = button["text"] if window.lp_mode == "Mk1": if color[2] != 0: color = lp_colors.RGB_to_RG(color) converted_to_rg = True if script_text != "": script_validation = None try: script_validation = scripts.validate_script(script_text) except: new_layout_func = lambda: window.app.unbind_lp(prompt_save = False) if popups: window.app.popup(window.app, "Script Validation Error", window.app.error_image, "Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.", "OK", end_command = new_layout_func) else: print("[files] Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.") raise if script_validation != True: lp_colors.update_all() window.app.draw_canvas() in_error = True window.app.save_script(window.app, x, y, script_text, open_editor = True, color = color) in_error = False else: scripts.bind(x, y, script_text, color) else: lp_colors.setXY(x, y, color) lp_colors.update_all() window.app.draw_canvas() curr_layout = name if converted_to_rg: if popups: window.app.popup(window.app, "Layout converted to Classic/Mini/S...", window.app.info_image, "The colors in this layout have been converted to be\ncompatable with the Launchpad Classic/Mini/S.\n\nChanges have not yet been saved to the file.", "OK") else: print("[files] The colors in this layout have been converted to be compatable with the Launchpad Classic/Mini/S. Changes have not yet been saved to the file.") layout_changed_since_load = True else: layout_changed_since_load = False
def validate_func(): nonlocal x, y, t text_string = t.get(1.0, tk.END) script_validate = scripts.validate_script(text_string) if script_validate != True and files.in_error: self.save_script(w, x, y, text_string) else: w.destroy()
def validate_func(): nonlocal x, y, t text_string = t.get(1.0, tk.END) try: script_validate = scripts.validate_script(text_string) except: #self.save_script(w, x, y, text_string) # This will fail and throw a popup error self.popup(w, "Script Validation Error", self.error_image, "Fatal error while attempting to validate script.\nPlease see LPHK.log for more information.", "OK") raise if script_validate != True and files.in_error: self.save_script(w, x, y, text_string) else: w.destroy()
def save_script(self, window, x, y, color, script_text): script_text = script_text.strip() script_validate = scripts.validate_script(script_text) if script_validate == True: if script_text != "": script_text = files.strip_lines(script_text) scripts.bind(x, y, script_text, color) self.draw_canvas() lp_colors.updateXY(x, y) window.destroy() else: self.popup(window, "No Script Entered", self.info_image, "Please enter a script to bind.", "OK") else: self.popup(window, "Syntax Error", self.warning_image, "Error in line: " + script_validate[1] + "\n" + script_validate[0], "OK")
def load_layout(name, add_path=True): global curr_layout global in_error global layout_changed_since_load scripts.unbind_all() window.app.draw_canvas() final_path = None if add_path: final_path = PATH + LAYOUT_PATH + name + LAYOUT_EXT else: final_path = name with open(final_path, "r") as f: l = f.readlines() for x in range(9): line = l[x][:-1].split(BUTTON_SEPERATOR) for y in range(9): info = line[y].split(ENTRY_SEPERATOR) color = info[0] if not color.isdigit(): split = color.split(",") color = [] color.append(int(split[0])) color.append(int(split[1])) color.append(int(split[2])) else: color = int(info[0]) script_text = info[1].replace(NEWLINE_REPLACE, "\n") if script_text != "": script_validation = scripts.validate_script(script_text) if script_validation != True: lp_colors.update_all() window.app.draw_canvas() in_error = True window.app.save_script(window.app, x, y, script_text, open_editor = True, color = color) in_error = False else: scripts.bind(x, y, script_text, color) else: lp_colors.setXY(x, y, color) lp_colors.update_all() window.app.draw_canvas() curr_layout = final_path layout_changed_since_load = False print("[files] Loaded layout " + final_path)