Repository: r0x0r/pywebview

Issue #66: Keyboard focus on MacOS
Created: 2016-12-19T19:38:35Z
Hello r0x0r, when trying to type in an input the focus is on the terminal that called the Python application but mouse works perfectly. I tried reading the docs thinking I maybe needed an specific parameter or setting but I'm not sure which one.
My application is a embebed Django web application and this is the main file that create the webview. Here is the call to webview constructor
What I'm doing wrong? Any help is appreciated.
Thank you.

Duplicate issue #1080: Keyboard button presses go to the shell instead of the opened web view in pywebview flask example project
Created: 2023-03-27T06:40:12Z
Description
When running the flask example project, keyboard button presses are not going into the opened web view, but into the shell in which the web view was launched. This is happening on MacOS 13.2.1 (22D68) on M2. I have tried using different versions of Python (3.8.16, 3.9.7, and 3.10.10), different versions of pywebview (3.5, 3.6, and 4.0.2), and different versions of poetry (1.2 and 1.4) with no success. I have also tried forcing pyobjc 8.5.1, but the issue persists.

  
    
    

    Screen.Recording.2023-03-27.at.07.27.26.mov
    
  

  

  


My co-worker is able to reproduce the issue using poetry (both versions), but he can run the example using pip and a Python version without a virtual environment. I was able to run the example on a Ubuntu VM with bare Python. However, when using poetry in Ubuntu, I get the error message: webview.util.WebViewException: You must have either QT or GTK with Python extensions installed in order to use pywebview. Everything works fine when I open a browser window and navigate to the URL created by running the example pywebview app.
Reading through #66 I was able to get it to run by installing and using homebrew python. This is a works but makes it harder to work in a usual development environment and manage dependencies. Is there a way to make pywebview work using virtual environments like pyenv, conda and poetry?
Running an the app built via pyinstaller has the same issue both while using homebrew python and pyenv/poetry/virtualenv pythons.
When using py2app with the following setup.py, I get
Error loading Python lib '/Users/petertrost/dev/pywebview/examples/flask_app/build/main/libpython3.8.dylib': dlopen: dlopen(/Users/petertrost/dev/pywebview/examples/flask_app/build/main/libpython3.8.dylib, 0x000A): tried: '/Users/petertrost/dev/pywebview/examples/flask_app/build/main/libpython3.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/petertrost/dev/pywebview/examples/flask_app/build/main/libpython3.8.dylib' (no such file), '/Users/petertrost/dev/pywebview/examples/flask_app/build/main/libpython3.8.dylib' (no such file)

setup.py:
import os
from setuptools import setup


def tree(src):
    return [(root, map(lambda f: os.path.join(root, f), files))
        for (root, dirs, files) in os.walk(os.path.normpath(src))]


ENTRY_POINT = ['src/backend/main.py']

DATA_FILES = tree('gui')
OPTIONS = {'argv_emulation': False,
           'strip': True,
           #'iconfile': 'icon.icns', # uncomment to include an icon
           'includes': ['flask', 'WebKit', 'Foundation', 'webview']}

setup(
    app=ENTRY_POINT,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)
Steps to reproduce

Clone the pywebview repository: git clone https://github.com/r0x0r/pywebview.git
Navigate to the examples/flask directory: cd pywebview/examples/flask
Activate a virtual environment or initialize a poetry environment or use pyenv versions
Install dependencies using pip or poetry install
Run the example with either python src/backend/main.py or poetry run python src/backend/main.py
Press some keyboard buttons and notice that they go to the shell instead of the web view.

Expected behavior
Keyboard button presses should go to the opened web view in the pywebview flask example project.
Actual behavior
Keyboard button presses go to the shell instead of the opened web view in the pywebview flask example project.
Environment
Operating system: MacOS 13.2.1 (22D68) on M2
Python version(s): 3.8.16, 3.9.7, and 3.10.10 (pyenv), works in 3.11.2 (homebrew)
Pywebview version(s): 3.5, 3.6, and 4.0.2
Poetry version(s): 1.2 and 1.4
Practicalities


YES I am willing to work on this issue myself.


NO I am prepared to support this issue financially.

Closing comment (2023-08-14T05:36:07Z): Is it possible to reopen this? Does appear related to #66. Getting the same issue as @intervall-peter regardless of venv or system-wide python.
Only difference between the two is a venv redirects input to VSCode, whereas running from a terminal sends input to the terminal — even if that terminal is integrated into VSCode.



Name
Version




os
macOS 12.6.7 (21G651)


arch
m1 pro (arm64)


python
3.11.4


pywebview
4.2.2


vscode
1.81.0