예제 #1
0
 def body(self, master):
     self.memory_textbox = ScrolledText(master, height=3)
     self.memory_textbox.grid(row=master.grid_size()[1],
                              column=0,
                              columnspan=2)
     self.memory_textbox.configure(
         font=Font(
             family="Georgia",
             size=12),  # Other nice options: Helvetica, Arial, Georgia
         spacing1=10,
         foreground=text_color(),
         background=bg_color(),
         padx=3,
         pady=3,
         spacing2=3,  # Spacing between lines
         spacing3=5,
         wrap="word",
     )
     self.memory_textbox.insert(tk.INSERT, self.memory['text'])
     self.memory_textbox.focus()
     row = master.grid_size()[1]
     create_side_label(master, "Inheritability", row)
     inheritability_options = ('none', 'subtree', 'delayed')
     self.inheritability.set(self.memory['inheritability'])
     dropdown = tk.OptionMenu(master, self.inheritability,
                              *inheritability_options)
     dropdown.grid(row=row, column=1, pady=3)
     self.delete_button = create_button(master,
                                        "Delete memory",
                                        self.delete_memory,
                                        width=15)
예제 #2
0
    def body(self, master):
        self.master = master

        # TODO
        # advanced options - show/hide
        # search ancestry
        create_side_label(master, "Subtree only")
        check = ttk.Checkbutton(master, variable=self.subtree)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)

        create_side_label(master, "Case sensitive")
        check = ttk.Checkbutton(master, variable=self.case_sensitive)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)
        create_side_label(master, "Search text")
        check = ttk.Checkbutton(master, variable=self.text)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)
        create_side_label(master, "Search chapter titles")
        check = ttk.Checkbutton(master, variable=self.chapters)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)
        create_side_label(master, "Search tags")
        check = ttk.Checkbutton(master, variable=self.tags)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)
        create_side_label(master, "Canonical only")
        check = ttk.Checkbutton(master, variable=self.canonical)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)
        create_side_label(master, "Regex")
        check = ttk.Checkbutton(master, variable=self.regex)
        check.grid(row=self.master.grid_size()[1] - 1, column=1)

        self.depth_limit = Entry(master,
                                 master.grid_size()[1],
                                 "Max depth",
                                 "",
                                 None,
                                 width=5)

        self.search_entry = Entry(master,
                                  master.grid_size()[1],
                                  "Search",
                                  "",
                                  None,
                                  width=20)
        self.search_entry.focus_entry()
        create_button(master, "Search", self.search)
예제 #3
0
 def body(self, master):
     self.master = master
     button = create_button(master, "Add media", self.add_media)
     button.grid(row=1, column=1, sticky='w')
     #if self.num_media() > 0:
     #img, caption = self.display_image()
     self.create_image()
     self.display_image()
     self.create_buttons()
     self.set_buttons()
예제 #4
0
    def body(self, master):
        sliders = {
            'textwidth': (10, 1000),
            'leafdist': (1, 500),
            'leveldistance': (1, 500),
            'textsize': (1, 25),
        }
        for name, value_range in sliders.items():
            create_slider(master, name, self.vars[name], value_range)

        for name in [
                'horizontal', 'displaytext', 'showbuttons', 'chaptermode'
        ]:
            row = master.grid_size()[1]
            create_side_label(master, name, row)
            check = ttk.Checkbutton(master, variable=self.vars[name])
            check.grid(row=row, column=1, pady=3)

        create_button(master, "Reset", self.reset_variables)
예제 #5
0
    def body(self, master):
        sliders = {
            'num_continuations': (1, 20),
            'temperature': (0., 1.),
            'top_p': (0., 1.),
            'response_length': (1, 1000),
            'prompt_length': (100, 10000),
        }
        for name, value_range in sliders.items():
            create_slider(master, name, self.vars[name], value_range)

        row = master.grid_size()[1]
        create_side_label(master, "Use Janus?", row)
        check = ttk.Checkbutton(master, variable=self.vars["janus"])
        check.grid(row=row, column=1, pady=3)
        create_side_label(master, "Adaptive branching", row + 1)
        check2 = ttk.Checkbutton(master, variable=self.vars["adaptive"])
        check2.grid(row=row + 1, column=1, pady=3)

        create_combo_box(master,
                         "Model",
                         self.vars["model"],
                         POSSIBLE_MODELS,
                         width=20)

        # create_label(master, "Memory")
        # self.memory_textbox = ScrolledText(master, height=7)
        # self.memory_textbox.grid(row=master.grid_size()[1], column=0, columnspan=2)
        # self.memory_textbox.configure(
        #     font=Font(family="Georgia", size=12),  # Other nice options: Helvetica, Arial, Georgia
        #     spacing1=10,
        #     foreground=text_color(),  # Darkmode
        #     background=bg_color(),
        #     padx=3,
        #     pady=3,
        #     spacing2=5,  # Spacing between lines
        #     spacing3=5,
        #     wrap="word",
        # )
        # self.memory_textbox.insert("1.0", self.orig_params["memory"])

        create_button(master, "Reset", self.reset_variables)
