Update the Rio Version, add meta tags, refactor rio components that have init overwrites, add member picture for Tim
This commit is contained in:
@@ -1,34 +1,36 @@
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import rio
|
||||
|
||||
|
||||
class NewsPost(rio.Component):
|
||||
def __init__(self, header: str, article_text: Union[str, Path], date: str):
|
||||
super().__init__()
|
||||
header: str
|
||||
date: str
|
||||
article_text_path_or_text: str | Path
|
||||
article_text = ""
|
||||
|
||||
@rio.event.on_populate
|
||||
def on_populate(self):
|
||||
self.align_y = 0
|
||||
self.margin_top = 0
|
||||
self.margin_bottom = 2
|
||||
self.margin_right = 1
|
||||
self._header = header
|
||||
self._date = date
|
||||
if isinstance(article_text, str):
|
||||
self._article_text = article_text
|
||||
elif isinstance(article_text, Path):
|
||||
with open(article_text, "r", encoding="utf-8") as f:
|
||||
self._article_text = f.read()
|
||||
if isinstance(self.article_text_path_or_text, str):
|
||||
self.article_text = self.article_text_path_or_text
|
||||
elif isinstance(self.article_text_path_or_text, Path):
|
||||
with open(self.article_text_path_or_text, "r", encoding="utf-8") as f:
|
||||
self.article_text = f.read()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
return rio.Rectangle(
|
||||
content=rio.Column(
|
||||
rio.Row(
|
||||
rio.Text(self._header, align_x=0.1, style="heading2"),
|
||||
rio.Text(self._date, align_x=0.9, style=rio.TextStyle(italic=True)),
|
||||
rio.Text(self.header, align_x=0.1, style="heading2"),
|
||||
rio.Text(self.date, align_x=0.9, style=rio.TextStyle(italic=True)),
|
||||
margin_top=0.5
|
||||
),
|
||||
rio.Column(
|
||||
rio.Markdown(self._article_text, margin=1)
|
||||
rio.Markdown(self.article_text, margin=1)
|
||||
)
|
||||
),
|
||||
fill=self.session.theme.neutral_color,
|
||||
@@ -37,3 +39,15 @@ class NewsPost(rio.Component):
|
||||
shadow_color=self.session.theme.hud_color,
|
||||
shadow_offset_y=0
|
||||
)
|
||||
|
||||
|
||||
def build_news_post(header: str, article_text_path_or_text: str | Path, date: str) -> NewsPost:
|
||||
return NewsPost(
|
||||
header=header,
|
||||
article_text_path_or_text=article_text_path_or_text,
|
||||
date=date,
|
||||
align_y=0,
|
||||
margin_top=0,
|
||||
margin_bottom=2,
|
||||
margin_right=1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user