-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
The pywebview window calls aren't returning data from fn
my code
# Instead of directly opening the dialog, send a request to the UI process
def open_file_dialog(self):
state, ctrl = GLOBAL_APP.server.state, GLOBAL_APP.server.controller
# Send the action to the UI process
result = ctrl.pywebview_window_call(
"create_file_dialog",
webview.FileDialog.OPEN,
file_types = ('PVD Files (*.pvd)', 'All Files (*.*)'),
allow_multiple = False
)
logging.info(f"File dialog result: {result}")
result never comes back, should probably be async anyway ... so I cant hook it up to the on_message on the server or a client state or anything else
# Register a handler for messages from the UI process
def on_message(msg):
# Check for file dialog result
logging.info(f"Received file dialog result: {msg}")
if isinstance(msg, dict) and msg.get("action") == "file_dialog_result":
logging.info(f"Received file dialog result: {msg} {dict}")
result = msg["result"]
# Set the result in the trame state
app.server.state.file_to_open = result
# ...existing message handling...
app.server.on_message = on_message
menu = [
("File", [
("Open...", "open_file_dialog"),
]),
# ("Help", [("About", app.show_about)]),
]
def on_message(msg):
logging.info(f"Message {msg}")
if msg == "menu:open_file_dialog":
app.open_file_dialog()
app.server.start(exec_mode="desktop",
maximized=True,
menu=menu,
on_message=on_message
)
Trame code
async def _monitor_action_requests(self):
while self._monitoring:
await asyncio.sleep(0.5)
if not self._action_queue.empty():
msg = self._action_queue.get_nowait()
action = msg.get("action")
args = msg.get("args", [])
kwargs = msg.get("kwargs", {})
fn = getattr(self._main_window, action)
if action == "destroy":
self.exit()
fn(*args, **kwargs)
This prevents me from being able to user pywebview menu to do a file->open in trame web view. I'd prefer not having to get rust just for file open, if we could have a return queue for pywebview that would help a ton.
Metadata
Metadata
Assignees
Labels
No labels