-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.py
More file actions
74 lines (54 loc) · 2.28 KB
/
widgets.py
File metadata and controls
74 lines (54 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""This contains all the smaller custom widgets that the dialog needs."""
import tkinter
from tkinter import ttk
class PathHistory(ttk.Frame):
"""The widget that shows the path history, and enables users to go back to
directories that they've already visited."""
def __init__(self, *args, path, **kwargs):
super().__init__(*args, **kwargs)
# The path we're showing
self.path = path
# The arrow buttons
self.left_button = tkinter.Button(self, text="<")
self.left_button.grid(row=0, column=0, sticky="w")
self.right_button = tkinter.Button(self, text=">")
self.right_button.grid(row=0, column=2, sticky="e")
# The frame containing the buttons for each step in the path
self.buttons_frame = ttk.Frame(self)
self.buttons_frame.grid(row=0, column=1, sticky="ew")
# The list of path-step buttons
self.buttons = []
# Show our path
self.show_path(self.path)
def show_path(self, path):
"""Show the path."""
# Remove all the old buttons
for button in self.buttons:
button.destroy()
# Reset the list of buttons
self.buttons = []
# Create the list of path elements we're going to show, limited to six elements
elements = []
for element in path.split("/"):
if element != "":
elements.append(element)
elements = elements[-6:]
# Show the buttons
for element in elements:
button = ttk.Button(self.buttons_frame, text=element)
button.pack(side="left")
self.buttons.append(button)
# Set our path variable
self.path = path
class SearchEntry(ttk.Entry):
"""The entry for the search widget. Has some "special" functionality that's
included in every other text widget on the operating system but is lacking
in `tkinter` for some stupid reason."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Set all the keybindings
self.bind("<Control-a>", self.select_all)
def select_all(self, event=None):
"""Select all the text in the entry."""
self.select_range("0", "end")
return "break"