From ac6fb3e4d815ae7bc08abc0219ec004a2960292a Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 9 Jun 2012 21:04:11 +0200 Subject: host/simu/inter: add text drawing primitive --- host/simu/inter/drawable.py | 12 ++++++++++++ host/simu/inter/test/test_drawable.py | 1 + 2 files changed, 13 insertions(+) diff --git a/host/simu/inter/drawable.py b/host/simu/inter/drawable.py index 849eddd3..fc9d3343 100644 --- a/host/simu/inter/drawable.py +++ b/host/simu/inter/drawable.py @@ -94,6 +94,10 @@ class Drawable: import math return self.__onto.__draw_arc (p, r, **kw) + def __draw_text (self, p, **kw): + p = self.trans_apply (p) + return self.__onto.__draw_text (p, **kw) + def draw_rectangle (self, *p, **kw): """Draw a rectangle.""" self.__items.append (self.__draw_rectangle (*p, **kw)) @@ -119,6 +123,10 @@ class Drawable: """Draw a arc of the given radius centered on p.""" self.__items.append (self.__draw_arc (p, r, **kw)) + def draw_text (self, p, **kw): + """Draw text at given position.""" + self.__items.append (self.__draw_text (p, **kw)) + def reset (self): """Clear all drawn items, reset transformations.""" for i in self.__children: @@ -208,6 +216,10 @@ class DrawableCanvas(Tkinter.Canvas): kw[k] = degrees (kw[k]) return self.create_arc (p1, p2, **kw) + def _Drawable__draw_text (self, p, **kw): + p, = self.__coord (p) + return self.create_text (p, **kw) + def _Drawable__delete (self, *list): self.delete (*list) diff --git a/host/simu/inter/test/test_drawable.py b/host/simu/inter/test/test_drawable.py index 9aa56ef1..3795170a 100644 --- a/host/simu/inter/test/test_drawable.py +++ b/host/simu/inter/test/test_drawable.py @@ -36,6 +36,7 @@ class Test (Drawable): self.draw_circle ((40, -40), 10) self.draw_oval ((40, -40), 10, 5) self.draw_arc ((-40, 0), 20, start = pi / 4, extent = pi / 2) + self.draw_text ((10, 0), text = "hello world") class App (DrawableCanvas): -- cgit v1.2.3