From 03fa5fe2e22c5733ed7cb81fbecf604e2f189908 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 27 Feb 2014 06:48:13 +0100 Subject: separate function for string drawing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 9 +-------- src/x.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index d1b5d66..5fee9f6 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -57,14 +57,7 @@ while True: window.fill_rectangle(gc, 0, 0, width, panel_height) gc.change(foreground = foreground) gc.change(font = font) - text_ = '°°° TEST °°° ꚺ░∈𝕐 '.encode('utf-16')[2:] - text = [] - for i in range(len(text_)): - if (i & 1) == 0: - text.append(text_[i]) - else: - text[-1] |= text_[i] << 8 - window.image_text_16(gc, 0, 10, text) + draw_text(window, gc, 0, 10, '°°° TEST °°°') display.flush() window.unmap() diff --git a/src/x.py b/src/x.py index 94437f5..3906ea5 100644 --- a/src/x.py +++ b/src/x.py @@ -139,6 +139,26 @@ def create_panel(width, height, left, ypos, panel_height, at_top): return window +def draw_text(window, gc, x, y, text): + ''' + Draw a text on a window + + @param window The window + @param gc The window's graphics context + @param x:int The left position of the text + @param y:int The Y position of the bottom of the text + @param text:str The text to draw + ''' + text_ = text.encode('utf-16')[2:] + text = [] + for i in range(len(text_)): + if (i & 1) == 0: + text.append(text_[i]) + else: + text[-1] |= text_[i] << 8 + window.image_text_16(gc, x, y, text) + + def close_x(): ''' Closes the connection to X, but flushes it first -- cgit v1.2.3-70-g09d2