PyWebView window calls not returning data

オープン
#63 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
backend, desktop

調査の方向性

pywebview_window_call と _monitor_action_requests から始め、次に _action_queue がアクションをディスパッチする仕組みと、server on_message がどのように登録されるかを追跡します。既存の menu:open_file_dialog フローを確認し、呼び出し結果をどこで観測できるかを判断します。create_file_dialog の結果が UI をブロックせずにアプリケーションへ届き、ファイルを開くワークフローで利用できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
17
フォーク
16
平均マージ
1日 15時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Kitware/trame-server のほかの issue

Kitware/trame-server の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。