diff options
author | luke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937> | 2013-10-07 02:58:33 +0000 |
---|---|---|
committer | luke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937> | 2013-10-07 02:58:33 +0000 |
commit | f8057aa657f55e87731bb3dc5700fef8d87f3b67 (patch) | |
tree | f9eb852b38d57bee2bbb6ba791b491015912e619 | |
parent | 1d6399068e43ba96a05a750b68be91289fcd18c9 (diff) | |
download | python-prettytable-f8057aa657f55e87731bb3dc5700fef8d87f3b67.tar.gz |
Initial implementation of min_width.
git-svn-id: http://prettytable.googlecode.com/svn/trunk@139 0f58610c-415a-11de-9c03-5d6cfad8e937
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | prettytable.py | 15 |
2 files changed, 15 insertions, 1 deletions
@@ -1,5 +1,6 @@ ########## PrettyTable 0.8 - Oct XX, 2013 ########### +* Added "min_width" attribute/option. * Added "title" attribute/option for table titles. * When slice syntax is used to create a new sub-table out of an existing table, the rows are sorted before, not after, the slicing. diff --git a/prettytable.py b/prettytable.py index a80ec20..f39eed1 100644 --- a/prettytable.py +++ b/prettytable.py @@ -119,6 +119,7 @@ class PrettyTable(object): self._align = {} self._valign = {} self._max_width = {} + self._min_width = {} self._rows = [] if field_names: self.field_names = field_names @@ -263,7 +264,7 @@ class PrettyTable(object): def _validate_option(self, option, val): if option in ("field_names"): self._validate_field_names(val) - elif option in ("start", "end", "max_width", "padding_width", "left_padding_width", "right_padding_width", "format"): + elif option in ("start", "end", "max_width", "min_width", "padding_width", "left_padding_width", "right_padding_width", "format"): self._validate_nonnegative_int(option, val) elif option in ("sortby"): self._validate_field_name(option, val) @@ -466,6 +467,16 @@ class PrettyTable(object): self._max_width[field] = val @property + def min_width(self): + return self._min_width + + @min_width.setter + def min_width(self, val): + self._validate_option("min_width", val) + for field in self._field_names: + self._min_width[field] = val + + @property def fields(self): """List or tuple of field names to include in displays""" return self._fields @@ -949,6 +960,8 @@ class PrettyTable(object): widths[index] = max(widths[index], min(_get_size(value)[0], self.max_width[fieldname])) else: widths[index] = max(widths[index], _get_size(value)[0]) + if fieldname in self.min_width: + widths[index] = max(widths[index], self.min_width[fieldname]) self._widths = widths def _get_padding_widths(self, options): |