aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-07-02 10:08:12 +0200
committerMattias Andrée <maandree@operamail.com>2014-07-02 10:08:12 +0200
commitee3d7d8c2128672342a29ab9926c1263e39f6e95 (patch)
treeac338b74bd36d177075471d2295350479fb747f6 /src
parentm (diff)
downloadxpybar-ee3d7d8c2128672342a29ab9926c1263e39f6e95.tar.gz
xpybar-ee3d7d8c2128672342a29ab9926c1263e39f6e95.tar.bz2
xpybar-ee3d7d8c2128672342a29ab9926c1263e39f6e95.tar.xz
add support for long texts
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/__main__.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/__main__.py b/src/__main__.py
index c545a66..e8120f4 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -154,7 +154,7 @@ class Bar:
'''
return self.font.query_text_extents(text).overall_width
- def draw_text(self, x, y, descent, text): ## TODO fix support for text longer than 255 symbols
+ def draw_text(self, x, y, descent, text):
'''
Draw a text
@@ -171,9 +171,15 @@ class Bar:
for c in text + '\0':
if c in special:
if not buf == '':
- draw_text(self.window, self.gc, x, y, buf)
- x += self.font_width * len(buf)
- buf = ''
+ if len(buf.encode('utf-8')) > 255:
+ while not buf == '':
+ sbuf, buf = buf[:42], buf[42:]
+ draw_text(self.window, self.gc, x, y, sbuf)
+ x += self.font_width * len(sbuf)
+ else:
+ draw_text(self.window, self.gc, x, y, buf)
+ x += self.font_width * len(buf)
+ buf = ''
if not c == '\0':
segs = []
if c in '─┼┬┴': segs.append((0, 1, 2, 1))