pitivi r1193 - in branches/SOC_2008_BLEWIS: . pitivi/ui



Author: blewis
Date: Sat Jul 19 19:04:41 2008
New Revision: 1193
URL: http://svn.gnome.org/viewvc/pitivi?rev=1193&view=rev

Log:
* pitivi/ui/complextimeline.py:
switched labels back to goocanvas.Text, as I am working on the Text
class in util.py
* pitivi/ui/util.py:
re-implementing a text object from the ground up because there are 
certain things that the goocanvas.Text class will not do for us, like
report its own size.


Modified:
   branches/SOC_2008_BLEWIS/ChangeLog
   branches/SOC_2008_BLEWIS/pitivi/ui/complextimeline.py
   branches/SOC_2008_BLEWIS/pitivi/ui/util.py

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/complextimeline.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/complextimeline.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/complextimeline.py	Sat Jul 19 19:04:41 2008
@@ -95,12 +95,12 @@
 )
 
 LABEL = (
-    Text,
+    goocanvas.Text,
     {
         "font" : "Sans 9",
         "text" : "will be replaced",
         "fill_color_rgba" : 0x000000FF,
-        "anchor" : gtk.ANCHOR_NW
+        "alignment" : pango.ALIGN_LEFT
     },
     {}
 )
@@ -333,6 +333,7 @@
     def do_set_width(self, *args):
         self.bg.props.width = self.width
         self.r_handle.props.x = self.x + self.width - width(self.r_handle)
+        self.name.props.width = self.width - (2 * width(self.l_handle) + 4)
         self._size_spacer()
 
     def do_set_height(self, *args):
@@ -340,7 +341,6 @@
         self.bg.props.height = height
         self.l_handle.props.height = height
         self.r_handle.props.height = height
-        self.name.props.height = 2
         self._size_spacer()
 
 class CompositionLayers(goocanvas.Canvas, ZoomableWidgetInterface):

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/util.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/util.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/util.py	Sat Jul 19 19:04:41 2008
@@ -22,6 +22,8 @@
 import gobject
 import goocanvas
 import gtk
+import pango
+import pangocairo
 from pitivi.utils import closest_item
 
 ## GooCanvas Convenience Functions
@@ -344,19 +346,6 @@
     root.connect("button_release_event", selection_end, canvas, marquee, overlap, changed_cb)
     root.connect("motion_notify_event", selection_drag, canvas, marquee)
 
-class Text(goocanvas.Text):
-    '''adds the "missing" height property to goocanvas.Text'''
-    #TODO: width/height are dumy props in this class...they 
-    #should ideally be read-only values calculated from the layout
-    #parameters and text. 
-    __gtype_name__ = 'SmartText'
-
-    height = gobject.property(type=float, default=0)
-    width = gobject.property(type=float, default=0)
-
-    def __init__(self, *args, **kwargs):
-        goocanvas.Text.__init__(self, *args, **kwargs)
- 
 class SmartGroup(goocanvas.Group):
     """Extends goocanvas.Group() with 
     through gobject properties x, y, and width/height"""
@@ -438,6 +427,55 @@
         self.update_width(None, None)
         self.update_height(None, None)
 
+class Text(goocanvas.ItemSimple, goocanvas.Item):
+    '''A replacement for the stock goocanvas.Text widget, which
+    doesn't have a height property, and the width property doesn't do
+    quite what you'd expect it might. To set where the text should
+    wrap, we provide this wrap_width, property. The width, height
+    property clip the text appropriately.'''
+
+    __gtype_name__ = 'SmartText'
+
+    alignment = gobject.property(type=int)
+    font = gobject.property(type=str)
+    font_desc = gobject.property(type=gobject.TYPE_PYOBJECT,default=None)
+    height = gobject.property(type=float)
+    justification = gobject.property(type=int)
+    text = gobject.property(type=str, default="")
+    use_markup = gobject.property(type=bool, default=False)
+    width = gobject.property(type=float)
+    wrap_width = gobject.property(type=float)
+    x = gobject.property(type=float)
+    y = gobject.property(type=float)
+
+    def __init__(self, *args, **kwargs):
+        super(Text, self).__init__(*args, **kwargs)
+        self.connect("notify::text", self.do_set_text)
+        self.connect("notify::font", self.do_set_font)
+
+    def do_simple_create_path(self, cr):
+        context = pangocairo.CairoContext(cr)
+        cr.move_to(self.x, self.y)
+        layout = context.create_layout()
+        layout.set_alignment(self.alignment)
+        layout.set_font_description(self.font_desc)
+        if not self.use_markup:
+            layout.set_text(self.text)
+        else:
+            layout.set_markup(self.text)
+        context.show_layout(layout)
+
+    @gobject.property
+    def layout(self):
+        return self._layout
+
+    def do_set_font(self, *args):
+        self.font_desc = pango.FontDescription(self.font)
+        self.changed(True)
+
+    def do_set_text(self, *args):
+        self.changed(True)
+ 
 class List(SmartGroup):
     __gytpe_name__ = 'List'
 



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