[pygobject] [gi] Provide GtkTextBuffer.insert_with_tags_by_name()
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] [gi] Provide GtkTextBuffer.insert_with_tags_by_name()
- Date: Fri, 28 Jan 2011 06:21:51 +0000 (UTC)
commit 488478a83640d50baee963337fcc870fec76b784
Author: Martin Pitt <martin pitt ubuntu com>
Date: Fri Jan 28 07:20:26 2011 +0100
[gi] Provide GtkTextBuffer.insert_with_tags_by_name()
Provide an actual insert_with_tags_by_name() instead of overloading
insert_with_tags() to handle both types. This keeps the overrides consistent
with the actual GTK API.
gi/overrides/Gtk.py | 19 ++++++++++++++-----
tests/test_overrides.py | 4 ++--
2 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index b5359b6..25a5d92 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -580,13 +580,22 @@ 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_with_tags_by_name(self, iter, text, *tags):
+ if not tags:
+ return
+
+ tag_objs = []
+
+ for tag in tags:
+ tag_obj = self.get_tag_table().lookup(tag)
+ if not tag_obj:
+ raise ValueError, 'unknown text tag: ' + tag
+ tag_objs.append(tag_obj)
+
+ self.insert_with_tags(iter, text, *tag_objs)
+
def insert_at_cursor(self, text):
if not isinstance(text , _basestring):
raise TypeError('text must be a string, not %s' % type(text))
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index d3241cd..f0edbc4 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -1047,12 +1047,12 @@ class TestGtk(unittest.TestCase):
self.assertTrue(start.has_tag(tag))
buffer.set_text('')
- buffer.insert_with_tags(buffer.get_start_iter(), 'HelloHello', 'title')
+ buffer.insert_with_tags_by_name(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,
+ self.assertRaises(ValueError, buffer.insert_with_tags_by_name,
buffer.get_start_iter(), 'HelloHello', 'unknowntag')
def test_text_iter(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]