[pygobject] [gi] Support tag names in GtkTextBuffer.insert_with_tags()
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] [gi] Support tag names in GtkTextBuffer.insert_with_tags()
- Date: Thu, 27 Jan 2011 12:38:32 +0000 (UTC)
commit dace1a553793fb7fb054b60760f02c9e5cf00b38
Author: Martin Pitt <martin pitt ubuntu com>
Date: Thu Jan 27 13:37:18 2011 +0100
[gi] Support tag names in GtkTextBuffer.insert_with_tags()
Neither insert_with_tags() nor insert_with_tags_by_name() are introspectable
due to using varargs. As both are useful, support both cases in the override.
gi/overrides/Gtk.py | 5 +++++
tests/test_overrides.py | 9 +++++++++
2 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 6e2f858..b5359b6 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -580,6 +580,11 @@ class TextBuffer(Gtk.TextBuffer):
start = self.get_iter_at_offset(start_offset)
for tag in tags:
+ if isinstance(tag, _basestring):
+ tagname = tag
+ tag = self.get_tag_table().lookup(tagname)
+ if not tag:
+ raise ValueError, 'unknown text tag: ' + tagname
self.apply_tag(tag, start, iter)
def insert_at_cursor(self, text):
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 25cea6a..d3241cd 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -1046,6 +1046,15 @@ class TestGtk(unittest.TestCase):
self.assertTrue(start.begins_tag(tag))
self.assertTrue(start.has_tag(tag))
+ buffer.set_text('')
+ buffer.insert_with_tags(buffer.get_start_iter(), 'HelloHello', 'title')
+ (start, end) = buffer.get_bounds()
+ self.assertTrue(start.begins_tag(tag))
+ self.assertTrue(start.has_tag(tag))
+
+ self.assertRaises(ValueError, buffer.insert_with_tags,
+ buffer.get_start_iter(), 'HelloHello', 'unknowntag')
+
def test_text_iter(self):
self.assertEquals(Gtk.TextIter, overrides.Gtk.TextIter)
buffer = Gtk.TextBuffer()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]