Beispiel #1
0
def gtk_textview_compute_optimal_height(widget, width):
    if not widget.props.visible:
        return
    buf = widget.get_buffer()
    # For border calculations, see gtktextview.c:gtk_text_view_size_request in the GTK source
    border = 2 * widget.border_width - 2 * widget.parent.border_width
    if widget.style_get_property("interior-focus"):
        border += 2 * widget.style_get_property("focus-line-width")

    buftext = buf.props.text
    # A good way to test height estimation is to use it for all units and
    # compare the reserved space to the actual space needed to display a unit.
    # To use height estimation for all units (not just empty units), use:
    #if True:
    if not buftext:
        text = getattr(widget, '_source_text', u"")
        if text:
            lang = factory.getlanguage(pan_app.settings.language["targetlang"])
            buftext = lang.alter_length(text)
            buftext = markup.escape(buftext)

    _w, h = rendering.make_pango_layout(widget, buftext,
                                        width - border).get_pixel_size()
    if h == 0:
        # No idea why this bug happens, but it often happens for the first unit
        # directly after the file is opened. For now we try to guess a more
        # useful default than 0. This should look much better than 0, at least.
        h = 28
    parent = widget.parent
    if isinstance(parent, gtk.ScrolledWindow
                  ) and parent.get_shadow_type() != gtk.SHADOW_NONE:
        border += 2 * parent.rc_get_style().ythickness
    widget.parent.set_size_request(-1, h + border)
    def create_repr_widgets(self):
        self.widgets.append(gtk.Label('{'))
        self.widgets.append(gtk.Label('}'))

        info = ''
        if self.elem.xml_node.tag:
            tag = self.elem.xml_node.tag
            if tag.startswith('{'):
                # tag is namespaced
                tag = tag[tag.index('}')+1:]
            info += tag + '|'
        # Uncomment the if's below for more verbose placeables
        #if self.elem.id:
        #    info += 'id=%s|'  % (self.elem.id)
        #if self.elem.rid:
        #    info += 'rid=%s|' % (self.elem.rid)
        #if self.elem.xid:
        #    info += 'xid=%s|' % (self.elem.xid)
        if info:
            self.widgets[0].set_text('{%s' % (info))

        for lbl in self.widgets:
            lbl.modify_font(get_role_font_description(self.textbox.role))
            w, h = make_pango_layout(self.textbox, u'{foo}', 100).get_pixel_size()
            lbl.set_size_request(-1, int(h/1.2))
Beispiel #3
0
def gtk_label_compute_optimal_height(widget, width):
    if widget.get_text().strip() == "":
        widget.set_size_request(width, 0)
    else:
        _w, h = rendering.make_pango_layout(widget, widget.get_label(),
                                            width).get_pixel_size()
        widget.set_size_request(width, h)
def gtk_textview_compute_optimal_height(widget, width):
    if not widget.props.visible:
        return
    buf = widget.get_buffer()
    # For border calculations, see gtktextview.c:gtk_text_view_size_request in the GTK source
    border = 2 * widget.border_width - 2 * widget.parent.border_width
    if widget.style_get_property("interior-focus"):
        border += 2 * widget.style_get_property("focus-line-width")

    buftext = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
    # A good way to test height estimation is to use it for all units and
    # compare the reserved space to the actual space needed to display a unit.
    # To use height estimation for all units (not just empty units), use:
    # if True:
    if not buftext:
        text = getattr(widget, "_source_text", u"")
        if text:
            lang = factory.getlanguage(pan_app.settings.language["targetlang"])
            buftext = lang.alter_length(text)
            buftext = markup.escape(buftext)

    _w, h = rendering.make_pango_layout(widget, buftext, width - border).get_pixel_size()
    if h == 0:
        # No idea why this bug happens, but it often happens for the first unit
        # directly after the file is opened. For now we try to guess a more
        # useful default than 0. This should look much better than 0, at least.
        h = 28
    parent = widget.parent
    if isinstance(parent, gtk.ScrolledWindow) and parent.get_shadow_type() != gtk.SHADOW_NONE:
        border += 2 * parent.rc_get_style().ythickness
    widget.parent.set_size_request(-1, h + border)
