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

37 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-02 18:57:04 +01:00
def _prepare(self):
self.val = int(self.value)
if self.val < 0 or self.val > 100:
raise Exception("progress value should be between 0 and 100 incl.")
def process_text(self, mode):
2018-01-02 18:57:04 +01:00
val /= 5
return '{}{}|{}|{}'.format(self.content, mode.newline,
'X' * val + '-' * (20 - val), mode.newline)
def process_html(self, mode):
2018-01-02 18:57:04 +01:00
return '<div>{}' \
'<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.content, self.val, self.val)
# End of file.