diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-04 00:18:45 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-04 00:18:45 +0100 |
commit | a0527773322ef6c8324dc57bfeb33118bd5f62cb (patch) | |
tree | d387f026d321bb172f889c30b01331d53cac2f68 /src/__main__.py | |
parent | m (diff) | |
download | xpybar-a0527773322ef6c8324dc57bfeb33118bd5f62cb.tar.gz xpybar-a0527773322ef6c8324dc57bfeb33118bd5f62cb.tar.bz2 xpybar-a0527773322ef6c8324dc57bfeb33118bd5f62cb.tar.xz |
reduce filker
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/__main__.py')
-rwxr-xr-x | src/__main__.py | 39 |
1 files changed, 39 insertions, 0 deletions
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 |