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
MacOS window opens in the background and does not receive focus #2499
Comments
This issue has been mentioned on Discuss wxPython. There might be relevant details there: https://discuss.wxpython.org/t/window-starts-hidden-in-vscode-on-osx/36791/2 |
I'm having the same issue. Doesn't look like the linked discussion was able to resolve the issue other than by including a new large dependency (Cocoa Python package). I have been able to get it to take focus on app startup (just using Edit: It looks like this same issue happens with a minimal example in C++ wxWidgets if we build to |
FWIW, this seems to be a regression with wxPython (or wx itself) 4.2.1 as in 4.2.0 it behaves as expected. I have python 3.10 and 3.12 locally with wxPython 4.2.0 and 4.2.1 respectively. The latter exhibits the bad behavior, but the former does not. |
This also reproduces for me for Python 3.12 and wxPython 4.2.1. FYI, C++ wxWidgets works correctly, even without the MacOS bundle (unless it's run from within VSCode, but that seems to be the editor's fault). Tested with wxWidgets 3.2.2 and 3.2.0. |
Can you test with the latest wxWidgets please? |
@kk7ds I was referring to C++ wxWidgets when I mentioned VSCode. I remember I had this problem before with my C++ wxWidgets applications when running from VSCode, but I checked just now, and it's no longer reproducible. The app's window shows up correctly in front, VSCode or not. For wxPython, you're right. The window shows up in the background. I'm just saying that's not the case for the original wxWidgets library. @swt2c Latest wxWidgets master branch works correctly (C++). |
Sorry, can you check the latest wxWidgets release or the 3.2 branch? wxPython uses the 3.2 branch. |
I suspect this might be the issue: wxWidgets/wxWidgets#24056 |
@swt2c as I said, I've checked 3.2.0 and it works correctly. If you have cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(myapp LANGUAGES CXX)
include(FetchContent)
set(wxBUILD_SHARED OFF)
message(STATUS "Fetching wxWidgets...")
FetchContent_Declare(
wxWidgets
GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git
GIT_TAG 3.2
)
FetchContent_MakeAvailable(wxWidgets)
set(SRCS myapp.cpp)
add_executable(main ${SRCS})
target_link_libraries(main PRIVATE wxcore) And #include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame("Hello Everyone!", wxDefaultPosition, wxDefaultSize);
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
new wxStaticText(this, wxID_ANY, "Good Morning!"); // no need to delete - the parent will do it automatically
} You can build it and run with: cmake -S. -Bbuild && cmake --build build -j && ./build/main CMake automatically downloads wxWidgets form GitHub from the branch specified by |
As a wxPython and wxWidgets developer, I know how to test it. The problem is that I don't own a Mac. Testing 3.2.0 is unfortunately not helpful because it was released a year and a half ago. |
@swt2c no problem, just give me the exact wxWidgets commit, and I will test it for you. |
If the problem is in wxWidgets, as I believe it is, can you please test: |
@swt2c On my machine, C++ apps compiled with Python apps with Python 3.12 and wxPython 4.2.1 do not work correctly when run from the terminal (the window shows up in the background without getting focus). |
Thanks for testing. I was hoping this was a wxWidgets issue, but your testing seems to indicate it is now. After looking at the changes between 4.2.0 and 4.2.1, I suspect this might be the culprit: |
Operating system: MacOS 13.6 (22G120)
wxPython version & source: pypi wxPython 4.2.1
Python version & source: Python 3.11.6
Description of the problem:
The window opens in the background and does not receive focus. After running the program, I am able to type, and my input goes into the terminal window
thank you for support
Code Example (click to expand)
The text was updated successfully, but these errors were encountered: