2018-01-02 18:57:04 +01:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2018-01-05 22:13:30 +01:00
|
|
|
|
from .__base__ import *
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
|
|
__all__ = ["TextoutProgressTag"]
|
|
|
|
|
|
2018-01-05 22:13:30 +01:00
|
|
|
|
class TextoutProgressTag(TextoutRawBlockTag):
|
2018-01-02 18:57:04 +01:00
|
|
|
|
""" Progress tag, used to display the progress on anything.
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
|
|
[progress=50]My great progress bar[/progress]
|
|
|
|
|
[progress=100][/progress] """
|
|
|
|
|
|
2018-01-05 22:13:30 +01:00
|
|
|
|
aliases = ('[progress]',)
|
|
|
|
|
|
2018-01-16 13:34:11 +01:00
|
|
|
|
def prepare(self, name, value):
|
2018-01-21 22:08:23 +01:00
|
|
|
|
self._val = int(value)
|
|
|
|
|
if self._val < 0 or self._val > 100:
|
2018-01-02 18:57:04 +01:00
|
|
|
|
raise Exception("progress value should be between 0 and 100 incl.")
|
|
|
|
|
|
2018-01-16 13:34:11 +01:00
|
|
|
|
def end_text(self):
|
2018-01-21 22:08:23 +01:00
|
|
|
|
val = self._val / 5
|
2018-01-16 13:34:11 +01:00
|
|
|
|
return '\n|{}|\n'.format('X' * val + '-' * (20 - val))
|
|
|
|
|
|
|
|
|
|
def begin_html(self):
|
|
|
|
|
return '<div>'
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-01-16 13:34:11 +01:00
|
|
|
|
def end_html(self):
|
|
|
|
|
return '' \
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'<div style="background-color: white; border: 1px solid black; ' \
|
|
|
|
|
'width: 50%; margin-top: 2px; text-align: left;">' \
|
|
|
|
|
'<div style="background-color: #FF3E28; color: black; ' \
|
|
|
|
|
'font-weight: bold; max-width: 100%; width: {}%;' \
|
|
|
|
|
'height: 18px;"> {}%' \
|
2018-01-21 22:08:23 +01:00
|
|
|
|
'</div></div></div>'.format(self._val, self._val)
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
|
|
# End of file.
|