83508

wxPython Whole Window Focus Event

Question:

With wxPython, how does one trigger an event whenever the whole window goes into/out of focus?

To elaborate, I'm building a serial terminal GUI and would like to close down the connection whenever the user doesn't have my application selected, and re-open the connection whenever the user brings my app back into the foreground. My application is just a single window derived from wx.Frame.

Answer1:

The correct answer for this case is to use an EVT_ACTIVATE handler bound to the frame. There will be an event whenever the frame is activated (brought into the foreground relative to other windows currently open) or deactivated. You can use the event object's GetActive method to tell which just happened.

Answer2:

as WxPerl programmer i know there is

EVT_SET_FOCUS(

EVT_KILL_FOCUS(

if you initialize this event by listening to the frame as first parameter it should work as in Perl since the API is almost the same

Answer3:

Interesting article at <a href="http://www.blog.pythonlibrary.org/2009/08/27/wxpython-learning-to-focus/" rel="nofollow">http://www.blog.pythonlibrary.org/2009/08/27/wxpython-learning-to-focus/</a>

Gist of it: wx.EVT_KILL_FOCUS works fine, but wx.EVT_SET_FOCUS behaves a little oddly for any panel containing widgets (the child's set-focus prevents the panel's set-focus event from firing as expected?)

Answer4:

In addition to what these fellows are saying, you might also want to try EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW. I think these are fired when you move the mouse into and out of the frame widget, although I don't think the frame has to be in focus for those events to fire.

@ Hugh - thanks for the readership!

Recommend

  • A textual month could not be found ,Trailing data Carbon - laravel
  • Get both dates from each sentence in different variables
  • Sort by date with jmespath
  • How to run an SQL script against a MDF file?
  • Can I just SELECT one column in MYSQL instead of all, to make it faster?
  • Create index on existing table Oracle
  • BufferNotEnough Could not create SSL/TLS secure channel
  • Posting an image using a jQuery AJAX call to an MVC action
  • Copy and paste to another sheet first empty row, pastes over the previous row if first cell is empty
  • Best practice to include console app in NuGet
  • import cv2 doesn't give error on command-Prompt but error on IDLE on Windows 10, Python 3.6.4
  • How to integrate Dialogflow with Django (Python)?
  • How do I add a trailing slash for Django MPTT-based categorization app?
  • unicode characters in html
  • How do I force ASP.NET Ajax to use a script from the FS and not WebResource.axd, or to reduce its HT
  • Using Facebook Graph API with ASP.NET
  • Connect from a client to a sails based server
  • NoSuchMethodError javax.ws.rs.core.Application.getProperties()Ljava/util/Map
  • Create a Terminal-Based Bluetooth Monitor in XCode?
  • how can i close the resultSet, prepareStatement, conn in several methods below to avoid rs close and
  • Getting CKEditor to work with Flask Admin
  • Faces Servlet not parsing .xhtml pages in jsf 2. running on tomcat 7
  • Laravel 5.7: Custom blade template for Maintenance Mode but not 503.blade.php
  • Gitlab: copy project to other git lab repository
  • SqlDatasource select parameters
  • MFMailComposer send email without presenting view
  • How to resolve this in PHPUnit where it is asking me to set KERNEL_DIR in my phpunit.xml?
  • Ajax call on Multiple selection in Select box
  • Separating definition/instantiation of template classes without 'extern'
  • openpyxl - adding new rows in excel file with merged cell existing
  • Tensorflow Dataset API restore Iterator after completing one epoch
  • Typeahead.js does give me suggestions but doesn't select them
  • how to get the location(lat/lng) on google maps v3 from the location(x,y)
  • Send array to next viewcontroller iOs xcode [duplicate]
  • Spring Boot fails to start
  • Bind selectedDates Aggregation for Calendar
  • php “page caching” solution suggestions for CMS Applications
  • Unity3d lost directional light shadows after generate assetBundle (.unity3d file)
  • Call Microservice from another Microservice within Docker
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?