Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdot/ui/elements: Bugfix: Check if GTK default settings are Null #124

Merged
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
10 changes: 7 additions & 3 deletions xdot/ui/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def get_text(self):
class TextShape(Shape):

LEFT, CENTER, RIGHT = -1, 0, 1
DEFAULT_FONTNAME = Gtk.Settings.get_default().get_property("gtk-font-name")

def __init__(self, pen, x, y, j, w, t):
Shape.__init__(self)
Expand All @@ -111,6 +110,11 @@ def __init__(self, pen, x, y, j, w, t):
self.j = j # Centering
self.w = w # width
self.t = t # text
default_settings = Gtk.Settings.get_default()
if default_settings:
self.default_fontname = default_settings.get_property("gtk-font-name")
else:
self.default_fontname = self.pen.fontname

def _font_available(self, fontname, pango_context):
available_fonts = [family.get_name() for family in pango_context.list_families()]
Expand Down Expand Up @@ -169,10 +173,10 @@ def _draw(self, cr, highlight, bounding):
else:
msg = "Font family {fontname!r} is not available, using {default!r}".format(
fontname=self.pen.fontname,
default=self.DEFAULT_FONTNAME
default=self.default_fontname
)
warnings.warn(msg)
font.set_family(self.DEFAULT_FONTNAME)
font.set_family(self.default_fontname)

font.set_absolute_size(self.pen.fontsize*Pango.SCALE)
layout.set_font_description(font)
Expand Down
Loading