MkProgressBar¶
Node to display a CSS-based progress bar.¶
Example: Regular
Jinja
{{ 60 | MkProgressBar }}
Python
MkProgressBar(60)
██████░░░░ 60%
`██████░░░░` 60%
<p><code>██████░░░░</code> 60%</p>
`██████░░░░` 60%
Example: Style thin
Jinja
{{ 60 | MkProgressBar(style="thin") }}
Python
MkProgressBar(60, style='thin')
██████░░░░ 60%
`██████░░░░` 60%
<p><code>██████░░░░</code> 60%</p>
`██████░░░░` 60%
Example: Style candystripe
Jinja
{{ 70 | MkProgressBar(style="candystripe") }}
Python
MkProgressBar(70, style='candystripe')
███████░░░ 70%
`███████░░░` 70%
<p><code>███████░░░</code> 70%</p>
`███████░░░` 70%
Example: Style candystripe_animated
Jinja
{{ 80 | MkProgressBar(style="candystripe_animated") }}
Python
MkProgressBar(80, style='candystripe_animated')
████████░░ 80%
`████████░░` 80%
<p><code>████████░░</code> 80%</p>
`████████░░` 80%
Name |
Children |
Inherits |
|---|---|---|
MkNode |
graph TD
492688635["mkprogressbar.MkProgressBar"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
1359323199 --> 492688635
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkprogressbar/metadata.toml¶
[metadata]
icon = "fa6-solid:bars-progress"
name = "MkProgressBar"
[[resources.css]]
filename = "progressbar.css"
[requirements.extension."pymdownx.progressbar"]
[examples.regular]
title = "Regular"
jinja = """
{{ 60 | MkProgressBar }}
"""
[examples.style_thin]
title = "Style thin"
jinja = """
{{ 60 | MkProgressBar(style="thin") }}
"""
[examples.style_candystripe]
title = "Style candystripe"
jinja = """
{{ 70 | MkProgressBar(style="candystripe") }}
"""
[examples.style_candystripe_animated]
title = "Style candystripe_animated"
jinja = """
{{ 80 | MkProgressBar(style="candystripe_animated") }}
"""
[output.markdown]
template = """
[={{ node.percentage }}% "{{ node.label }}"]
"""
[output.html5]
template = """
<label for="progress_bar">{{ node.label }}:</label>
<progress id="progress_bar" max="100" value="{{ node.percentage }}">{{ node.percentage }}%</progress>
"""
mknodes.basenodes.mkprogressbar.MkProgressBar¶
10class MkProgressBar(mknode.MkNode):
11 """Node to display a CSS-based progress bar."""
12
13 REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.progressbar")]
14 ICON = "fontawesome/solid/bars-progress"
15 CSS = [resources.CSSFile("progressbar.css")]
16 ATTR_LIST_SEPARATOR = ""
17
18 def __init__(
19 self,
20 percentage: int,
21 *,
22 label: str | Literal[True] | None = True,
23 style: Literal["thin", "candystripe", "candystripe_animated"] | None = None,
24 **kwargs: Any,
25 ) -> None:
26 """Constructor.
27
28 Args:
29 percentage: Percentage value for the progress bar
30 label: Label to display on top of progress bar
31 style: Progress bar style
32 kwargs: Keyword arguments passed to parent
33 """
34 super().__init__(**kwargs)
35 self._label = label
36 self.percentage = percentage
37 self.style = style
38 match self.style:
39 case "thin":
40 self.add_css_class("thin")
41 case "candystripe":
42 self.add_css_class("candystripe")
43 case "candystripe_animated":
44 self.add_css_class("candystripe")
45 self.add_css_class("candystripe-animate")
46 case None:
47 pass
48
49 @property
50 def label(self) -> str:
51 match self._label:
52 case str():
53 return self._label.format(percentage=self.percentage)
54 case True:
55 return f"{self.percentage}%"
56 case _:
57 return ""
58
59 def to_md_unprocessed(self) -> str:
60 return rf'[={self.percentage}% "{self.label}"]'
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes¶
93def create_section_for_nodes(
94 nav: mk.MkNav,
95 klasses: Sequence[type[mk.MkNode]],
96) -> mk.MkTable:
97 table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
98 for kls in klasses:
99 tpl = "classpage_custom.jinja"
100 page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
101 nav += page
102 if kls.STATUS:
103 page.metadata.status = kls.STATUS
104 elif kls.JS_FILES:
105 page.metadata.status = "js"
106 elif kls.CSS:
107 page.metadata.status = "css"
108 page.created_by = create_section_for_nodes
109 link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
110 extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
111 table.add_row((link, kls.__doc__, extensions))
112 return table
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7ff77e88b060>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: create_section_for_nodes
source_line_no: 93
hide:
- toc
icon: fontawesome/solid/bars-progress
status: css
title: MkProgressBar