2012-01-09 43 views
7

屬性我有下面的代碼,使用的PyGTK:攀高與pygobject

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.AttrFamily,既不Pango.AttrWeight,既不攀高.AttrForeground(我無法實例化Pango.AttrSize)。

的問題是:如何使用pango_attr_size_newpango_attr_weight_new,通過instrospection pango_attr_family_newpango_attr_foreground_new

我知道我可以使用markup來做到這一點,但1.使用屬性會使事情變得簡單,2.我想知道這裏發生了什麼!我已經花了很多時間來解決它。

+0

你有沒有得到這個地方?我有同樣的問題。 – 2012-08-19 01:48:07

+0

FIY,這裏是相關問題: https://bugzilla.gnome.org/show_bug.cgi?id=646788(自2014年起不變) – 2016-05-25 22:44:47

+0

這還沒有被修復。但是你可以通過使用新的CSS系統來解決它:'#mylabel {color:blabla; etc'},設置'self.label.set_name(「mylabel」)',然後導入CSS文件'Gtk.CssProvider.load_from_file(Gtk.CssProvider_get_default(),file)'。 – 2016-07-02 23:20:13

回答

1

編輯:由於方法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其他物體之間。

+0

請勿使用此代碼。 'override_font'已被棄用。 HTTPS://developer.gnome。組織/ gtk3 /穩定/ GtkWidget.html#GTK的小部件,覆蓋的字體 – 2016-07-02 23:15:26

0

從這個mail我發現,這個運行沒有運行時錯誤:

from gi.repository import Pango 

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

雖然在我的代碼,這並沒有使內容右對齊,但我可能在我的代碼中的另一個錯誤。這裏最重要的是,上面的代碼似乎是翻譯PyGTK的東西,如import pango和:pango.ALIGN_RIGHT

這不是完整的答案,OP,但希望一步靠近。