<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Pango > 原文: [http://zetcode.com/gui/pygtk/pango/](http://zetcode.com/gui/pygtk/pango/) 在 PyGTK 編程教程的這一部分中,我們將探索 Pango 庫。 Pango 是一個免費的開源計算庫,可高質量呈現國際化文本。 可以使用不同的字體后端,從而允許跨平臺支持。 (維基百科) Pango 提供了用于`Gdk`和`Gtk`的高級字體和文本處理。 ## 簡單的例子 在第一個示例中,我們展示了如何更改標簽小部件的字體。 `quotes.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # This example shows how to modify # the font of a label # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk import pango quotes = """Excess of joy is harder to bear than any amount of sorrow. The more one judges, the less one loves. There is no such thing as a great talent without great will power. """ class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.connect("destroy", gtk.main_quit) self.set_title("Quotes") label = gtk.Label(quotes) gtk.gdk.beep() fontdesc = pango.FontDescription("Purisa 10") label.modify_font(fontdesc) fix = gtk.Fixed() fix.put(label, 5, 5) self.add(fix) self.set_position(gtk.WIN_POS_CENTER) self.show_all() PyApp() gtk.main() ``` 在上面的代碼示例中,我們有一個帶有三個引號的標簽小部件。 我們將其字體更改為 Purisa 10。 ```py quotes = """Excess of joy is harder to bear than any amount of sorrow. The more one judges, the less one loves. There is no such thing as a great talent without great will power. """ ``` 這是要在標簽中顯示的文本。 ```py fontdesc = pango.FontDescription("Purisa 10") ``` `FontDescription`用于指定字體的特征。 ```py label.modify_font(fontdesc) ``` 我們將標簽小部件的字體更改為 Purisa 10。 ![Quotations](https://img.kancloud.cn/c1/a4/c1a443f684b4c84be9797ccc9b5d43fb_503x99.jpg) 圖:`Quotations` ## 系統字體 下一個代碼示例顯示`TreeView`小部件中的所有可用字體。 `systemfonts.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # This example lists all available # fonts on a system in a TreeView widget # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk import pango class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_size_request(350, 250) self.set_border_width(8) self.connect("destroy", gtk.main_quit) self.set_title("System fonts") sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) context = self.create_pango_context() self.fam = context.list_families() store = self.create_model() treeView = gtk.TreeView(store) treeView.set_rules_hint(True) sw.add(treeView) self.create_column(treeView) self.add(sw) self.set_position(gtk.WIN_POS_CENTER) self.show_all() def create_column(self, treeView): rendererText = gtk.CellRendererText() column = gtk.TreeViewColumn("FontName", rendererText, text=0) column.set_sort_column_id(0) treeView.append_column(column) def create_model(self): store = gtk.ListStore(str) for ff in self.fam: store.append([ff.get_name()]) return store PyApp() gtk.main() ``` 該代碼示例顯示了系統上所有可用的字體。 ```py context = self.create_pango_context() ``` 此代碼行創建一個 pango 上下文對象。 它包含有關文本渲染過程的全局信息。 ```py self.fam = context.list_families() ``` 從上下文對象中,我們檢索所有可用的字體系列。 ```py for ff in self.fam: store.append([ff.get_name()]) ``` 在`TreeView`小部件的模型創建期間,我們從字體家族數組中獲取所有字體名稱,并將它們放入列表存儲中。 ![System fonts](https://img.kancloud.cn/2f/4b/2f4b6877339b56fc0f8f1b75c09b291b_358x278.jpg) 圖:系統字體 ## Unicode Pango 用于處理國際化文本。 `unicode.py` ```py #!/usr/bin/python # -*- coding: utf-8 -*- # ZetCode PyGTK tutorial # # This example displays text # in azbuka # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk import pango obj = unicode(u'''Фёдор Михайлович Достоевский родился 30 октября (11 ноября) 1821 года в Москве. Был вторым из 7 детей. Отец, Михаил Андреевич, работал вгоспитале для бедных. Мать, Мария Фёдоровна (в девичестве Нечаева), происходила из купеческого рода.''') class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.connect("destroy", gtk.main_quit) self.set_title("Unicode") label = gtk.Label(obj.encode('utf-8')) fontdesc = pango.FontDescription("Purisa 10") label.modify_font(fontdesc) fix = gtk.Fixed() fix.put(label, 5, 5) self.add(fix) self.set_position(gtk.WIN_POS_CENTER) self.show_all() PyApp() gtk.main() ``` 我們在西里爾字母中顯示一些文本。 ```py # -*- coding: utf-8 -*- ``` 為了直接在源代碼中使用國際化文本,我們必須提供此魔術注釋。 請注意,它必須在第一行或第二行上。 ```py obj = unicode(u'''Фёдор Михайлович Достоевский родился 30 октября (11 ноября) 1821 года в Москве. Был вторым из 7 детей. Отец, Михаил Андреевич, работал вгоспитале для бедных. Мать, Мария Фёдоровна (в девичестве Нечаева), происходила из купеческого рода.''') ``` 這是阿茲布卡語中的文字。 ```py Label label = new Label(text); ``` 我們將編碼的文本放入標簽中。 ![Unicode](https://img.kancloud.cn/65/1a/651a3e3856ffaf07117fc3e278ccad94_628x99.jpg) 圖:Unicode ## 屬性 Pango 屬性是適用于一段文字的屬性。 `attributes.py` ```py #!/usr/bin/python # ZetCode PyGTK tutorial # # In this program we work with # pango attributes # # author: jan bodnar # website: zetcode.com # last edited: February 2009 import gtk import pango text = "Valour fate kinship darkness" class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.connect("destroy", gtk.main_quit) self.set_title("Attributes") label = gtk.Label(text) attr = pango.AttrList() fg_color = pango.AttrForeground(65535, 0, 0, 0, 6) underline = pango.AttrUnderline(pango.UNDERLINE_DOUBLE, 7, 11) bg_color = pango.AttrBackground(40000, 40000, 40000, 12, 19) strike = pango.AttrStrikethrough(True, 20, 29) size = pango.AttrSize(30000, 0, -1) attr.insert(fg_color) attr.insert(underline) attr.insert(bg_color) attr.insert(size) attr.insert(strike) label.set_attributes(attr) fix = gtk.Fixed() fix.put(label, 5, 5) self.add(fix) self.set_position(gtk.WIN_POS_CENTER) self.show_all() PyApp() gtk.main() ``` 在代碼示例中,我們顯示了應用于文本的四個不同屬性。 ```py attr = pango.AttrList() ``` Pango 屬性列表是用于保存屬性的對象。 ```py fg_color = pango.AttrForeground(65535, 0, 0, 0, 6) ``` 在這里,我們創建一個屬性,該屬性將以紅色呈現文本。 前三個參數是顏色的 R,G,B 值。 最后兩個參數是文本的開始和結束索引,我們將其應用于此屬性。 ```py label.set_attributes(attr) ``` 我們設置標簽的屬性列表。 ![Pango attributes](https://img.kancloud.cn/88/fe/88fe5be5e3937240fa1b0acfdd05f745_567x80.jpg) 圖:Pango 屬性 在 PyGTK 編程庫的這一章中,我們使用了 pango 庫。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看