From 4aa1bfc52d8cdfe9ef7872dd2b447db052054f96 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 27 Feb 2014 22:27:29 +0100 Subject: [PATCH] Started making a crop addition to evtable --- src/utils/evtable.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils/evtable.py b/src/utils/evtable.py index 3dbae6a8df..6304192188 100644 --- a/src/utils/evtable.py +++ b/src/utils/evtable.py @@ -283,6 +283,11 @@ class Cell(object): border_top - top border width border_bottom - bottom border width + crop_string - string to use when cropping sideways, + default is '[...]' + crop - crop content of cell rather than expand vertically, + default=False + border_char - this will use a single border char for all borders. overruled by individual settings below border_left_char - char used for left border @@ -328,6 +333,8 @@ class Cell(object): vfill_char = kwargs.get("vfill_char", fill_char) self.vfill_char = vfill_char[0] if vfill_char else " " + self.crop_string = kwargs.get("crop_string", "[...]") + # borders and corners borderwidth = kwargs.get("border_width", 0) self.border_left = kwargs.get("border_left", borderwidth) @@ -375,6 +382,13 @@ class Cell(object): # prepare data self.formatted = self._reformat() + def _crop(self, text, width): + "Apply cropping of text" + if len(text) > width: + crop_string = self.crop_string + return text[:width-len(crop_string)] + crop_string + return text + def _reformat(self): "Apply formatting" return self._border(self._pad(self._valign(self._align(self._fit_width(self.data))))) @@ -822,7 +836,6 @@ class EvTable(object): bwidth = self.border_width headchar = self.header_line_char - cchar = self.corner_char # use the helper functions to define various # table "styles"