Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def test_fontchooser_init(self):
text='Abcd' * 20, title='Test')
self.window.update()

def test_fontchooser_init_only_fixed(self):
FontChooser(self.window,
{'family': 'Arial', 'weight': 'bold', 'slant': 'italic'},
text='Abcd' * 20, title='Test', only_fixed=True)
self.window.update()

def test_fontchooser_methods(self):
props = {'family': "TkDefaultFont", 'weight': 'bold', 'size': 27,
'slant': 'italic'}
Expand Down
15 changes: 12 additions & 3 deletions tkfontchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FontChooser(Toplevel):
"""Font chooser dialog."""

def __init__(self, master, font_dict={}, text="Abcd", title="Font Chooser",
**kwargs):
only_fixed=False, **kwargs):
"""
Create a new FontChooser instance.

Expand Down Expand Up @@ -101,8 +101,17 @@ def __init__(self, master, font_dict={}, text="Abcd", title="Font Chooser",
self.configure(bg=bg)

# --- family list
self.fonts = list(set(families()))
self.fonts.append("TkDefaultFont")
if only_fixed:
all_families = list(set(families()))
self.fonts = []
for ffamily in all_families:
fnt = Font(family=ffamily)
is_fixed = fnt.metrics('fixed')
if (is_fixed != 0):
self.fonts.append(ffamily)
else:
self.fonts = list(set(families()))
self.fonts.append("TkDefaultFont")
self.fonts.sort()
for i in range(len(self.fonts)):
self.fonts[i] = self.fonts[i].replace(" ", "\ ")
Expand Down