2
0
Fork 0
textout/textoutpc/Tags/Progress.py

39 lines
1.0 KiB
Python
Raw Normal View History

2018-01-02 18:57:04 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .__base__ import *
2018-01-02 18:57:04 +01:00
__all__ = ["TextoutProgressTag"]
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] """
aliases = ('[progress]',)
2018-01-16 13:34:11 +01:00
def prepare(self, name, value):
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):
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;">{}%' \
'</div></div></div>'.format(self._val, self._val)
2018-01-02 18:57:04 +01:00
# End of file.