aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-04 00:18:45 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-04 00:18:45 +0100
commita0527773322ef6c8324dc57bfeb33118bd5f62cb (patch)
treed387f026d321bb172f889c30b01331d53cac2f68
parentm (diff)
downloadxpybar-a0527773322ef6c8324dc57bfeb33118bd5f62cb.tar.gz
xpybar-a0527773322ef6c8324dc57bfeb33118bd5f62cb.tar.bz2
xpybar-a0527773322ef6c8324dc57bfeb33118bd5f62cb.tar.xz
reduce filker
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--TODO2
-rw-r--r--examples/moderate2
-rwxr-xr-xsrc/__main__.py39
3 files changed, 40 insertions, 3 deletions
diff --git a/TODO b/TODO
index dfed92a..d4b4fde 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-Reduce filker
-
List of plugins to implement:
iostat [-x] [-d] [-N] -zk [-p | <devices>...] <interval>
diff --git a/examples/moderate b/examples/moderate
index 3c14fe3..d47c704 100644
--- a/examples/moderate
+++ b/examples/moderate
@@ -232,8 +232,8 @@ semaphore = threading.Semaphore()
def redraw():
if semaphore.acquire(blocking = False):
values = pattern % tuple([f() for f in functions])
- bar.clear()
#print(values.replace('\0', ' ' * 8))
+ bar.partial_clear(0, bar.width, 10, 0, 2, values)
bar.draw_coloured_splitted_text(0, bar.width, 10, 0, 2, values)
semaphore.release()
return True
diff --git a/src/__main__.py b/src/__main__.py
index 5c9f831..1196341 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -349,6 +349,45 @@ class Bar:
'''
self.gc.change(font = font)
+ def partial_clear(self, x, width, y, ascent, descent, text):
+ '''
+ Fill the panel with its background colour on areas that are not
+ about to be over painted with text and reset the colour and font
+
+ @param x:int The left position of the text
+ @param width:int The width of the print area
+ @param y:int The Y position of the bottom of the text
+ @param ascent:int Extra height above the text on each line
+ @param descent:int Extra height under the text on each line
+ @param text:str The text to draw, '\0' is column delimiter inside each line
+ '''
+ line_height, areas = ascent + self.font_height + descent, []
+ y -= self.font_height - ascent
+
+ for line in text.split('\n'):
+ if '\0' not in line:
+ x_ = Bar.coloured_length(line)
+ areas.append((x + x_, y, width - x_, line_height))
+ else:
+ areas_ = []
+ parts = line.split('\0')
+ i, n = 0, len(parts) - 1
+ for part in parts:
+ w = Bar.coloured_length(part) * self.font_width
+ x_ = int((width - w) * i / n)
+ areas_.append((x_, x_ + w))
+ i += 1
+ x1 = areas_[0][1]
+ for x2, x3 in areas_[1:]:
+ areas.append((x + x1, y, x2 - x1, line_height))
+ x1 = x3
+ y += line_height
+
+ self.change_colour(self.background)
+ self.window.poly_fill_rectangle(self.gc, areas)
+ self.change_colour(self.foreground)
+ self.change_font(self.font)
+
def clear(self):
'''
Fill the panel with its background colour and reset the colour and font