Ejemplo n.º 1
0
 def delete_profile():
     global file_display
     os.remove("profiles/" + file_display.value)
     file_display.destroy()
     file_display = Combo(box3,
                          options=get_profile_list(),
                          command=file_load,
                          grid=[0, 0])
     file_display.size = 24
     file_display.bg = "white"
     file_load(file_display.value)
Ejemplo n.º 2
0
def editor_launcher():
    def copy():
        copy_window = Window(json_editor_window, title="create a copy")
        copy_window.show(wait=True)
        Text(copy_window, text="Name of copy :")
        file_name = TextBox(copy_window,
                            text=file_display.value,
                            enabled=True,
                            width="fill")
        file_name.when_left_button_released = text_click

        def complete_copy():
            destination = file_name.value
            save(0, destination)
            copy_window.destroy()

        ok_button = PushButton(copy_window, text="OK", command=complete_copy)
        cancel_button = PushButton(copy_window,
                                   text="cancel",
                                   command=copy_window.destroy)

    def text_click(box):
        key_pad.show(wait=True)
        key_pad.focus()
        text_input.value = box.widget.value
        make_keyboard("num", box)

    def save(is_it_from_save_butt, save_new_file):
        global json_file
        for values in json_file:
            if values == "stages":
                for subtitle in json_file[values]:
                    coords = []
                    for coord in json_file[values][subtitle]:
                        entry = coord.value
                        coords.append(int(entry))
                    json_file[values][subtitle] = coords
            elif values == "profile":
                list_of_coords = []
                for subtitle in json_file[values]:
                    coords = []
                    for coord in subtitle:
                        entry = coord.value
                        coords.append(int(entry))
                    list_of_coords.append(coords)
                json_file[values] = list_of_coords
            elif values == "temp_range" or values == "time_range":
                coords = []
                for coord in json_file[values]:
                    entry = coord.value
                    coords.append(int(entry))
                json_file[values] = coords
            else:
                entry = json_file[values].value
                json_file[values] = entry
        if is_it_from_save_butt == True:
            with open("profiles/" + file_display.value, mode="w") as fpr:
                json.dump(json_file, fpr)
                fpr.close()
            file_load(file_display.value)
        else:
            with open("profiles/" + save_new_file, mode="w") as fpr:
                json.dump(json_file, fpr)
                fpr.close()
            file_load(save_new_file)
            file_display.append(save_new_file)
            file_display.value = save_new_file

    def get_profile_list():
        f = []
        try:
            for (dirpath, dirnames, filenames) in os.walk("./profiles/"):
                f.extend(filenames)
                break
        except:
            return f
        return f

    def file_load(selected_file):
        global json_file
        while len(box2.children) > 0:
            for child in box2.children:
                child.destroy()
        with open("profiles/" + selected_file, mode="r") as fpr:
            json_file = json.load(fpr)
            fpr.close()
        row = 3
        for values in json_file:
            if values == "stages":
                row = 1
                entry = Text(box2, text=values, color="blue", grid=[3, row])
                entry = Text(box2, text="Time", color="yellow", grid=[5, row])
                entry = Text(box2,
                             text="Temperature",
                             color="yellow",
                             grid=[6, row])
                row += 1
                for subtitle in json_file[values]:
                    entry = Text(box2,
                                 text=subtitle,
                                 color="yellow",
                                 grid=[4, row])
                    x = 5
                    coords = []
                    for coord in json_file[values][subtitle]:
                        entry = TextBox(box2, coord, grid=[x, row])
                        entry.when_left_button_released = text_click
                        entry.bg = "white"
                        coords.append(entry)
                        x += 1
                    json_file[values][subtitle] = coords
                    row += 1
            elif values == "profile":
                row = 1
                entry = Text(box2, text=values, color="blue", grid=[7, row])
                entry = Text(box2, text="Time", color="yellow", grid=[8, row])
                entry = Text(box2,
                             text="Temperature",
                             color="yellow",
                             grid=[9, row])
                row += 1
                list_of_coords = []
                for subtitle in json_file[values]:
                    x = 8
                    coords = []
                    for coord in subtitle:
                        entry = TextBox(box2, coord, grid=[x, row])
                        entry.when_left_button_released = text_click
                        entry.bg = "white"
                        coords.append(entry)
                        x += 1
                    row += 1
                    list_of_coords.append(coords)

                def add_row():
                    global add_button
                    global subtract_button
                    global json_file
                    row = 2 + len(json_file["profile"])
                    x = 8
                    coords = []
                    for coord in range(0, 2):
                        entry = TextBox(box2, coord, grid=[x, row])
                        entry.when_left_button_released = text_click
                        entry.bg = "white"
                        coords.append(entry)
                        x += 1
                    row += 1
                    add_button.destroy()
                    subtract_button.destroy()
                    add_button = PushButton(box2,
                                            text="+",
                                            grid=[8, row],
                                            command=add_row)
                    add_button.bg = "white"
                    subtract_button = PushButton(box2,
                                                 text="-",
                                                 grid=[9, row],
                                                 command=subtract_row)
                    subtract_button.bg = "white"
                    json_file["profile"].append(coords)

                def subtract_row():
                    global add_button
                    global subtract_button
                    global json_file
                    row = len(json_file["profile"]) - 1
                    x = 8
                    coords = []
                    for coord in json_file["profile"][row]:
                        coord.destroy()
                        x += 1
                    json_file["profile"].pop()
                    row = len(json_file["profile"]) + 2
                    add_button.destroy()
                    subtract_button.destroy()
                    add_button = PushButton(box2,
                                            text="+",
                                            grid=[8, row],
                                            command=add_row)
                    add_button.bg = "white"
                    subtract_button = PushButton(box2,
                                                 text="-",
                                                 grid=[9, row],
                                                 command=subtract_row)
                    subtract_button.bg = "white"

                global add_button
                global subtract_button
                add_button = PushButton(box2,
                                        text="+",
                                        grid=[8, row],
                                        command=add_row)
                add_button.bg = "white"
                subtract_button = PushButton(box2,
                                             text="-",
                                             grid=[9, row],
                                             command=subtract_row)
                subtract_button.bg = "white"
                json_file[values] = list_of_coords
            elif values == "temp_range" or values == "time_range":
                entry = Text(box2, text=values, color="blue", grid=[0, row])
                entry = Text(box2, text="min", color="yellow", grid=[1, row])
                entry = Text(box2, text="max", color="yellow", grid=[2, row])
                row += 1
                x = 1
                coords = []
                for coord in json_file[values]:
                    entry = TextBox(box2, coord, grid=[x, row])
                    entry.when_left_button_released = text_click
                    entry.bg = "white"
                    coords.append(entry)
                    x += 1
                json_file[values] = coords
                row += 1

            else:
                entry = Text(box2, text=values, color="blue", grid=[0, row])
                entry = TextBox(box2, json_file[values], grid=[1, row])
                entry.when_left_button_released = text_click
                entry.bg = "white"
                json_file[values] = entry
                row += 1

    json_editor_window = Window(app,
                                bg="black",
                                width=800,
                                height=480,
                                layout="auto")
    Text(json_editor_window, text="Profile Editor", color="blue", size=15)
    box3 = Box(json_editor_window, layout="grid")
    file_display = Combo(box3,
                         options=get_profile_list(),
                         command=file_load,
                         grid=[0, 0])

    def delete_profile():
        global file_display
        os.remove("profiles/" + file_display.value)
        file_display.destroy()
        file_display = Combo(box3,
                             options=get_profile_list(),
                             command=file_load,
                             grid=[0, 0])
        file_display.size = 24
        file_display.bg = "white"
        file_load(file_display.value)

    delete_file = PushButton(box3,
                             grid=[1, 0],
                             command=delete_profile,
                             text="delete")
    delete_file.bg = "white"
    file_display.size = 24
    file_display.bg = "white"
    box1 = Box(json_editor_window)
    copy_button = PushButton(box1, command=copy, text="copy", align="left")
    copy_button.bg = "white"
    save_button = PushButton(box1,
                             command=save,
                             text="save",
                             enabled=True,
                             align="left",
                             args=[True, 0])
    save_button.bg = "white"
    box2 = Box(json_editor_window, layout="grid")
    # json_editor_window.set_full_screen()
    key_pad = Window(
        json_editor_window,
        title="key_pad",
        width=800,
        height=480,
    )
    # key_pad.set_full_screen()
    text_input = TextBox(key_pad, width="fill")
    key_pad.hide()

    def make_keyboard(key_board, field=0):
        def enter_text(text):
            old_string = text_input.value
            new_string = old_string + str(text)
            text_input.value = new_string

        key_box = Box(key_pad, layout="grid")

        def switch_keyboard(argument):
            # print("switch")
            key_box.destroy()
            cancel_button.destroy()
            ok_button.destroy()
            make_keyboard(argument, field)

        if key_board == "num":
            for button in range(0, 10):
                key_button = PushButton(key_box,
                                        text=str(button),
                                        padx=16,
                                        grid=[button % 3, button // 3 + 1],
                                        command=enter_text,
                                        args=[button])
                key_button.bg = "white"

            def back_space():
                old_string = text_input.value
                new_string = old_string[0:len(old_string) - 1]
                text_input.value = new_string

            key_button = PushButton(key_box,
                                    text="<X|",
                                    grid=[11 % 3, 11 // 3 + 1],
                                    command=back_space)
            key_button.bg = "white"
            key_button = PushButton(key_box,
                                    text="abc",
                                    grid=[10 % 3, 10 // 3 + 1],
                                    command=switch_keyboard,
                                    args=["alph"])
            key_button.bg = "white"
        elif key_board == "alph":
            row = 0
            characters = ["qwertyuiop[]", "asdfghjkl;'", "zxcvbnm,./", " "]
            for string in characters:
                column = 0
                if len(string) == 1:
                    button = string[0]
                    key_button = PushButton(key_box,
                                            text=str(button),
                                            padx=100,
                                            grid=[column, row, 12, 1],
                                            command=enter_text,
                                            args=[button])
                    key_button.bg = "white"
                else:
                    for button in string:
                        key_button = PushButton(key_box,
                                                text=str(button),
                                                padx=16,
                                                grid=[column, row],
                                                command=enter_text,
                                                args=[button])
                        key_button.bg = "white"
                        column += 1
                    if row == len(characters) - 2:
                        button = PushButton(key_box,
                                            text="shift",
                                            padx=16,
                                            grid=[column, row],
                                            command=switch_keyboard,
                                            args=["ALPH"])
                row += 1

            def back_space():
                old_string = text_input.value
                new_string = old_string[0:len(old_string) - 1]
                text_input.value = new_string

            key_button = PushButton(key_box,
                                    text="<X|",
                                    grid=[11 % 3, 11 // 3 + 1],
                                    command=back_space)
            key_button.bg = "white"
            key_button = PushButton(key_box,
                                    text="123",
                                    grid=[10 % 3, 10 // 3 + 1],
                                    command=switch_keyboard,
                                    args=["num"])
            key_button.bg = "white"
        elif key_board == "ALPH":
            row = 0
            characters = ["QWERTYUIOP{}", "ASDFGHJKL:'", "ZXCVBNM<>?", " "]
            for string in characters:
                column = 0
                if len(string) == 1:
                    button = string[0]
                    key_button = PushButton(key_box,
                                            text=str(button),
                                            padx=100,
                                            grid=[column, row, 12, 1],
                                            command=enter_text,
                                            args=[button])
                    key_button.bg = "white"
                else:
                    for button in string:
                        key_button = PushButton(key_box,
                                                text=str(button),
                                                padx=16,
                                                grid=[column, row],
                                                command=enter_text,
                                                args=[button])
                        key_button.bg = "white"
                        column += 1
                    if row == len(characters) - 2:
                        button = PushButton(key_box,
                                            text="shift",
                                            padx=16,
                                            grid=[column, row],
                                            command=switch_keyboard,
                                            args=["alph"])
                row += 1

            def back_space():
                old_string = text_input.value
                new_string = old_string[0:len(old_string) - 1]
                text_input.value = new_string

            key_button = PushButton(key_box,
                                    text="<X|",
                                    grid=[11 % 3, 11 // 3 + 1],
                                    command=back_space)
            key_button.bg = "white"
            key_button = PushButton(key_box,
                                    text="123",
                                    grid=[10 % 3, 10 // 3 + 1],
                                    command=switch_keyboard,
                                    args=["num"])
            key_button.bg = "white"

        def write_text(textbox):
            textbox.value = text_input.value
            key_pad.hide()
            cancel_button.destroy()
            ok_button.destroy()
            key_box.destroy()

        def cancel():
            key_pad.hide()
            cancel_button.destroy()
            ok_button.destroy()
            key_box.destroy()

        ok_button = PushButton(key_pad,
                               text="ok",
                               command=write_text,
                               args=[field.widget])
        cancel_button = PushButton(key_pad, text="cancel", command=cancel)
        key_pad.when_closed = cancel

    file_load(file_display.value)
    json_editor_window.display()
Ejemplo n.º 3
0
        json.dump(config, fpr)
        fpr.close()
    with open("profiles/" + config["profile"] + ".json", mode="r") as fpr:
        oven.sprofile = json.load(fpr)
        fpr.close()
    loadPlot()
    # print("plot loaded")


file_box_1 = Box(controls_box)

fileDisplay = Combo(file_box_1,
                    options=getProfileList(),
                    command=file_display_command,
                    align="left")
fileDisplay.size = 24
fileDisplay.bg = "white"


def editor_launcher():
    def copy():
        copy_window = Window(json_editor_window, title="create a copy")
        copy_window.show(wait=True)
        Text(copy_window, text="Name of copy :")
        file_name = TextBox(copy_window,
                            text=file_display.value,
                            enabled=True,
                            width="fill")
        file_name.when_left_button_released = text_click

        def complete_copy():