[pygobject] Override Pango.FontDescription.



commit 2adcd95762944a4e27123093d3c8d080e49be1ea
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Dec 8 18:06:01 2010 +0100

    Override Pango.FontDescription.

 demos/gtk-demo/gtk-demo.py |    2 +-
 gi/overrides/Makefile.am   |    1 +
 gi/overrides/Pango.py      |   40 ++++++++++++++++++++++++++++++++++++++++
 tests/test_overrides.py    |    7 +++++++
 4 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/demos/gtk-demo/gtk-demo.py b/demos/gtk-demo/gtk-demo.py
index da0cb88..8a8c3e0 100755
--- a/demos/gtk-demo/gtk-demo.py
+++ b/demos/gtk-demo/gtk-demo.py
@@ -288,7 +288,7 @@ class GtkDemoApp(object):
         scrolled_window.add(text_view)
 
         if is_source:
-            font_desc = Pango.Font.description_from_string('monospace')
+            font_desc = Pango.FontDescription('monospace')
             text_view.modify_font(font_desc)
             text_view.set_wrap_mode(Gtk.WrapMode.NONE)
         else:
diff --git a/gi/overrides/Makefile.am b/gi/overrides/Makefile.am
index 424222b..0e4f6c0 100644
--- a/gi/overrides/Makefile.am
+++ b/gi/overrides/Makefile.am
@@ -8,6 +8,7 @@ pygioverrides_PYTHON = \
 	Gtk.py \
 	Gdk.py \
 	GIMarshallingTests.py \
+	Pango.py \
 	keysyms.py \
 	__init__.py
 
diff --git a/gi/overrides/Pango.py b/gi/overrides/Pango.py
new file mode 100644
index 0000000..1bbfcad
--- /dev/null
+++ b/gi/overrides/Pango.py
@@ -0,0 +1,40 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+#
+# Copyright (C) 2010 Paolo Borelli <pborelli gnome org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+from ..overrides import override
+from ..importer import modules
+
+Pango = modules['Pango'].introspection_module
+
+__all__ = []
+
+class FontDescription(Pango.FontDescription):
+
+    def __new__(cls, string=None):
+        if string is not None:
+            # FIXME: this should be Pango.FontDescription.from_string()
+            # GI bug?
+            return Pango.font_description_from_string (string)
+        else:
+            return Pango.FontDescription.__new__(cls)
+
+FontDescription = override(FontDescription)
+__all__.append('FontDescription')
+
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index be7693a..72278a7 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -10,6 +10,7 @@ from gi.repository import GLib
 from gi.repository import GObject
 from gi.repository import Gdk
 from gi.repository import Gtk
+from gi.repository import Pango
 import gi.overrides as overrides
 import gi.types
 
@@ -37,6 +38,12 @@ class TestGLib(unittest.TestCase):
         self.assertEquals(variant.get_child_value(0).get_child_value(0).get_string(), 'key2')
         self.assertEquals(variant.get_child_value(0).get_child_value(1).get_int32(), 2)
 
+class TestPango(unittest.TestCase):
+
+    def test_font_description(self):
+        desc = Pango.FontDescription('monospace')
+        self.assertEquals(desc.get_family(), 'monospace')
+
 class TestGdk(unittest.TestCase):
 
     def test_color(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]