-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonManager.py
More file actions
99 lines (83 loc) · 4.12 KB
/
Copy pathButtonManager.py
File metadata and controls
99 lines (83 loc) · 4.12 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import tkinter as tk
import os
__all__ = ["ButtonManager"]
class ButtonManager:
def __init__(self, text):
self.text = text
self.text.tag_config("folder", background="gray30", foreground="#A4541D", justify=tk.LEFT, font=("Ariel", 10, "bold"),
lmargin1="15", spacing1=2, spacing3=2)
self.text.tag_config("file", background="gray30", foreground="#1DA498", justify=tk.LEFT, font=("Ariel", 10, "bold"),
lmargin1="15", spacing1=2, spacing3=2)
self.text.tag_bind("folder", "<Enter>", self._enter)
self.text.tag_bind("folder", "<Leave>", self._leave)
self.text.tag_bind("folder", "<Button-1>", self._click)
self.text.tag_bind("file", "<Enter>", self._enter)
self.text.tag_bind("file", "<Leave>", self._leave)
self.text.tag_bind("file", "<Button-1>", self._click)
self.folder = {}
self.file = {}
def reset(self):
self.folder.clear()
self.file.clear()
def add(self, action, folder):
tag = "folder-%d" % len(self.folder)
self.folder[tag] = [action, folder]
return "folder", tag
def addFile(self, action, file):
tag = "file-%s" % len(self.file)
current = "current-%s" % len(self.file)
self.file[tag] = [action, file]
return "file", current, tag
def _enter(self, event):
# self._leave()
self.text.config(cursor="hand2")
for tag in self.text.tag_names(tk.CURRENT):
if tag[:7] == "folder-":
self.text.tag_config(tag, background="blue", foreground="#A4541D", justify=tk.LEFT,
font=("Ariel", 10, "bold"), lmargin1="15")
return
elif tag[:5] == "file-":
self.text.tag_config(tag, background="blue", foreground="#1DA498", justify=tk.LEFT,
font=("Ariel", 10, "bold"), lmargin1="15")
return
def _leave(self, event=""):
self.text.config(cursor="")
for tag in self.text.tag_names():
if tag[:7] == "folder-":
self.text.tag_config(tag, background="gray30", foreground="#A4541D", justify=tk.LEFT,
font=("Ariel", 10, "bold"), lmargin1="15")
elif tag[:5] == "file-":
self.text.tag_config(tag, background="gray30", foreground="#1DA498", justify=tk.LEFT,
font=("Ariel", 10, "bold"), lmargin1="15")
def _click(self, event):
for tag in self.text.tag_names(tk.CURRENT):
if tag[:7] == "folder-":
self.folder[tag][0](self.folder[tag][1])
return
elif tag[:5] == "file-":
for current in self.text.tag_names():
if current[:8] == "current-":
self.text.tag_lower(current)
self.file[tag][0](self.file[tag][1])
self.text.tag_raise(f"current-{tag[5:]}")
self.text.tag_config(f"current-{tag[5:]}", background="blue", foreground="#1DA498", justify=tk.LEFT,
font=("Ariel", 10, "bold"), lmargin1="15")
return
def scroll(self, checked):
for key, value in self.file.items():
for val in value:
if val == checked:
tag = key
try:
if tag[:5] == "file-":
for current in self.text.tag_names():
if current[:8] == "current-":
self.text.tag_lower(current)
self.file[tag][0](self.file[tag][1])
self.text.tag_raise(f"current-{tag[5:]}")
self.text.tag_config(f"current-{tag[5:]}", background="blue", foreground="#1DA498", justify=tk.LEFT,
font=("Ariel", 10, "bold"), lmargin1="15")
self.text.see(self.text.search(f"- {os.path.split(checked)[-1]}\n", 1.0))
return
except ValueError:
return