-
import asyncio
from rich.tree import Tree
from textual.app import App
from textual.widgets import ScrollView
class MTree(App):
async def on_load(self, event):
await self.bind('q', 'quit', 'Quit app')
async def on_mount(self, event):
self.body = ScrollView(name='MTree')
await self.view.dock(self.body)
self.mbTree = Tree('root')
self.mbTree.hide_root = True
for c in ['a', 'b', 'c']:
node = self.mbTree.add(c)
await self.body.update(self.mbTree)
await self.call_later(self.updateTree,node)
async def updateTree(self, _node):
await asyncio.sleep(2)
_node.label = _node.label + ' R'
await self.body.update(self.mbTree)
MTree.run(title='MTree') The whole App get's displayed, after all updateTree calls are finished. |
Beta Was this translation helpful? Give feedback.
Answered by
mharig
Mar 16, 2022
Replies: 2 comments
-
I found a more or less minimal solution, that does what I want: import asyncio
from concurrent.futures import ThreadPoolExecutor
from rich.tree import Tree
from rich.panel import Panel
from textual.widget import Widget
from textual.app import App
from textual.widgets import ScrollView
from time import sleep
class MboxTree(Widget):
def on_mount(self):
self.mbTree = Tree('root')
self.mbTree.hide_root = True
self.nodes = []
for c in ['a', 'b', 'c']:
node = self.mbTree.add(c)
self.nodes.append(node)
self.panel = Panel(
self.mbTree,
title='Title',
title_align='left'
)
self.refresh()
self.executor = ThreadPoolExecutor(max_workers=3)
self.updateTree()
def getNewLabel(self, _node):
sleep(2)
_node.label = _node.label + ' R'
self.refresh()
def updateTree(self):
loop = asyncio.get_event_loop()
for node in self.nodes:
loop.run_in_executor(self.executor, self.getNewLabel, node)
def render(self) -> Panel:
return self.panel
class MTree(App):
async def on_load(self, event):
await self.bind('q', 'quit', 'Quit app')
async def on_mount(self, event):
self.body = MboxTree()
await self.view.dock(self.body)
MTree.run(title='MTree', log='minimal_tui.log') Sorry for my misunderstanding of asyncio. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mharig
-
This was very helpful to me, thanks @mharig! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found a more or less minimal solution, that does what I want: