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

Keyboard focus on MacOS #66

Closed
diegojromerolopez opened this issue Dec 19, 2016 · 21 comments
Closed

Keyboard focus on MacOS #66

diegojromerolopez opened this issue Dec 19, 2016 · 21 comments

Comments

@diegojromerolopez
Copy link

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.

@r0x0r
Copy link
Owner

r0x0r commented Dec 26, 2016

Hey, I don't quite follow what the problem is. What is exactly the problem and what platform are you using?

@diegojromerolopez
Copy link
Author

I launch the application from the terminal and when writing in an input field the text appears in the terminal. So I assumed that there was a problem with the focus.

OS is OSX El Capitan 10.11.6.

@r0x0r
Copy link
Owner

r0x0r commented Dec 26, 2016

I cannot reproduce it. I have tested it flask_app by adding an input box to examples/flask_app/gui/index.html

@diegojromerolopez
Copy link
Author

Hi r0x0r I've made a pull request with a small Django application that suffers of this problem. There is information about running this app in the pull request.

Thank you.

@r0x0r
Copy link
Owner

r0x0r commented Dec 27, 2016

This issue seems to occur only under virtualenv. Could you verify that this is the case on your machine?
I don't have much experience in virtualenv. No idea where to look for the problem.

@diegojromerolopez
Copy link
Author

I'm going to try to use another alternative method to virtualenv and see what happens.

@r0x0r
Copy link
Owner

r0x0r commented Jan 6, 2017

Any update?

@diegojromerolopez
Copy link
Author

I've tried using docker and no luck so far.

I'm going to use some packaging tool like py2app next week and see how it goes.

@r0x0r
Copy link
Owner

r0x0r commented Jan 13, 2017

The problem is caused by the Python interpreter supplied by virtualenv. It acts as a command line application and does not properly register a GUI window with OSX.
I managed to fix the issue by copying the original python executable over your_virtual_env/bin/python.
The virtualenv documentation also describes another way to use a virtualenv with an alternative python interpreter.
https://virtualenv.pypa.io/en/stable/userguide/#using-virtualenv-without-bin-python

@ericmjl
Copy link

ericmjl commented Jan 13, 2017

I see. It must be the same with my Conda installation in #68. Thanks for finding the cause, @r0x0r!

@diegojromerolopez
Copy link
Author

Thank you @r0x0r I'm going to check it!

@r0x0r
Copy link
Owner

r0x0r commented Jan 14, 2017

Updated README with this info.

@r0x0r r0x0r closed this as completed Jan 14, 2017
@r0x0r
Copy link
Owner

r0x0r commented Jan 14, 2017

This seems to be related as well https://github.com/gldnspud/virtualenv-pythonw-osx/

@diegojromerolopez
Copy link
Author

Confirming that with https://github.com/gldnspud/virtualenv-pythonw-osx pywebview works 100%. Thanks!

@cateee
Copy link

cateee commented Mar 7, 2017

BTW, I think this issue should remain open, until it will be solved (possibly by some dependencies). And in README, I don't think the title is appropriate. VirtualEnv is a cause, but I think the title should have the real issue: e.g. "Lack of keyboard events on macos/cocoa".

Reading StackOverflow, it is a common problem (in objc), so I assume it is due to some subtle change in pyobjc, or just pywebview not keeping up the new flags, interfaces, etc. I've tried many "solutions", but without luck, and pyobjc examples are designed in a very different way.

In any case, forcing QT solves the problem, allowing me to use virtual environment and python 3.6. (which is important for me, because of backend code, and using to processes it is not so clean)

@psytron
Copy link

psytron commented Oct 7, 2019

+1 Still experiencing this issue. ( Python 3.7.4 Mac OSX Mojave 10.14.6 ).

All keyboard input is captured by terminal window.
Typing in webview input fields doesn't work.

@shakfu
Copy link

shakfu commented Nov 4, 2019

I confirm I had the same issue trying to run the todos example out of a virtualenv on mac os 10.14.6 (home brewed Python 3.7.5): text was consistently routed to the terminal (even when I detached the process with 'python start.py &'

@lwerdna
Copy link

lwerdna commented May 22, 2020

I have the same issue running the todos example. Typing in the input field is echoed in the terminal.
OS: MacOS 10.15 Catalina
Python: 3.7.4 installed in pyenv

@crystalthoughts
Copy link

crystalthoughts commented Sep 19, 2021

I agree that this should be reopened. At least a check should be added with a descriptive message of the problem. For future conda users - in your environment run conda install python.app then run your script using pythonw, e.g pythonw main.py.

@r0x0r
Copy link
Owner

r0x0r commented Sep 19, 2021

@danvenn what check do you propose?

@crystalthoughts
Copy link

crystalthoughts commented Sep 27, 2021

@r0x0r I couldn't tell you the best way, but one way might be to check if an OSX user is inside a venv, then restart using pythonw / python framework. Looks like there has been some discussion and fixes in the matplotlib repo about this issue. (see here)

Rough code idea:

import sys
if sys.platform == "darwin":         #If OSX
    if sys.prefix != sys.base_prefix: # and if inside a venv
        ## warn user ##
        ## check if using framework/ pythonw ##
        ## restart with framework ## -> os.execv(  ..... , sys.argv) 

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

No branches or pull requests

8 participants