mirror of
https://github.com/ublue-os/forge.git
synced 2025-04-23 15:03:44 +03:00
59 lines
2 KiB
Python
59 lines
2 KiB
Python
![]() |
#!/usr/bin/env python3
|
||
|
import asyncio
|
||
|
import os.path
|
||
|
import platform
|
||
|
import shlex
|
||
|
import sys
|
||
|
|
||
|
from nicegui import ui
|
||
|
|
||
|
async def run_command(command: str) -> None:
|
||
|
"""Run a command in the background and display the output in the pre-created dialog."""
|
||
|
dialog.open()
|
||
|
result.content = ''
|
||
|
command = command.replace('python3', sys.executable) # NOTE replace with machine-independent Python path (#1240)
|
||
|
process = await asyncio.create_subprocess_exec(
|
||
|
*shlex.split(command, posix='win' not in sys.platform.lower()),
|
||
|
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT,
|
||
|
cwd=os.path.dirname(os.path.abspath(__file__))
|
||
|
)
|
||
|
# NOTE we need to read the output in chunks, otherwise the process will block
|
||
|
output = ''
|
||
|
while True:
|
||
|
new = await process.stdout.read(4096)
|
||
|
if not new:
|
||
|
break
|
||
|
output += new.decode()
|
||
|
# NOTE the content of the markdown element is replaced every time we have new output
|
||
|
result.content = f'```\n{output}\n```'
|
||
|
|
||
|
with ui.header().classes(replace='row items-center') as header:
|
||
|
ui.button(on_click=lambda: left_drawer.toggle(), icon='menu').props('flat color=white')
|
||
|
with ui.tabs() as tabs:
|
||
|
ui.tab('Home')
|
||
|
ui.tab('Ansible')
|
||
|
ui.tab('Registry')
|
||
|
|
||
|
with ui.footer(value=False) as footer:
|
||
|
ui.label('Footer')
|
||
|
|
||
|
with ui.left_drawer().classes('bg-blue-100') as left_drawer:
|
||
|
ui.label('Side menu')
|
||
|
|
||
|
ui.button('Build Project', on_click=lambda: run_command('python3 runner.py')).props('no-caps')
|
||
|
with ui.dialog() as dialog, ui.card():
|
||
|
result = ui.markdown()
|
||
|
|
||
|
|
||
|
with ui.page_sticky(position='bottom-right', x_offset=20, y_offset=20):
|
||
|
ui.button(on_click=footer.toggle, icon='contact_support').props('fab')
|
||
|
|
||
|
with ui.tab_panels(tabs, value='A').classes('w-full'):
|
||
|
with ui.tab_panel('A'):
|
||
|
ui.label('Content of A')
|
||
|
with ui.tab_panel('B'):
|
||
|
ui.label('Content of B')
|
||
|
with ui.tab_panel('C'):
|
||
|
ui.label('Content of C')
|
||
|
|
||
|
ui.run()
|