def show_diff_blob(title, result):
d = gtk.Dialog(title=title,
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
b = gtk.TextBuffer()
tags = b.get_tag_table()
for color in ["red", "blue", "green", "grey"]:
tag = gtk.TextTag(color)
tag.set_property("foreground", color)
tags.add(tag)
tag = gtk.TextTag("bold")
tag.set_property("weight", pango.WEIGHT_BOLD)
tags.add(tag)
try:
fontsize = CONF.get_int("diff_fontsize", "developer")
except Exception:
fontsize = 11
if fontsize < 4 or fontsize > 144:
LOG.info("Unsupported diff_fontsize %i. Using 11." % fontsize)
fontsize = 11
lines = result.split(os.linesep)
for line in lines:
if line.startswith("-"):
tags = ("red", "bold")
elif line.startswith("+"):
tags = ("blue", "bold")
else:
tags = ()
b.insert_with_tags_by_name(b.get_end_iter(), line + os.linesep, *tags)
v = gtk.TextView(b)
fontdesc = pango.FontDescription("Courier %i" % fontsize)
v.modify_font(fontdesc)
v.set_editable(False)
v.show()
s = gtk.ScrolledWindow()
s.add(v)
s.show()
d.vbox.pack_start(s, 1, 1, 1)
d.set_size_request(600, 400)
d.run()
d.destroy()
评论列表
文章目录