Beispiel #5
0
    def create_repr_widgets(self):
        self.widgets.append(gtk.Label('{'))
        self.widgets.append(gtk.Label('}'))

        info = ''
        if self.elem.xml_node.tag:
            tag = self.elem.xml_node.tag
            if tag.startswith('{'):
                # tag is namespaced
                tag = tag[tag.index('}') + 1:]
            info += tag + '|'
        # Uncomment the if's below for more verbose placeables
        #if self.elem.id:
        #    info += 'id=%s|'  % (self.elem.id)
        #if self.elem.rid:
        #    info += 'rid=%s|' % (self.elem.rid)
        #if self.elem.xid:
        #    info += 'xid=%s|' % (self.elem.xid)
        if info:
            self.widgets[0].set_text('{%s' % (info))

        for lbl in self.widgets:
            lbl.modify_font(get_role_font_description(self.textbox.role))
            w, h = make_pango_layout(self.textbox, u'{foo}',
                                     100).get_pixel_size()
            lbl.set_size_request(-1, int(h / 1.2))
 def create_repr_widgets(self):
     lbl = gtk.Label(u'¶')
     lbl.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.fg)) # foreground is light grey
     font_desc = get_role_font_description(self.textbox.role)
     lbl.modify_font(font_desc)
     self.textbox.get_pango_context().set_font_description(font_desc)
     w, h = make_pango_layout(self.textbox, u'¶', 100).get_pixel_size()
     lbl.set_size_request(-1, int(h/1.2))
     self.widgets.append(lbl)
    def create_repr_widgets(self):
        self.widgets.append(gtk.Label('))'))

        for lbl in self.widgets:
            font_desc = get_role_font_description(self.textbox.role)
            lbl.modify_font(font_desc)
            self.textbox.get_pango_context().set_font_description(font_desc)
            w, h = make_pango_layout(self.textbox, u'))', 100).get_pixel_size()
            lbl.set_size_request(-1, int(h/1.2))
Beispiel #8
0
    def create_repr_widgets(self):
        self.widgets.append(gtk.Label('))'))

        for lbl in self.widgets:
            font_desc = self.textbox.style.font_desc
            lbl.modify_font(font_desc)
            self.textbox.get_pango_context().set_font_description(font_desc)
            w, h = make_pango_layout(self.textbox, u'))', 100).get_pixel_size()
            lbl.set_size_request(-1, int(h / 1.2))
Beispiel #9
0
 def create_repr_widgets(self):
     lbl = gtk.Label(u'¶')
     lbl.modify_fg(gtk.STATE_NORMAL,
                   gtk.gdk.color_parse(self.fg))  # foreground is light grey
     font_desc = self.textbox.style.font_desc
     lbl.modify_font(font_desc)
     self.textbox.get_pango_context().set_font_description(font_desc)
     w, h = make_pango_layout(self.textbox, u'¶', 100).get_pixel_size()
     lbl.set_size_request(-1, int(h / 1.2))
     self.widgets.append(lbl)
Beispiel #10
0
    def create_repr_widgets(self):
        lbl = gtk.Label('[]')
        self.widgets.append(lbl)
        if self.elem.id:
            lbl.set_text('[%s]' % (self.elem.id))

        font_desc = get_role_font_description(self.textbox.role)
        lbl.modify_font(font_desc)
        self.textbox.get_pango_context().set_font_description(font_desc)
        w, h = make_pango_layout(self.textbox, u'[foo]', 100).get_pixel_size()
        lbl.set_size_request(-1, int(h/1.2))
    def create_repr_widgets(self):
        lbl = gtk.Label("[]")
        self.widgets.append(lbl)
        if self.elem.id:
            lbl.set_text("[%s]" % (self.elem.id))

        font_desc = self.textbox.style.font_desc
        lbl.modify_font(font_desc)
        self.textbox.get_pango_context().set_font_description(font_desc)
        w, h = make_pango_layout(self.textbox, u"[foo]", 100).get_pixel_size()
        lbl.set_size_request(-1, int(h / 1.2))
Beispiel #12
0
    def create_repr_widgets(self):
        lbl = gtk.Label('[]')
        self.widgets.append(lbl)
        if self.elem.id:
            lbl.set_text('[%s]' % (self.elem.id))

        font_desc = self.textbox.style.font_desc
        lbl.modify_font(font_desc)
        self.textbox.get_pango_context().set_font_description(font_desc)
        w, h = make_pango_layout(self.textbox, u'[foo]', 100).get_pixel_size()
        lbl.set_size_request(-1, int(h / 1.2))
    def create_repr_widgets(self):
        self.widgets.append(gtk.Label("<"))
        self.widgets.append(gtk.Label(">"))
        if self.elem.id:
            self.widgets[0].set_text("<%s|" % (self.elem.id))

        for lbl in self.widgets:
            font_desc = self.textbox.style.font_desc
            lbl.modify_font(font_desc)
            self.textbox.get_pango_context().set_font_description(font_desc)
            w, h = make_pango_layout(self.textbox, u"<foo>", 100).get_pixel_size()
            lbl.set_size_request(-1, int(h / 1.2))
Beispiel #14
0
    def create_repr_widgets(self):
        self.widgets.append(gtk.Label('<'))
        self.widgets.append(gtk.Label('>'))
        if self.elem.id:
            self.widgets[0].set_text('<%s|' % (self.elem.id))

        for lbl in self.widgets:
            font_desc = get_role_font_description(self.textbox.role)
            lbl.modify_font(font_desc)
            self.textbox.get_pango_context().set_font_description(font_desc)
            w, h = make_pango_layout(self.textbox, u'<foo>',
                                     100).get_pixel_size()
            lbl.set_size_request(-1, int(h / 1.2))
def gtk_label_compute_optimal_height(widget, width):
    if widget.get_text().strip() == "":
        widget.set_size_request(width, 0)
    else:
        _w, h = rendering.make_pango_layout(widget, widget.get_label(), width).get_pixel_size()
        widget.set_size_request(width, h)