[pygtk] Problem with change fonts size on custom widget.

Mike Bernson mike at mlb.org
Wed Oct 11 02:43:57 WST 2006


I have a custom widget that set it style based on another widget. I
trying to change to font size and it does not work. It is correct in
the style until self.get_pango_context is called.

If I comment out the set_style in init things work.

Here init:

 def __init__(self):
                gtk.Widget.__init__(self)
                style = gtk.rc_get_style_by_paths(self.get_settings(),
                        'GtkEntry', 'GtkEntry', gtk.Entry)
                self.set_style(style)
                self.__enums = []
                self.__menu  = None
                self.__width_chars = -1
                self.__width = -1
                self.__text = ''
                self.__has_frame = True
                self._layout = self.create_pango_layout('')
                self.__xalign = 0.5

here is the start of size request:

  def do_size_request(self, requisition):
                self.ensure_style()

                context = self.get_pango_context()
                metrics = context.get_metrics(self.style.font_desc,
                        context.get_language())
                self.ascent = metrics.get_ascent()
                self.descent = metrics.get_descent()


Here is the code trying to set the font size which work for other
widgets (Also work if I custom widget if I do not set the style)

                w = PyEnum()

                size = 4.0
                style = w.style
                font_desc = style.font_desc.copy()
                font_desc.set_size(int(size * 1024.0))
                w.modify_font(font_desc)


More information about the pygtk mailing list