[hamster-applet] shortcut function "create_layout" to create layout and set font to system's default



commit c0f01040b555a9a6631b4e49991433d1fe95c6c9
Author: Toms Bauģis <toms baugis gmail com>
Date:   Sun Apr 11 00:39:43 2010 +0100

    shortcut function "create_layout" to create layout and set font to system's default

 src/hamster/graphics.py |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/hamster/graphics.py b/src/hamster/graphics.py
index 10bb1eb..a8c7b68 100644
--- a/src/hamster/graphics.py
+++ b/src/hamster/graphics.py
@@ -241,6 +241,24 @@ class Graphics(object):
 
         context.show_layout(layout)
 
+    def create_layout(self, size):
+        """utility function to create layout with the default font. Size and
+        alignment parameters are shortcuts to according functions of the
+        pango.Layout"""
+        if not self.context:
+            # TODO - this is rather sloppy as far as exception goes
+            #        should explain better
+            raise "Can not create layout without existing context!"
+
+        layout = self.context.create_layout()
+        font_desc = pango.FontDescription(gtk.Style().font_desc.to_string())
+        if size: font_desc.set_size(size * pango.SCALE)
+
+        layout.set_font_description(font_desc)
+        return layout
+
+
+
     def show_text(self, text, size = None, color = None):
         """display text with system's default font"""
         font_desc = pango.FontDescription(gtk.Style().font_desc.to_string())



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