Use pango markup instead of attributes

Attributes don't work from introspection, so this blocks porting to gtk3.

In MessageColumn, admit that multiple highlighters don't actually work.
This commit is contained in:
René Stadler 2012-09-23 17:22:53 +02:00 committed by Stefan Sauer
parent 634f17ed7d
commit 66ed3bb258
3 changed files with 40 additions and 31 deletions

View file

@ -24,6 +24,7 @@ def _ (s):
import logging
import glib
import gtk
from GstDebugViewer import Common, Data
@ -328,30 +329,38 @@ class MessageColumn (TextColumn):
def get_row_data_func (self):
from pango import AttrList, AttrBackground, AttrForeground
highlighters = self.highlighters
id_ = self.id
# FIXME: This should be none; need to investigate
# `cellrenderertext.props.attributes = None' failure (param conversion
# error like `treeview.props.model = None').
no_attrs = AttrList ()
def message_data_func (props, row):
props.text = row[id_]
msg = row[id_]
if not highlighters:
props.attributes = no_attrs
for highlighter in highlighters.values ():
ranges = highlighter (row)
if not ranges:
props.attributes = no_attrs
else:
attrlist = AttrList ()
for start, end in ranges:
attrlist.insert (AttrBackground (0, 0, 65535, start, end))
attrlist.insert (AttrForeground (65535, 65535, 65535, start, end))
props.attributes = attrlist
props.text = msg
return
if len (highlighters) > 1:
raise NotImplementedError ("FIXME: Support more than one...")
highlighter = highlighters.values ()[0]
ranges = highlighter (row)
if not ranges:
props.text = msg
else:
tags = []
prev_end = 0
end = None
for start, end in ranges:
if prev_end < start:
tags.append (glib.markup_escape_text (msg[prev_end:start]))
msg_escape = glib.markup_escape_text (msg[start:end])
tags.append ("<span foreground=\'#FFFFFF\'"
" background=\'#0000FF\'>%s</span>" % (msg_escape,))
prev_end = end
if end is not None:
tags.append (glib.markup_escape_text (msg[end:]))
props.markup = "".join (tags)
return message_data_func

View file

@ -28,7 +28,7 @@ import os.path
from bisect import bisect_right, bisect_left
import logging
import pango
import glib
import gobject
import gtk
@ -846,11 +846,11 @@ class Window (object):
bar.props.message_type = gtk.MESSAGE_ERROR
box = bar.get_content_area ()
attrs = pango.AttrList ()
attrs.insert (pango.AttrWeight (pango.WEIGHT_BOLD, 0, len (message1)))
markup = "<b>%s</b> %s" % (glib.markup_escape_text (message1),
glib.markup_escape_text (message2),)
label = gtk.Label ()
label.props.label = "%s %s" % (message1, message2)
label.props.attributes = attrs
label.props.use_markup = True
label.props.label = markup
label.props.selectable = True
box.pack_start (label, False, False, 0)

View file

@ -24,7 +24,7 @@ import logging
from GstDebugViewer import Common, Data, GUI
from GstDebugViewer.Plugins import *
import pango
import glib
import gtk
class SearchOperation (object):
@ -152,11 +152,9 @@ class FindBarWidget (gtk.HBox):
next_action.connect_proxy (next_button)
self.pack_start (next_button, False, False, 0)
self.status_label = gtk.Label ("")
self.status_label = gtk.Label ()
self.status_label.props.xalign = 0.
attrs = pango.AttrList ()
attrs.insert (pango.AttrWeight (pango.WEIGHT_BOLD, 0, -1))
self.status_label.props.attributes = attrs
self.status_label.props.use_markup = True
self.pack_start (self.status_label, False, False, 6)
self.__compute_status_size ()
self.status_label.connect ("notify::style", self.__handle_notify_style)
@ -166,7 +164,7 @@ class FindBarWidget (gtk.HBox):
def __compute_status_size (self):
label = self.status_label
old_text = label.props.label
old_markup = label.props.label
label.set_size_request (-1, -1)
max_width = 0
try:
@ -176,7 +174,7 @@ class FindBarWidget (gtk.HBox):
max_width = max (max_width, width)
label.set_size_request (max_width, -1)
finally:
label.props.label = old_text
label.props.label = old_markup
def __handle_notify_style (self, *a, **kw):
@ -184,7 +182,9 @@ class FindBarWidget (gtk.HBox):
def __set_status (self, text):
self.status_label.props.label = text
markup = "<b>%s</b>" % (glib.markup_escape_text (text),)
self.status_label.props.label = markup
def status_no_match_found (self):