Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call native window methods from NiceGUI main thread #917

Merged
merged 23 commits into from
May 30, 2023

Conversation

rodja
Copy link
Member

@rodja rodja commented May 13, 2023

This PR provides a pywebview proxy object app.native.window to call methods on the window object in the pywebview process. This solves #909 and other issues like #770. It may also be used as basis to implement a native file picker. Possibly the core requirement behind #892 is also related.

Example usage:

async def startup():
    app.native.main_window.resize(1000, 700)
    app.native.main_window.load_url('https://nicegui.io')
    w, h = await app.native.main_window.get_size()
    x, y = await app.native.main_window.get_position()
    print(f'window: {w}x{h} at {x},{y}', flush=True)
    await asyncio.sleep(1)
    selected_files = await app.native.main_window.create_file_dialog()
    print(selected_files, flush=True)

async def update():
    on_top.set_text(f'{await app.native.main_window.is_always_on_top()}')

ui.switch('ontop', on_change=lambda args: app.native.main_window.set_always_on_top(args.value))
on_top = ui.label()
ui.timer(0.1, update)

app.on_startup(startup)

ToDos

  • replace print messages with logging
  • allow receiving of return values from window methods (awaitable?)
  • implement get_size and get_position
  • provide type annotations
  • documentation

rodja added 4 commits May 12, 2023 07:24
fails because queue is not passed to uvicorn subprocess when reload=True
neccessary for pywebview when running as subprocess with reload=True
@rodja rodja changed the title Make native window controllable from NiceGUI main thread Call native window from NiceGUI main thread May 13, 2023
@rodja rodja changed the title Call native window from NiceGUI main thread Call native window methods from NiceGUI main thread May 13, 2023
@rodja rodja added the enhancement New feature or request label May 13, 2023
@rodja rodja requested a review from falkoschindler May 27, 2023 11:29
@rodja rodja marked this pull request as ready for review May 27, 2023 11:29
@rodja rodja added this to the 1.2.16 milestone May 27, 2023
@rodja rodja merged commit d1c2602 into main May 30, 2023
@rodja rodja deleted the changeable_native_window branch May 30, 2023 12:39
@retsyo
Copy link
Contributor

retsyo commented Dec 7, 2023

anyway to set the caption of native file dialog? for example, "please select config file to load"

btw, app.native.main_window.is_always_on_top() is app.native.main_window.get_always_on_top() in current

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants