Beispiel #1
0
    def __init__(self, master):
        ttk.Frame.__init__(self, master)

        main_font = tkinter.font.nametofont("TkDefaultFont")

        bold_font = main_font.copy()
        bold_font.configure(weight="bold", size=main_font.cget("size"))

        h1_font = main_font.copy()
        h1_font.configure(size=main_font.cget("size") * 2, weight="bold")

        h2_font = main_font.copy()
        h2_font.configure(size=round(main_font.cget("size") * 1.5),
                          weight="bold")

        h3_font = main_font.copy()
        h3_font.configure(size=main_font.cget("size"), weight="bold")

        self.text = tktextext.TweakableText(self,
                                            border=0,
                                            padx=15,
                                            pady=15,
                                            font=main_font,
                                            wrap="word")

        self.text.tag_configure("h1", font=h1_font)
        self.text.tag_configure("h2", font=h2_font)
        self.text.tag_configure("h3", font=h3_font)
        self.text.grid(row=0, column=0, sticky="nsew")
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        self._vbar = ttk.Scrollbar(self, orient=tk.VERTICAL)
        self._vbar.grid(row=0, column=1, sticky=tk.NSEW)
        self._vbar['command'] = self.text.yview
        self.text['yscrollcommand'] = self._vbar.set

        self.load_rst_file("help.rst")
Beispiel #2
0
    def init_header(self, row, column):
        header_frame = ttk.Frame(self, style="ViewToolbar.TFrame")
        header_frame.grid(row=row, column=column, sticky="nsew")
        header_frame.columnconfigure(0, weight=1)

        self.path_bar = tktextext.TweakableText(
            header_frame,
            borderwidth=0,
            relief="flat",
            height=1,
            font="TkDefaultFont",
            wrap="word",
            padx=6,
            pady=5,
            insertwidth=0,
            highlightthickness=0,
            background=lookup_style_option("ViewToolbar.TFrame", "background"),
        )

        self.path_bar.grid(row=0, column=0, sticky="nsew")
        self.path_bar.set_read_only(True)
        self.path_bar.bind("<Configure>", self.resize_path_bar, True)
        self.path_bar.tag_configure("dir",
                                    foreground=lookup_style_option(
                                        "Url.TLabel", "foreground"))
        self.path_bar.tag_configure("underline", underline=True)

        def get_dir_range(event):
            mouse_index = self.path_bar.index("@%d,%d" % (event.x, event.y))
            return self.path_bar.tag_prevrange("dir", mouse_index + "+1c")

        def dir_tag_motion(event):
            self.path_bar.tag_remove("underline", "1.0", "end")
            dir_range = get_dir_range(event)
            if dir_range:
                range_start, range_end = dir_range
                self.path_bar.tag_add("underline", range_start, range_end)

        def dir_tag_enter(event):
            self.path_bar.config(cursor="hand2")

        def dir_tag_leave(event):
            self.path_bar.config(cursor="")
            self.path_bar.tag_remove("underline", "1.0", "end")

        def dir_tag_click(event):
            mouse_index = self.path_bar.index("@%d,%d" % (event.x, event.y))
            lineno = int(float(mouse_index))
            if lineno == 1:
                self.request_focus_into("")
            else:
                assert lineno == 2
                dir_range = get_dir_range(event)
                if dir_range:
                    _, end_index = dir_range
                    path = self.path_bar.get("2.0", end_index)
                    if path.endswith(":"):
                        path += "\\"
                    self.request_focus_into(path)

        self.path_bar.tag_bind("dir", "<1>", dir_tag_click)
        self.path_bar.tag_bind("dir", "<Enter>", dir_tag_enter)
        self.path_bar.tag_bind("dir", "<Leave>", dir_tag_leave)
        self.path_bar.tag_bind("dir", "<Motion>", dir_tag_motion)

        # self.menu_button = ttk.Button(header_frame, text="≡ ", style="ViewToolbar.Toolbutton")
        self.menu_button = ttk.Button(header_frame,
                                      text=" ≡ ",
                                      style="ViewToolbar.Toolbutton",
                                      command=self.post_button_menu)
        # self.menu_button.grid(row=0, column=1, sticky="ne")
        self.menu_button.place(anchor="ne", rely=0, relx=1)
Beispiel #3
0
    def __init__(self,
                 master,
                 show_hidden_files=False,
                 last_folder_setting_name=None):
        ttk.Frame.__init__(self, master, borderwidth=0, relief="flat")
        self.vert_scrollbar = ttk.Scrollbar(self,
                                            orient=tk.VERTICAL,
                                            style=scrollbar_style("Vertical"))
        self.vert_scrollbar.grid(row=0, column=1, sticky=tk.NSEW, rowspan=4)

        self.toolbar = ttk.Frame(self, style="ViewToolbar.TFrame")
        self.toolbar.grid(row=0, sticky="nsew")
        self.toolbar.grid(row=1, sticky="nsew")
        self.init_toolbar()

        tktextext.fixwordbreaks(tk._default_root)
        self.building_breadcrumbs = False
        self.path_bar = tktextext.TweakableText(self,
                                                borderwidth=0,
                                                relief="flat",
                                                height=1,
                                                font="TkDefaultFont",
                                                wrap="word",
                                                padx=6)
        self.init_path_bar()

        self.set_breadcrumbs(
            "This computer\\C:\\Users\\Aivar\\Documents\\Python\\PyGame\\NikaNaka"
        )

        self.path_bar.grid(row=2, sticky="nsew")

        self.tree = ttk.Treeview(
            self,
            columns=["#0", "kind", "path"],
            displaycolumns=(0, ),
            yscrollcommand=self.vert_scrollbar.set,
        )
        self.tree["show"] = "headings"
        self.tree.grid(row=3, column=0, sticky=tk.NSEW)
        self.vert_scrollbar["command"] = self.tree.yview
        self.columnconfigure(0, weight=1)
        self.rowconfigure(3, weight=1)

        self.show_hidden_files = show_hidden_files
        self.tree["show"] = ("tree", )

        wb = get_workbench()
        self.folder_icon = wb.get_image("folder")
        self.python_file_icon = wb.get_image("python-file")
        self.text_file_icon = wb.get_image("text-file")
        self.generic_file_icon = wb.get_image("generic-file")
        self.hard_drive_icon = wb.get_image("hard-drive")

        self.tree.column("#0", width=500, anchor=tk.W)

        # set-up root node
        self.tree.set("", "kind", "root")
        self.tree.set("", "path", "")
        self.refresh_tree()

        self.tree.bind("<<TreeviewOpen>>", self.on_open_node)

        self._last_folder_setting_name = last_folder_setting_name
        self.open_initial_folder()