diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-10-09 05:31:37 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-10-23 16:55:56 (GMT) |
commit | 88f239570e5871a221b8122570026f66f7213c3d (patch) | |
tree | 90c849552c3d2637a1c5d62b47769e7f97e3f91e | |
parent | 8716960c0f1862f438143f465982bbb130932111 (diff) |
Use a different technique to draw text in the canvas
Previously, we used the cairo toy api, but had problem with complex
scripts.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | Desenho.py | 60 |
1 files changed, 25 insertions, 35 deletions
@@ -62,7 +62,8 @@ Walter Bender (walter@laptop.org) """ from gi.repository import Gdk -from gi.repository import PangoCairo +from gi.repository import Gtk +from gi.repository import GObject import logging import math import cairo @@ -629,45 +630,34 @@ class Desenho: widget.activity.move_textview(coord_x, coord_y) widget.activity.textview.show() + widget.activity.textview.set_cursor_visible(True) widget.activity.textview.grab_focus() else: widget.text_in_progress = False - - buf = widget.activity.textview.get_buffer() - start, end = buf.get_bounds() - text = buf.get_text(start, end, True) - textview = widget.activity.textview - #tv_layout = textview.create_pango_layout(text) - - ctx = widget.drawing_ctx - - ctx.save() - ctx.new_path() - ctx.set_source_rgba(*widget.tool['cairo_stroke_color']) - - pango_layout = PangoCairo.create_layout(ctx) - pango_layout.set_font_description(widget.get_font_description()) - pango_layout.set_text(unicode(text), len(unicode(text))) - - tv_alloc = textview.get_allocation() - ctx.move_to(tv_alloc.x, tv_alloc.y) - PangoCairo.show_layout(ctx, pango_layout) - ctx.stroke() - ctx.restore() - - widget.activity.textview.hide() - widget.drawing_canvas.flush() - - try: - widget.activity.textview.set_text('') - except AttributeError: - buf.set_text('') - - widget.enable_undo() - # TODO: clip - widget.queue_draw() + textview.set_cursor_visible(False) + # need wait until the cursor is hidden + GObject.idle_add(self._finalize_text, widget, textview) + + def _finalize_text(self, widget, textview): + buf = textview.get_buffer() + window = textview.get_window(Gtk.TextWindowType.TEXT) + ctx = widget.drawing_ctx + tv_alloc = textview.get_allocation() + Gdk.cairo_set_source_window(ctx, window, tv_alloc.x, tv_alloc.y) + ctx.paint() + + widget.activity.textview.hide() + widget.drawing_canvas.flush() + + try: + widget.activity.textview.set_text('') + except AttributeError: + buf.set_text('') + + widget.enable_undo() + widget.queue_draw() def selection(self, widget, coords): """Make a selection. |