예제 #1
0
파일: files.py 프로젝트: thenetimp/LPHK
def load_layout(name, add_path=True):
    global curr_layout
    scripts.unbind_all()

    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 = int(info[0])
                script_text = info[1].replace(NEWLINE_REPLACE, "\n")

                if script_text != "":
                    scripts.bind(x, y, script_text, color)
                else:
                    lp_colors.setXY(x, y, color)
        lp_colors.update_all()
    curr_layout = final_path
    print("[files] Loaded layout " + final_path)
예제 #2
0
파일: files.py 프로젝트: shongdr/LPHK
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
예제 #3
0
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)
예제 #4
0
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()
    scripts.Unload_all()                         # remove all existing subroutines when you load a new layout
    window.Redraw(True)

    if preload == None:
        layout = load_layout(name, popups=popups, save_converted=save_converted)
    else:
        layout = preload

    # load subroutines before buttons so you don't get errors on buttons using them
    if "subroutines" in layout:                  # were subroutines saved?
        for sub in layout["subroutines"]:        # for all the subroutines that were saved
            load_subroutine(sub, 0, 'LAYOUT')    # load the subroutine

    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 == LP_MK1:
                if color[2] != 0:
                    color = lp_colors.RGB_to_RG(color)
                    converted_to_rg = True

            if script_text != "":
                script_validation = None
                try:
                    btn = scripts.Button(x, y, script_text)
                    script_validation = btn.Validate_script()
                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.Redraw(True)
                    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, btn, color)
            else:
                lp_colors.setXY(x, y, color)

    lp_colors.update_all()
    window.Redraw(True)

    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
예제 #5
0
파일: lp_events.py 프로젝트: thenetimp/LPHK
def start(lp_object):
    lp_colors.init(lp_object)
    init(lp_object)
    run(lp_object)
    lp_colors.update_all()
예제 #6
0
def start(lp_object):
    lp_colors.init(lp_object)  # assign this to a global (what?!)
    init(lp_object)  # create the timer object for this lp_object (button)
    run(lp_object)  # "run" the object (why not just start the timer?)
    lp_colors.update_all()  # update all the colours after exiting