summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Stadler <mail@renestadler.de>2012-09-23 17:22:53 +0200
committerRené Stadler <mail@renestadler.de>2012-09-24 02:43:37 +0200
commit670f0f68d027a15f642f9308a40c82fa27fc632a (patch)
tree521dc936b303f6a96e54b9f44173068d9343cb0d
parentcc2e338d1696790f83b8978e43e4d895cd2a63ea (diff)
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.
-rw-r--r--GstDebugViewer/GUI/columns.py45
-rw-r--r--GstDebugViewer/GUI/window.py10
-rw-r--r--GstDebugViewer/Plugins/FindBar.py16
3 files changed, 40 insertions, 31 deletions
diff --git a/GstDebugViewer/GUI/columns.py b/GstDebugViewer/GUI/columns.py
index 96ea98c..27c409f 100644
--- a/GstDebugViewer/GUI/columns.py
+++ b/GstDebugViewer/GUI/columns.py
@@ -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
diff --git a/GstDebugViewer/GUI/window.py b/GstDebugViewer/GUI/window.py
index 990485c..bad88c7 100644
--- a/GstDebugViewer/GUI/window.py
+++ b/GstDebugViewer/GUI/window.py
@@ -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)
diff --git a/GstDebugViewer/Plugins/FindBar.py b/GstDebugViewer/Plugins/FindBar.py
index 234a6a2..22462dc 100644
--- a/GstDebugViewer/Plugins/FindBar.py
+++ b/GstDebugViewer/Plugins/FindBar.py
@@ -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):