Пример #1
0
	def __init__(it, tbf): # tbf - instance of gtk.TextBuffer
		it.lsTags = []
		it.bold = tbf.create_tag('bold', weight = pango.WEIGHT_BOLD)
		it.italic = tbf.create_tag('italic', style = pango.STYLE_ITALIC)
		it.underline = tbf.create_tag('underline', underline = pango.UNDERLINE_SINGLE)
		for name, color in (
			('black', 'black'),
			('dk_grey', '#444'),
			('red', 'red'),
			('pink', 'pink'),
			('green', 'green'),
			('lt_green', '#5F5'),
			('yellow', '#AA0'),
			('lt_yellow', '#FF5'),
			('blue', 'blue'),
			('lt_blue', '#55F'),
			('magenta', '#A0A'),
			('lt_magenta', '#F0F'),
			('cyan', 'cyan'),
			('lt_cyan', '#AFF'),
			('white', 'white'),
			('grey', 'grey'),
			):
			setattr(it, 'fg_'+name, tbf.create_tag('fg_'+name, foreground_gdk=_cp(color)))
			setattr(it, 'bg_'+name, tbf.create_tag('bg_'+name, background_gdk=_cp(color)))
		_dbg("yellow:%s\n" % str(it.bg_yellow.get_property('background-gdk')))
		_dbg("lt_yellow:%s\n" % str(it.bg_lt_yellow.get_property('background-gdk')))
Пример #2
0
	def get(it, tag_name):
		if not(tag_name):
			return False
		if not(hasattr(it, tag_name)) and(tag_name[:4] in('fg__', 'bg__')):
			try:
				color = _cp('#'+tag_name[3:])
			except ValueError:
				return False
			if tag_name[:2]=='fg':
				setattr(it, tag_name, tbf.create_tag(tag_name, foreground_gdk=color))
			elif tag_name[:2]=='bg':
				setattr(it, tag_name, tbf.create_tag(tag_name, background_gdk=color))
		if not(hasattr(it, tag_name)):
			return False
		it_attr =  getattr(it, tag_name)
		if callable(it_attr):
			it_attr()
			return True
		elif isinstance(it_attr, gtk.TextTag):
			it.cm_reset(tag_name[:3])
			it.lsTags.append(it_attr)
			return True
		return False