b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

pango markup_markup公式_markup用法(6)

电脑杂谈  发布时间:2017-06-08 15:06:17  来源:网络整理

import Pango
...
        #Create a new label whose text is rendered by Pango
        mylabel = gtk.Label()
        mylabel.set_markup("<u>This is pango markup</u> <span foreground=\"orange\">inside a label</span>")
        first_page.pack_start(mylabel)

Here's how this label shows up in the UI.

Image: suagar_almanac_pango_label.jpg

More often than not, you will probably want larger Pango layout areas to display data contained inside of a file rather than data that is conceived within the code of your program. The following code shows a utility method used to read from a file that can then be used to load data in to a Pango layout.

#### Method getFileData, which takes a file_path and returns the data within that file
def getFileData(file_path):
    fd = open(file_path, 'r')
    try:
        data = fd.read()
    finally:
        fd.close()
    return data

With this utility method in place, updating a Pango layout with file data is pretty straightforward:

import pango
...
class TextWidget(gtk.DrawingArea):
	def __init__(self):

		self.repeat_period_msec = 1000 
		
		gtk.DrawingArea.__init__(self)
		self.context = None

		#create a pango layout. Leave text argument to be empty string since we want to use markup
		self.pango_context = self.create_pango_context()
		self.pango_layout = self.create_pango_layout('')
                ...


	#### Method update_file, reloads data from filepath and then updates the Pango layout that
	# displays the data in the file. 
	def update_file(self, filepath):
		self.pango_layout.set_markup(annotateutils.getFileData(filepath))
		self.queue_draw()

Pango Reference Manual

PYGTK's gtk.gdk Class Referencegtk.gdk.PangoRenderer


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-51835-6.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 肖源圣
      肖源圣

      @老子起个昵称怎么就那么难@郑甜甜的辛普森美美美

    热点图片
    拼命载入中...