예제 #6
0
    def refresh(self):
        if self.new_button:
            self.new_button.destroy()
        for memory in self.memories:
            memory.destroy()
        for check in self.checks:
            check.destroy()
        for edit_button in self.edit_buttons:
            edit_button.destroy()
        self.memories = []
        self.checks = []
        self.edit_buttons = []

        for i, memory in enumerate(self.state.construct_memory(self.node)):
            if memory['text']:
                temp_check = tk.BooleanVar()
                temp_check.set(True)
                row = self.master.grid_size()[1]
                self.memories.append(TextAware(self.master, height=1))
                self.memories[i].grid(row=row, column=0, columnspan=2, padx=5)
                self.memories[i].insert(tk.INSERT, memory['text'])
                self.memories[i].configure(
                    state='disabled',
                    foreground=text_color(),
                    background=bg_color(),
                    wrap="word",
                )
                # FIXME checks are unchecked by default
                self.checks.append(
                    tk.Checkbutton(self.master, variable=temp_check))
                self.checks[i].grid(row=row, column=2, padx=3)
                self.edit_buttons.append(
                    create_button(
                        self.master,
                        "Edit",
                        lambda _memory=memory: self.edit_memory(_memory),
                        width=4))
                self.edit_buttons[i].grid(row=row, column=3)
        self.new_button = create_button(self.master,
                                        "Add memory",
                                        self.create_new,
                                        width=11)
예제 #7
0
    def refresh(self):
        if self.new_button:
            self.new_button.destroy()
        for memory in self.memories:
            memory.destroy()
        for edit_button in self.edit_buttons:
            edit_button.destroy()
        self.memories = []
        self.checks = []
        self.edit_buttons = []

        if 'memories' in self.node:
            for i, memory_id in enumerate(self.node['memories']):
                memory = self.state.memories[memory_id]
                if memory['text']:
                    row = self.master.grid_size()[1]
                    self.memories.append(TextAware(self.master, height=1))
                    self.memories[i].grid(row=row,
                                          column=0,
                                          columnspan=2,
                                          padx=5)
                    self.memories[i].insert(tk.INSERT, memory['text'])
                    self.memories[i].configure(
                        state='disabled',
                        foreground=text_color(),
                        background=bg_color(),
                        wrap="word",
                    )
                    self.edit_buttons.append(
                        create_button(
                            self.master,
                            "Edit",
                            lambda _memory=memory: self.edit_memory(_memory),
                            width=4))
                    self.edit_buttons[i].grid(row=row, column=3)
        self.new_button = create_button(self.master,
                                        "Add memory",
                                        self.create_new,
                                        width=11)
예제 #8
0
 def create_buttons(self):
     self.next_button = create_button(self.master, "Next",
                                      lambda: self.traverse(1))
     self.next_button.grid(row=4, column=1, sticky='e')
     self.prev_button = create_button(self.master, "Prev",
                                      lambda: self.traverse(-1))
     self.prev_button.grid(row=4, column=1, sticky='w')
     self.move_up_button = create_button(self.master, "Move >",
                                         lambda: self.shift(1))
     self.move_up_button.grid(row=5, column=1, sticky='e')
     self.move_down_button = create_button(self.master, "< Move",
                                           lambda: self.shift(-1))
     self.move_down_button.grid(row=5, column=1, sticky='w')
     self.caption_button = create_button(self.master, "Change caption",
                                         self.change_caption)
     self.caption_button.grid(row=5, column=1)
     self.caption_button.config(width=15)
     self.delete_button = create_button(self.master, "Delete",
                                        self.delete_media)
     self.delete_button.grid(row=1, column=1, sticky='e')
예제 #9
0
    def search_results(self, matches, start=0):
        # remove previous search results
        context_padding = 50
        limit = 4
        counter = 0
        if self.num_results_label:
            self.num_results_label.destroy()
        if self.next_page_button:
            self.next_page_button.destroy()
        if self.prev_page_button:
            self.prev_page_button.destroy()
        for result in self.results:
            result.destroy()
        for label in self.labels:
            label.destroy()
        for button in self.goto_buttons:
            button.destroy()
        self.results = []
        self.labels = []
        self.goto_buttons = []
        self.num_results_label = create_side_label(self.master,
                                                   f'{len(matches)} results')
        for i, match in enumerate(matches[start:]):
            if counter >= limit:
                break
            node = self.state.tree_node_dict[match['node_id']]
            self.labels.append(
                create_side_label(
                    self.master,
                    f"chapter: {self.state.chapter(node)['title']}"))
            #side_label.config(fg="blue")
            self.results.append(TextAware(self.master, height=2))
            #readable_font = Font(family="Georgia", size=12)
            self.results[i].configure(
                #font=readable_font,
                spacing1=8,
                foreground=text_color(),
                background=bg_color(),
                wrap="word",
            )
            self.results[i].grid(row=self.master.grid_size()[1] - 1, column=1)
            node_text = node["text"]
            start_index = max(0, match['span'][0] - context_padding)
            end_index = min(len(node_text), match['span'][1] + context_padding)
            text_window = node_text[start_index:end_index]
            self.results[i].insert(tk.INSERT, text_window)
            self.results[i].tag_configure("blue", background="blue")
            self.results[i].highlight_pattern(match['match'], "blue")
            self.results[i].configure(state='disabled')

            # makes text copyable
            # binding causes computer to freeze
            #self.results[i].bind("<Button>", lambda event, _result=self.results[i]: result.focus_set())
            #matched_text.bind("<Alt-Button-1>", lambda event: self.goto_result(match['node_id']))

            self.goto_buttons.append(
                create_button(
                    self.master,
                    "go to match",
                    lambda _match=match: self.goto_result(_match['node_id'])))
            self.goto_buttons[i].grid(row=self.master.grid_size()[1] - 2,
                                      column=2)
            counter += 1
        if start > 0:
            self.prev_page_button = create_button(
                self.master,
                "previous page",
                lambda _start=start, _limit=limit: self.search_results(
                    matches, start=_start - _limit))
            self.prev_page_button.config(width=12)
        if len(matches) > start + limit:
            self.next_page_button = create_button(
                self.master,
                "next page",
                lambda _start=start, _limit=limit: self.search_results(
                    matches, start=_start + _limit))