GTK3 fix. Workaround for bug https://bugzilla.gnome.org/show_bug.cgi?id=679654 which prevents list_families() being called more than once to generate a list of fonts. Text reports and anything else which uses the PDF backend now works
svn: r20212
This commit is contained in:
parent
ea5dcfd4ae
commit
aa1729d364
@ -41,6 +41,7 @@ from gen.ggettext import gettext as _
|
|||||||
# GNOME/GTK
|
# GNOME/GTK
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from gi.repository import PangoCairo
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -296,6 +297,47 @@ class ProgressMeter(object):
|
|||||||
"""
|
"""
|
||||||
self.__dialog.destroy()
|
self.__dialog.destroy()
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# SystemFonts class
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class SystemFonts(object):
|
||||||
|
"""
|
||||||
|
Define fonts available to Gramps
|
||||||
|
|
||||||
|
This is a workaround for bug which prevents the list_families method
|
||||||
|
being called more than once.
|
||||||
|
|
||||||
|
The bug is described here: https://bugzilla.gnome.org/show_bug.cgi?id=679654
|
||||||
|
|
||||||
|
This code generate a warning:
|
||||||
|
/usr/local/lib/python2.7/site-packages/gi/types.py:47:
|
||||||
|
Warning: g_value_get_object: assertion `G_VALUE_HOLDS_OBJECT (value)' failed
|
||||||
|
|
||||||
|
To get a list of fonts, instantiate this class and call get_system_fonts()
|
||||||
|
#TODO GTK3: the underlying bug may be fixed at some point in the future
|
||||||
|
"""
|
||||||
|
|
||||||
|
__FONTS = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Populate the class variable __FONTS only once.
|
||||||
|
"""
|
||||||
|
if SystemFonts.__FONTS is None:
|
||||||
|
families = PangoCairo.font_map_get_default().list_families()
|
||||||
|
print ('GRAMPS GTK3: a g_value_get_object warning:')
|
||||||
|
SystemFonts.__FONTS = [family.get_name() for family in families]
|
||||||
|
SystemFonts.__FONTS.sort()
|
||||||
|
|
||||||
|
def get_system_fonts(self):
|
||||||
|
"""
|
||||||
|
Return a sorted list of fonts available to Gramps
|
||||||
|
"""
|
||||||
|
return SystemFonts.__FONTS
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -61,6 +61,7 @@ from gui.widgets.toolcomboentry import ToolComboEntry
|
|||||||
from gui.widgets.springseparator import SpringSeparatorAction
|
from gui.widgets.springseparator import SpringSeparatorAction
|
||||||
from gui.spell import Spell
|
from gui.spell import Spell
|
||||||
from gui.display import display_url
|
from gui.display import display_url
|
||||||
|
from gui.utils import SystemFonts
|
||||||
from gen.config import config
|
from gen.config import config
|
||||||
from gen.constfunc import has_display
|
from gen.constfunc import has_display
|
||||||
|
|
||||||
@ -175,24 +176,12 @@ class StyledTextEditor(Gtk.TextView):
|
|||||||
(GObject.TYPE_PYOBJECT,)), # arguments
|
(GObject.TYPE_PYOBJECT,)), # arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
FONTS = None
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Setup initial instance variable values."""
|
"""Setup initial instance variable values."""
|
||||||
self.textbuffer = UndoableStyledBuffer()
|
self.textbuffer = UndoableStyledBuffer()
|
||||||
self.textbuffer.connect('style-changed', self._on_buffer_style_changed)
|
self.textbuffer.connect('style-changed', self._on_buffer_style_changed)
|
||||||
self.textbuffer.connect('changed', self._on_buffer_changed)
|
self.textbuffer.connect('changed', self._on_buffer_changed)
|
||||||
GObject.GObject.__init__(self, buffer=self.textbuffer)
|
GObject.GObject.__init__(self, buffer=self.textbuffer)
|
||||||
if StyledTextEditor.FONTS is None:
|
|
||||||
#TODO GTK3: How to do this different?
|
|
||||||
#workaround for bug https://bugzilla.gnome.org/show_bug.cgi?id=679654
|
|
||||||
#but still gives error on output:
|
|
||||||
#/usr/local/lib/python2.7/site-packages/gi/types.py:47:
|
|
||||||
# Warning: g_value_get_object: assertion `G_VALUE_HOLDS_OBJECT (value)' failed
|
|
||||||
print ('GRAMPS GTK3: a g_value_get_object warning:')
|
|
||||||
StyledTextEditor.FONTS = [f.get_name() for f in
|
|
||||||
self.get_pango_context().list_families()]
|
|
||||||
StyledTextEditor.FONTS.sort()
|
|
||||||
|
|
||||||
self.match = None
|
self.match = None
|
||||||
self.last_match = None
|
self.last_match = None
|
||||||
@ -486,11 +475,12 @@ class StyledTextEditor(Gtk.TextView):
|
|||||||
|
|
||||||
# ...last the custom actions, which have custom proxies
|
# ...last the custom actions, which have custom proxies
|
||||||
default = StyledTextTagType.STYLE_DEFAULT[StyledTextTagType.FONTFACE]
|
default = StyledTextTagType.STYLE_DEFAULT[StyledTextTagType.FONTFACE]
|
||||||
|
fonts = SystemFonts()
|
||||||
fontface_action = ValueAction(str(StyledTextTagType.FONTFACE),
|
fontface_action = ValueAction(str(StyledTextTagType.FONTFACE),
|
||||||
_("Font family"),
|
_("Font family"),
|
||||||
default,
|
default,
|
||||||
ToolComboEntry,
|
ToolComboEntry,
|
||||||
StyledTextEditor.FONTS,
|
fonts.get_system_fonts(),
|
||||||
False, #editable
|
False, #editable
|
||||||
True, #shortlist
|
True, #shortlist
|
||||||
None) # validator
|
None) # validator
|
||||||
|
@ -51,6 +51,7 @@ from gen.plug.report import utils as ReportUtils
|
|||||||
from gen.errors import PluginError
|
from gen.errors import PluginError
|
||||||
from gen.plug.docbackend import CairoBackend
|
from gen.plug.docbackend import CairoBackend
|
||||||
from gen.utils.image import resize_to_buffer
|
from gen.utils.image import resize_to_buffer
|
||||||
|
from gui.utils import SystemFonts
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -108,9 +109,8 @@ def set_font_families():
|
|||||||
"""
|
"""
|
||||||
global font_families
|
global font_families
|
||||||
|
|
||||||
##families = pango_context.list_families()
|
fonts = SystemFonts()
|
||||||
families = PangoCairo.font_map_get_default().list_families()
|
family_names = fonts.get_system_fonts()
|
||||||
family_names = [family.get_name() for family in families]
|
|
||||||
|
|
||||||
fam = [f for f in _TTF_FREEFONT.itervalues() if f in family_names]
|
fam = [f for f in _TTF_FREEFONT.itervalues() if f in family_names]
|
||||||
if len(fam) == len(_TTF_FREEFONT):
|
if len(fam) == len(_TTF_FREEFONT):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user