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

How to set wx.App() from C++? #1126

pointhi opened this issue Jan 6, 2019 · 3 comments · Fixed by #1352


Copy link

@pointhi pointhi commented Jan 6, 2019

Operating system: Arch Linux
wxPython version & source: '4.0.3 gtk3 (phoenix) wxWidgets 3.0.4'
Python version & source: 3.7.2

Description of the problem:

I did the Python3/Phoenix Port of KiCad some time ago. Unfortunately, it seems like the application is not exiting correctly when the scripting console (based on wx) was used:

I assume it is due to a hack needed to get phoenix working which required me to to create a new wx.App() inside python, and not to reuse the main one of the c++ application itself. Removing it cause the error: assert app is not None, 'No wx.App created yet' because ofwx.GetApp() returns None. How do I correctly instantiate a wx.Phoenix frame using the c++ app?

My patchset to get Phoenix working can be found here:


Notable is the change to instantiate a new wx.App():


As well as the change to actually create the window. In the old implementation, we used the wxWindow parent of the c++ application, while in the new implementation the window id is used.


It would be nice to know how to correctly create wx Phoenix frames from c++ or what issues I created in this implementation.


This comment has been minimized.

Copy link

@RobinD42 RobinD42 commented Jan 15, 2019

The C++ wxApp created from wxPython is actually wxPyApp located in The implementation of wxGetApp is located at the end of the file, and simply returns a pointer to the wxPyApp that the class maintains as a static member.

Currently that class isn't accessible from outside via the API, not sure it makes sense to do so but I'll give it some thought. Or perhaps just have wx.GetApp fall back to the instance pointer that is set in the base wxAppConsole class would be okay for most use-cases. I'll need to try to remember why I added keeping track of a separate pointer...


This comment has been minimized.

Copy link

@qu1ck qu1ck commented May 13, 2019

Gentle ping on this issue.
Lack of access to valid wx.App in python forces us to create another one to use features like wx.CallAfter() and that prevents host process from exiting cleanly.


This comment has been minimized.

Copy link

@Andrei-Pozolotin Andrei-Pozolotin commented May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.