Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2011-11-10 21:49:29 (GMT)
committer C. Scott Ananian <cscott@cscott.net>2011-11-10 23:30:24 (GMT)
commit3c3a5f03d1a2605b6773b472548da825199d5855 (patch)
treedd769ffd6983929a3a33e2d69664b2b2bc256de5
parentdb1d1641ea50b991fdeec592b6f716f1e1903eb1 (diff)
Update PangoCairo and PangoLayout to new GIR calling convention.
-rw-r--r--TurtleArt/sprites.py18
-rw-r--r--TurtleArt/tacanvas.py10
-rw-r--r--util/gtkcompat.py16
3 files changed, 30 insertions, 14 deletions
diff --git a/TurtleArt/sprites.py b/TurtleArt/sprites.py
index d9c3a7b..9577656 100644
--- a/TurtleArt/sprites.py
+++ b/TurtleArt/sprites.py
@@ -365,14 +365,14 @@ class Sprite:
def draw_label(self, cr):
''' Draw the label based on its attributes '''
# Create a pangocairo context
- cr = PangoCairo.CairoContext(cr)
my_width = self.rect.width - self._margins[0] - self._margins[2]
if my_width < 0:
my_width = 0
my_height = self.rect.height - self._margins[1] - self._margins[3]
for i in range(len(self.labels)):
- pl = cr.create_layout()
- pl.set_text(str(self.labels[i]))
+ pcr = PangoCairo.create_context(cr)
+ pl = Pango.Layout.new(pcr)
+ pl.set_text(str(self.labels[i]), -1)
# pl = self._sprites.canvas.create_pango_layout(str(self.labels[i]))
self._fd.set_size(int(self._scale[i] * Pango.SCALE))
pl.set_font_description(self._fd)
@@ -387,7 +387,7 @@ class Sprite:
j = len(self.labels[i]) - 1
while(w > my_width and j > 0):
pl.set_text(
- "…" + self.labels[i][len(self.labels[i]) - j:])
+ "…" + self.labels[i][len(self.labels[i]) - j:],-1)
self._fd.set_size(int(self._scale[i] * Pango.SCALE))
pl.set_font_description(self._fd)
w = pl.get_size()[0] / Pango.SCALE
@@ -408,18 +408,18 @@ class Sprite:
cr.save()
cr.translate(x, y)
cr.set_source_rgb(self._color[0], self._color[1], self._color[2])
- cr.update_layout(pl)
- cr.show_layout(pl)
+ PangoCairo.update_layout(cr, pl)
+ PangoCairo.show_layout(cr, pl)
cr.restore()
def label_width(self):
''' Calculate the width of a label '''
- cr = PangoCairo.CairoContext(self._sprites.cr)
+ cr = PangoCairo.create_context(self._sprites.cr)
if cr is not None:
max = 0
for i in range(len(self.labels)):
- pl = cr.create_layout()
- pl.set_text(self.labels[i])
+ pl = Pango.Layout.new(cr)
+ pl.set_text(self.labels[i], -1)
self._fd.set_size(int(self._scale[i] * Pango.SCALE))
pl.set_font_description(self._fd)
w = pl.get_size()[0] / Pango.SCALE
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py
index 197d17e..1c545a6 100644
--- a/TurtleArt/tacanvas.py
+++ b/TurtleArt/tacanvas.py
@@ -577,17 +577,17 @@ class TurtleGraphics:
def draw_text(self, label, x, y, size, w, share=True):
''' Draw text '''
w *= self.tw.coord_scale
- cr = PangoCairo.CairoContext(self.canvas)
- pl = cr.create_layout()
+ cr = PangoCairo.create_context(self.canvas)
+ pl = Pango.Layout.new(cr)
fd = Pango.FontDescription('Sans')
fd.set_size(int(size * self.tw.coord_scale) * Pango.SCALE)
pl.set_font_description(fd)
if type(label) == str or type(label) == unicode:
- pl.set_text(label.replace('\0', ' '))
+ pl.set_text(label.replace('\0', ' '), -1)
elif type(label) == float or type(label) == int:
- pl.set_text(str(label))
+ pl.set_text(str(label), -1)
else:
- pl.set_text(str(label))
+ pl.set_text(str(label), -1)
pl.set_width(int(w) * Pango.SCALE)
cr.save()
cr.translate(x, y)
diff --git a/util/gtkcompat.py b/util/gtkcompat.py
index fea0b6f..b55091a 100644
--- a/util/gtkcompat.py
+++ b/util/gtkcompat.py
@@ -138,3 +138,19 @@ except ValueError, ImportError:
def new_with_label(label):
return GtkMenuItem1(label)
Gtk.MenuItem = GtkMenuItem2
+
+ class PangoLayout2(Pango.Layout):
+ @staticmethod
+ def new(cr):
+ # call cr.create_layout(), but wrap the result so we can override
+ # set_text() below
+ return PangoLayout2(cr.create_layout().get_context())
+ def set_text(self, text, val):
+ if val != -1: text = text[:val]
+ super(PangoLayout2, self).set_text(text)
+
+ Pango.Layout = PangoLayout2
+
+ PangoCairo.create_context = lambda x: PangoCairo.CairoContext(x)
+ PangoCairo.update_layout = lambda cr, pl: cr.update_layout(pl)
+ PangoCairo.show_layout = lambda cr, pl: cr.show_layout(pl)