Skip to content

Commit b4a179e

Browse files
committed
Merge branch 'fix_style'
2 parents 9bd5cf3 + 243bef0 commit b4a179e

5 files changed

Lines changed: 23 additions & 35 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
long_description = f.read()
1313

1414
setup(name='tkfilebrowser',
15-
version='2.2.4',
15+
version='2.2.5',
1616
description='File browser for Tkinter, alternative to tkinter.filedialog in linux with GTK bookmarks support.',
1717
long_description=long_description,
1818
url='https://github.com/j4321/tkFileBrowser',

tests/test_tooltip.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
class TestTooltip(BaseWidgetTest):
1111
def test_tooltip(self):
12-
t = Tooltip(self.window, background='white', foreground='black')
12+
t = Tooltip(self.window)
1313
self.window.update()
14-
t.configure(text='Hello', background='black', foreground='white',
15-
image=None, alpha=0.75)
14+
t.configure(text='Hello', image=None, alpha=0.75)
1615

1716

1817
class TestTooltipTreeWrapper(BaseWidgetTest):
@@ -22,7 +21,7 @@ def test_tooltiptreewrapper(self):
2221
tree.insert("", "end", "1", text="item 1")
2322
tree.insert("", "end", "2", text="item 2")
2423
self.window.update()
25-
tw = TooltipTreeWrapper(tree, background='white', foreground='black')
24+
tw = TooltipTreeWrapper(tree)
2625
tw.add_tooltip("1", "tooltip 1")
2726
tw.add_tooltip("2", "tooltip 2")
2827
self.window.update()

tkfilebrowser/filebrowser.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
135135
style.configure("left.tkfilebrowser.Treeview.Heading",
136136
font="TkDefaultFont")
137137
style.configure("left.tkfilebrowser.Treeview.Item", padding=2)
138-
style.configure("listbox.TFrame", background="white", relief="sunken")
138+
style.configure("listbox.tkfilebrowser.TFrame", background="white", relief="sunken")
139139
field_bg = style.lookup("TEntry", "fieldbackground", default='white')
140140
tree_field_bg = style.lookup("ttk.Treeview", "fieldbackground",
141141
default='white')
@@ -145,22 +145,25 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
145145
sel_fg = style.lookup('Treeview', 'foreground', ('selected',))
146146
self.option_add('*TCombobox*Listbox.selectBackground', sel_bg)
147147
self.option_add('*TCombobox*Listbox.selectForeground', sel_fg)
148-
style.map('types.TCombobox', foreground=[], fieldbackground=[])
149-
style.configure('types.TCombobox', lightcolor=bg,
148+
style.map('types.tkfilebrowser.TCombobox', foreground=[], fieldbackground=[])
149+
style.configure('types.tkfilebrowser.TCombobox', lightcolor=bg,
150150
fieldbackground=bg)
151-
style.configure('types.TCombobox.Item', background='red')
151+
style.configure('types.tkfilebrowser.TCombobox.Item', background='red')
152152
style.configure("left.tkfilebrowser.Treeview", background=active_bg,
153153
font="TkDefaultFont",
154154
fieldbackground=active_bg)
155155
self.configure(background=bg)
156156
# path button style
157-
style.configure("path.TButton", padding=2)
157+
style.configure("path.tkfilebrowser.TButton", padding=2)
158158
selected_bg = style.lookup("TButton", "background", ("pressed",))
159159
map_bg = style.map("TButton", "background")
160160
map_bg.append(("selected", selected_bg))
161-
style.map("path.TButton",
161+
style.map("path.tkfilebrowser.TButton",
162162
background=map_bg,
163163
font=[("selected", "TkDefaultFont 9 bold")])
164+
# tooltip style
165+
style.configure('tooltip.tkfilebrowser.TLabel', background='black',
166+
foreground='white')
164167

165168
# --- images
166169
self.im_file = tk.PhotoImage(file=cst.IM_FILE, master=self)
@@ -185,7 +188,7 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
185188
w = max([len(f) for f in values] + [5])
186189
b_filetype = ttk.Combobox(self, textvariable=self.filetype,
187190
state='readonly',
188-
style='types.TCombobox',
191+
style='types.tkfilebrowser.TCombobox',
189192
values=values,
190193
width=w)
191194
b_filetype.grid(row=3, sticky="e", padx=10, pady=(4, 0))
@@ -203,7 +206,7 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
203206
# --- path completion
204207
self.complete = self.register(self._completion)
205208
self.listbox_var = tk.StringVar(self)
206-
self.listbox_frame = ttk.Frame(self, style="listbox.TFrame", borderwidth=1)
209+
self.listbox_frame = ttk.Frame(self, style="listbox.tkfilebrowser.TFrame", borderwidth=1)
207210
self.listbox = tk.Listbox(self.listbox_frame,
208211
listvariable=self.listbox_var,
209212
highlightthickness=0,
@@ -265,8 +268,7 @@ def __init__(self, parent, initialdir="", initialfile="", mode="openfile",
265268
paned.add(left_pane, weight=0)
266269
self.left_tree = ttk.Treeview(left_pane, selectmode="browse",
267270
style="left.tkfilebrowser.Treeview")
268-
wrapper = TooltipTreeWrapper(self.left_tree, background='black',
269-
foreground='white')
271+
wrapper = TooltipTreeWrapper(self.left_tree)
270272
self.left_tree.column("#0", width=150)
271273
self.left_tree.heading("#0", text=_("Shortcuts"), anchor="w")
272274
self.left_tree.grid(row=0, column=0, sticky="sewn")
@@ -926,7 +928,7 @@ def _update_path_bar(self, path):
926928
b = PathButton(self.path_bar, self.path_var, p, text=folder,
927929
width=len(folder) + 1,
928930
command=lambda f=p: self.display_folder(f),
929-
style="path.TButton")
931+
style="path.tkfilebrowser.TButton")
930932
self.path_bar_buttons.append(b)
931933
b.grid(row=0, column=i + 2, sticky="ns")
932934

tkfilebrowser/path_button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, parent, variable, value, **kwargs):
4242
to value
4343
* all ttk.Button options
4444
"""
45-
kwargs["style"] = "path.TButton"
45+
kwargs["style"] = "path.tkfilebrowser.TButton"
4646
ttk.Button.__init__(self, parent, **kwargs)
4747
self.variable = variable
4848
self.value = value

tkfilebrowser/tooltip.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def __init__(self, parent, **kwargs):
3333
3434
Options:
3535
* parent: parent window
36-
* background: background color
37-
* foreground: foreground color
3836
* image: PhotoImage/BitmapImage to display in the tooltip
3937
* text: text (str) to display in the tooltip
4038
* compound: relative orientation of the graphic relative to the text
@@ -46,33 +44,22 @@ def __init__(self, parent, **kwargs):
4644
self.attributes('-type', 'tooltip')
4745
self.attributes('-alpha', kwargs.get('alpha', 0.8))
4846
self.overrideredirect(True)
49-
self.configure(padx=kwargs.get('padx', 4))
50-
self.configure(pady=kwargs.get('pady', 4))
47+
style = kwargs.get('style', 'tooltip.tkfilebrowser.TLabel')
5148

52-
self.style = ttk.Style(self)
53-
if 'background' in kwargs:
54-
bg = kwargs['background']
55-
self.configure(background=bg)
56-
self.style.configure('tooltip.TLabel', background=bg)
57-
if 'foreground' in kwargs:
58-
self.style.configure('tooltip.TLabel', foreground=kwargs['foreground'])
49+
bg = ttk.Style(self).lookup(style, 'background')
50+
self.configure(background=bg)
5951

6052
self.im = kwargs.get('image', None)
6153
self.label = ttk.Label(self, text=kwargs.get('text', ''), image=self.im,
62-
style='tooltip.TLabel',
63-
compound=kwargs.get('compound', 'left'))
54+
style=style, compound=kwargs.get('compound', 'left'),
55+
padding=kwargs.get('padding', 4))
6456
self.label.pack()
6557

6658
def configure(self, **kwargs):
6759
if 'text' in kwargs:
6860
self.label.configure(text=kwargs.pop('text'))
6961
if 'image' in kwargs:
7062
self.label.configure(image=kwargs.pop('image'))
71-
if 'background' in kwargs:
72-
self.style.configure('tooltip.TLabel', background=kwargs['background'])
73-
if 'foreground' in kwargs:
74-
fg = kwargs.pop('foreground')
75-
self.style.configure('tooltip.TLabel', foreground=fg)
7663
if 'alpha' in kwargs:
7764
self.attributes('-alpha', kwargs.pop('alpha'))
7865
tk.Toplevel.configure(self, **kwargs)

0 commit comments

Comments
 (0)