示例#1
0
def load_layout_legacy(name, printing=True):
    layout = dict()
    layout["version"] = "LEGACY"

    layout["buttons"] = []
    with open(name, "r") as f:
        l = f.readlines()

        for x in range(9):
            layout["buttons"].append([])
            line = l[x][:-1].split(":LPHK_BUTTON_SEP:")
            for y in range(9):
                info = line[y].split(":LPHK_ENTRY_SEP:")

                color = None
                if not info[0].isdigit():
                    split = info[0].split(",")
                    color = [int(x) for x in split[:3]]
                else:
                    color = lp_colors.code_to_RGB(int(info[0]))
                script_text = info[1].replace(":LPHK_NEWLINE_REP:", "\n")

                layout["buttons"][-1].append({"color": color, "text": script_text})
    if printing:
        print("[files] Loaded legacy layout " + name)
    return layout
示例#2
0
    def script_entry_window(self,
                            x,
                            y,
                            text_override=None,
                            color_override=None):
        global color_to_set

        w = tk.Toplevel(self)
        w.winfo_toplevel().title("Editing Script for Button (" + str(x) +
                                 ", " + str(y) + ")")
        w.resizable(False, False)
        if MAIN_ICON != None:
            if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
                dummy = None
                #w.call('wm', 'iconphoto', w._w, tk.PhotoImage(file=MAIN_ICON))
            else:
                w.iconbitmap(MAIN_ICON)

        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()

        w.protocol("WM_DELETE_WINDOW", validate_func)

        e_m = tk.Menu(w)
        w.config(menu=e_m)

        e_m_Script = tk.Menu(e_m, tearoff=False)

        t = tk.scrolledtext.ScrolledText(w)
        t.grid(column=0, row=0, rowspan=3, padx=10, pady=10)

        if text_override == None:
            t.insert(tk.INSERT, scripts.text[x][y])
        else:
            t.insert(tk.INSERT, text_override)
        t.bind("<<Paste>>", self.custom_paste)
        t.bind("<Control-Key-a>", self.select_all)

        import_script_func = lambda: self.import_script(t, w)
        e_m_Script.add_command(label="Import script",
                               command=import_script_func)
        export_script_func = lambda: self.export_script(t, w)
        e_m_Script.add_command(label="Export script",
                               command=export_script_func)
        e_m.add_cascade(label="Script", menu=e_m_Script)

        if color_override == None:
            colors_to_set[x][y] = lp_colors.getXY(x, y)
        else:
            colors_to_set[x][y] = color_override

        if type(colors_to_set[x][y]) == int:
            colors_to_set[x][y] = lp_colors.code_to_RGB(colors_to_set[x][y])

        if all(c < 4 for c in colors_to_set[x][y]):
            if lp_mode == "Mk1":
                colors_to_set[x][y] = MK1_DEFAULT_COLOR
            else:
                colors_to_set[x][y] = DEFAULT_COLOR

        ask_color_func = lambda: self.ask_color(w, color_button, x, y,
                                                colors_to_set[x][y])
        color_button = tk.Button(w,
                                 text="Select Color",
                                 command=ask_color_func)
        color_button.grid(column=1,
                          row=0,
                          padx=(0, 10),
                          pady=(10, 50),
                          sticky="nesw")
        color_button.config(font=BUTTON_FONT)
        start_color_str = lp_colors.list_RGB_to_string(colors_to_set[x][y])
        self.button_color_with_text_update(color_button, start_color_str)

        save_script_func = lambda: self.save_script(w, x, y, t.get(
            1.0, tk.END))
        save_button = tk.Button(w,
                                text="Bind Button (" + str(x) + ", " + str(y) +
                                ")",
                                command=save_script_func)
        save_button.grid(column=1, row=1, padx=(0, 10), sticky="nesw")
        save_button.config(font=BUTTON_FONT)
        save_button.config(bg="#c3d9C3")

        unbind_func = lambda: self.unbind_destroy(x, y, w)
        unbind_button = tk.Button(w,
                                  text="Unbind Button (" + str(x) + ", " +
                                  str(y) + ")",
                                  command=unbind_func)
        unbind_button.grid(column=1,
                           row=2,
                           padx=(0, 10),
                           pady=10,
                           sticky="nesw")
        unbind_button.config(font=BUTTON_FONT)
        unbind_button.config(bg="#d9c3c3")

        w.wait_visibility()
        w.grab_set()
        t.focus_set()
        w.wait_window()
示例#3
0
    def script_entry_window(self,
                            x,
                            y,
                            text_override=None,
                            color_override=None):
        global color_to_set

        w = tk.Toplevel(self)
        w.winfo_toplevel().title("Editing Script for Button (" + str(x) +
                                 ", " + str(y) + ")...")
        w.resizable(False, 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()

        w.protocol("WM_DELETE_WINDOW", validate_func)

        e_m = tk.Menu(w)
        w.config(menu=e_m)

        e_m_Script = tk.Menu(e_m, tearoff=False)

        t = tk.scrolledtext.ScrolledText(w)
        t.grid(column=0, row=0, rowspan=3, padx=10, pady=10)

        if text_override == None:
            t.insert(tk.INSERT, scripts.text[x][y])
        else:
            t.insert(tk.INSERT, text_override)
        t.bind("<<Paste>>", self.custom_paste)
        t.bind("<Control-Key-a>", self.select_all)

        import_script_func = lambda: self.import_script(t, w)
        e_m_Script.add_command(label="Import script...",
                               command=import_script_func)
        export_script_func = lambda: self.export_script(t, w)
        e_m_Script.add_command(label="Export script...",
                               command=export_script_func)
        e_m.add_cascade(label="Script", menu=e_m_Script)

        if color_override == None:
            colors_to_set[x][y] = lp_colors.getXY(x, y)
        else:
            colors_to_set[x][y] = color_override

        if type(colors_to_set[x][y]) == int:
            colors_to_set[x][y] = lp_colors.code_to_RGB(colors_to_set[x][y])

        if all(c < 4 for c in colors_to_set[x][y]):
            colors_to_set[x][y] = DEFAULT_COLOR

        ask_color_func = lambda: self.ask_color(w, color_button, x, y,
                                                colors_to_set[x][y])
        color_button = tk.Button(w,
                                 text="Select Color",
                                 command=ask_color_func)
        color_button.grid(column=1,
                          row=0,
                          padx=(0, 10),
                          pady=(10, 50),
                          sticky="nesw")
        color_button.config(font=BUTTON_FONT)
        start_color_str = lp_colors.list_RGB_to_string(colors_to_set[x][y])
        self.button_color_with_text_update(color_button, start_color_str)

        save_script_func = lambda: self.save_script(w, x, y, t.get(
            1.0, tk.END))
        save_button = tk.Button(w,
                                text="Bind Button (" + str(x) + ", " + str(y) +
                                ")",
                                command=save_script_func)
        save_button.grid(column=1, row=1, padx=(0, 10), sticky="nesw")
        save_button.config(font=BUTTON_FONT)
        save_button.config(bg="#c3d9C3")

        unbind_func = lambda: self.unbind_destroy(x, y, w)
        unbind_button = tk.Button(w,
                                  text="Unbind Button (" + str(x) + ", " +
                                  str(y) + ")",
                                  command=unbind_func)
        unbind_button.grid(column=1,
                           row=2,
                           padx=(0, 10),
                           pady=10,
                           sticky="nesw")
        unbind_button.config(font=BUTTON_FONT)
        unbind_button.config(bg="#d9c3c3")

        w.wait_visibility()
        w.grab_set()
        t.focus_set()
        w.wait_window()