diff options
| author | Zach DeCook <zachdecook@librem.one> | 2022-12-22 20:45:08 -0500 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2022-12-22 20:45:08 -0500 |
| commit | 7f7c524cf1cd6188d8704af3d211ce2c0a8b4e6f (patch) | |
| tree | 07c2e55dedd2609beafb5a41c26781331a939ccf /gemtext.py | |
| parent | a2707df86fcd7541840f2f3091953b717a6a101b (diff) | |
| download | browset-7f7c524cf1cd6188d8704af3d211ce2c0a8b4e6f.tar.gz | |
Gemtext: Dynamically add new content
Diffstat (limited to 'gemtext.py')
| -rw-r--r-- | gemtext.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/gemtext.py b/gemtext.py index df8402c..62640a3 100644 --- a/gemtext.py +++ b/gemtext.py @@ -5,23 +5,28 @@ from textual.containers import Container class Gemtext(Static): """Gemtext widget.""" items = [] - def compose(self) -> ComposeResult: - yield Container(*self.items) + #def compose(self) -> ComposeResult: + # yield Container(id="content") - def __init__(self, txt): - super().__init__() + def __init__(self, txt, id): + super().__init__(id=id) + self.update(txt) + def update(self, txt): + #S = self.query("Static") + #if S: + # S.last().remove() for line in txt.split('\n'): if line.startswith("=>"): path = line[2:].lstrip().split(' ')[0] text = ' '.join(line[2:].lstrip().split(' ')[1:]) - self.items.append(Button(text or path, name=path)) + self.mount(Button(text or path, name=path)) else: - self.items.append(Static(line)) + self.mount(Static(line)) if __name__ == "__main__": from textual.app import App class Test(App): def compose(self) -> ComposeResult: - yield Gemtext(txt="#title\n=> /href link text\nworld star hiphop") + yield Gemtext(txt="#title\n=> /href link text\nworld star hiphop", id="yo") app = Test() app.run() |
