summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorNicolas Schodet2012-06-09 21:04:11 +0200
committerNicolas Schodet2012-06-09 21:04:11 +0200
commitac6fb3e4d815ae7bc08abc0219ec004a2960292a (patch)
tree4e7bd9784e802139d44a8f30e656b4205b079e0a /host
parent9184fb957a6d9bf39c5aea315528475838abc82b (diff)
host/simu/inter: add text drawing primitive
Diffstat (limited to 'host')
-rw-r--r--host/simu/inter/drawable.py12
-rw-r--r--host/simu/inter/test/test_drawable.py1
2 files changed, 13 insertions, 0 deletions
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):