带pygobj的pango属性

2024-09-30 20:17:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下使用pygtk的代码:

attr = pango.AttrList()
attr.change(pango.AttrSize((
            50 * window_height / 100) * 1000, 0, -1))
attr.change(pango.AttrFamily("Sans", 0, -1))
attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
attr.change(pango.AttrForeground(65535, 65535, 65535, 0, -1))

self.label.set_attributes(attr)

我正在尝试将其移植到pygobject,但没有类盘古属也没有盘古吸引子也没有Pango.AttrForeground公司(我不能实例化Pango.AttrSize公司). 在

问题是:如何通过透视法使用^{}^{}^{}和{a4}?在

我知道我可以用markup来做这个,但是1。使用属性可以使事情更简单。我想知道这里发生了什么!我已经花了很多时间试图解决它。在


Tags: 代码公司windowchangepygtkpangoattrheight
2条回答

从这个mail我发现这个运行没有运行时错误:

    from gi.repository import Pango

    ren = Gtk.CellRendererText()
    ren.set_property('alignment', Pango.Alignment.RIGHT)

虽然在我的代码中这并没有使内容向右对齐,但我的代码中可能有另一个错误。这里最重要的是,上面的代码似乎是pygtk的翻译,比如import pango和:pango.ALIGN_RIGHT

这并不是OP的完整答案,但希望能更近一步。在

编辑:由于方法override_font已被弃用,您应该按照本页的描述使用CSS-https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-font

剩下的答案留作历史之用。在

我不知道为什么这样不行。在

这里有一个方法。在

def set_global_styles(self, editor_widget):
    pango_context = editor_widget.create_pango_context()
    font_description = pango_context.get_font_description()
    increase = 14 #pt 14
    font_size = 1024*increase
    font_description.set_size(font_size)
    editor_widget.override_font(font_description)

到目前为止我找到的最简单的方法。 迟答总比不回答好。在

以防Pango的一些资源,并使用上面的代码。 我不确定Pango的所有文档是否都适用于gtk3,但它对我有用。在

Pango context set font description

Pango font description

Pango fonts in gtk

Pango layout

GtkWidget inherited by text editors在其他对象中。在

相关问题 更多 >