2
0
Fork 0
textout/textoutpc/builtin/_Progress.py

37 lines
1021 B
Python
Raw Normal View History

2018-01-02 18:57:04 +01:00
#!/usr/bin/env python3
#******************************************************************************
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
2018-01-02 18:57:04 +01:00
from .. import BlockTag as _BlockTag
2018-01-02 18:57:04 +01:00
__all__ = ["ProgressTag"]
2018-01-02 18:57:04 +01:00
2018-08-25 17:38:24 +02:00
class ProgressTag(_BlockTag):
2018-01-02 18:57:04 +01:00
""" Progress tag, used to display the progress on anything.
Usage:
2018-08-25 17:38:24 +02:00
2018-01-02 18:57:04 +01:00
[progress=50]My great progress bar[/progress]
[progress=100][/progress] """
aliases = ('[progress]',)
raw = True
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 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-08-25 17:38:24 +02:00
'<div class="progress">' \
'<div class="progress-inner" style="width: {}%;">{}%' \
'</div></div></div>'.format(self._val, self._val)
2018-01-02 18:57:04 +01:00
# End of file.