Created
June 17, 2015 00:12
-
-
Save adam-stokes/7fa1b02ba07c74dbccae to your computer and use it in GitHub Desktop.
urwid padding decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from urwid import Padding as _Padding | |
| from functools import partialmethod | |
| def apply_padders(cls): | |
| padding_count = 100 | |
| for i in range(1, padding_count): | |
| setattr(cls, 'push_{}'.format(i), partialmethod(_Padding, left=i)) | |
| setattr(cls, 'pull_{}'.format(i), partialmethod(_Padding, right=i)) | |
| setattr(cls, 'center_{}'.format(i), | |
| partialmethod(_Padding, align='center', | |
| width=('relative', i))) | |
| setattr(cls, 'left_{}'.format(i), | |
| partialmethod(_Padding, align='left', | |
| width=('relative', i))) | |
| setattr(cls, 'right_{}'.format(i), | |
| partialmethod(_Padding, align='right', | |
| width=('relative', i))) | |
| return cls | |
| @apply_padders | |
| class Padding: | |
| """ Padding methods | |
| .. py:meth:: push_X(:class:`urwid.Widget`) | |
| This method supports padding the left side of the widget | |
| from 1-99, for example: | |
| .. code:: | |
| Padding.push_20(Text("This will be indented 20 columns") | |
| .. py:meth:: pull_X(:class:`urwid.Widget`) | |
| This method supports padding the right side of the widget | |
| from 1-99, for example: | |
| .. code:: | |
| Padding.pull_20(Text("This will be right indented 20 columns") | |
| .. py:meth:: center_X(:class:`urwid.Widget`) | |
| This method centers a widget with X being the relative width of | |
| the widget. | |
| .. code:: | |
| Padding.center_10(Text("This will be centered with a " | |
| "width of 10 columns")) | |
| .. py:meth:: left_X(:class:`urwid.Widget`) | |
| This method aligns a widget left with X being the relative width of | |
| the widget. | |
| .. code:: | |
| Padding.left_10(Text("This will be left aligned with a " | |
| "width of 10 columns")) | |
| .. py:meth:: right_X(:class:`urwid.Widget`) | |
| This method right aligns a widget with X being the relative width of | |
| the widget. | |
| .. code:: | |
| Padding.right_10(Text("This will be right aligned with a " | |
| "width of 10 columns")) | |
| """ | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment