.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.PyApp:

==========================================================================================================================================
|phoenix_title|  **wx.PyApp**
==========================================================================================================================================

The :ref:`wx.App`  class represents the application itself when  ``USE_GUI=1`` .           

In addition to the features provided by :ref:`wx.AppConsole`  it keeps track of the `top window`  (see :meth:`~wx.PyApp.SetTopWindow`) and adds support for video modes (see SetVideoMode()). 

In general, application-wide settings for GUI-only apps are accessible from :ref:`wx.App`  (or from :ref:`wx.SystemSettings`  or :ref:`wx.SystemOptions`  classes). 





.. _PyApp-events:

|events| Events Emitted by this Class
=====================================

Event macros for events emitted by this class: 

  

- EVT_QUERY_END_SESSION: Process a query end session event, supplying the member function. See :ref:`wx.CloseEvent`.  
- EVT_END_SESSION: Process an end session event, supplying the member function. See :ref:`wx.CloseEvent`.  
- EVT_ACTIVATE_APP: Process a  ``wxEVT_ACTIVATE_APP``   event. See  :ref:`wx.ActivateEvent`.  
- EVT_HIBERNATE: Process a hibernate event. See :ref:`wx.ActivateEvent`.  
- EVT_DIALUP_CONNECTED: A connection with the network was established. See :ref:`DialUpEvent`.  
- EVT_DIALUP_DISCONNECTED: The connection with the network was lost. See :ref:`DialUpEvent`.  
- EVT_IDLE: Process a  ``wxEVT_IDLE``   event. See  :ref:`wx.IdleEvent`.  








         



.. seealso:: :ref:`App Overview <app overview>`, :ref:`wx.AppTraits`, :ref:`wx.EventLoopBase`, :ref:`wx.SystemSettings`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>PyApp</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.App_inheritance.png" alt="Inheritance diagram of PyApp" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.EventFilter.html" title="wx.EventFilter" alt="" coords="5,83,112,112"/> <area shape="rect" id="node3" href="wx.AppConsole.html" title="wx.AppConsole" alt="" coords="66,160,184,189"/> <area shape="rect" id="node2" href="wx.App.html" title="wx.App" alt="" coords="89,237,161,267"/> <area shape="rect" id="node4" href="wx.Object.html" title="wx.Object" alt="" coords="93,5,175,35"/> <area shape="rect" id="node5" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="137,83,248,112"/> <area shape="rect" id="node6" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="200,5,301,35"/> </map> 
   </p>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.PyApp.__init__`                                                       Constructor.
:meth:`~wx.PyApp.GetAssertMode`                                                  Returns the current mode for how the application responds to  asserts.
:meth:`~wx.PyApp.GetComCtl32Version`                                             Returns 400, 470, 471, etc. for comctl32.dll 4.00, 4.70, 4.71 or 0 if
:meth:`~wx.PyApp.GetDisplayMode`                                                 Get display mode that is used use.
:meth:`~wx.PyApp.GetExitOnFrameDelete`                                           Returns ``True`` if the application will exit when the top-level frame is deleted.
:meth:`~wx.PyApp.GetLayoutDirection`                                             Return the layout direction for the current locale or  ``Layout_Default``   if it's unknown.
:meth:`~wx.PyApp.GetShell32Version`                                              Returns 400, 470, 471, etc. for shell32.dll 4.00, 4.70, 4.71 or 0 if
:meth:`~wx.PyApp.GetTopWindow`                                                   Returns a pointer to the top window.
:meth:`~wx.PyApp.GetUseBestVisual`                                               Returns ``True`` if the application will use the best visual on systems that support different visuals, ``False`` otherwise.
:meth:`~wx.PyApp.IsActive`                                                       Returns ``True`` if the application is active, i.e. if one of its windows is currently in the foreground.
:meth:`~wx.PyApp.IsDisplayAvailable`                                             Returns True if the application is able to connect to the system's
:meth:`~wx.PyApp.MacHideApp`                                                     Hide all application windows just as the user can do with the
:meth:`~wx.PyApp.MacNewFile`                                                     Called in response of an "open-application" Apple event.
:meth:`~wx.PyApp.MacOpenFile`                                                    Called in response of an "open-document" Apple event.
:meth:`~wx.PyApp.MacOpenFiles`                                                   Called in response of an openFiles message with Cocoa, or an "open-document" Apple event with Carbon.
:meth:`~wx.PyApp.MacOpenURL`                                                     Called in response of a "get-url" Apple event.
:meth:`~wx.PyApp.MacPrintFile`                                                   Called in response of a "print-document" Apple event.
:meth:`~wx.PyApp.MacReopenApp`                                                   Called in response of a "reopen-application" Apple event.
:meth:`~wx.PyApp.OSXIsGUIApplication`                                            May be overridden to indicate that the application is not a foreground GUI application under OS X.
:meth:`~wx.PyApp.SafeYield`                                                      This function is similar to :ref:`wx.Yield`, except that it disables the user input to all program windows before calling :meth:`wx.AppConsole.Yield`   and re-enables it again afterwards.
:meth:`~wx.PyApp.SafeYieldFor`                                                   Works like :ref:`wx.SafeYield`  with `onlyIfNeeded`  == ``True`` except that it allows the caller to specify a mask of events to be processed.
:meth:`~wx.PyApp.SetAssertMode`                                                  Set the mode indicating how the application responds to  assertion
:meth:`~wx.PyApp.SetDisplayMode`                                                 Set display mode to use.
:meth:`~wx.PyApp.SetExitOnFrameDelete`                                           Allows the programmer to specify whether the application will exit when the top-level frame is deleted.
:meth:`~wx.PyApp.SetNativeTheme`                                                 Allows runtime switching of the UI environment theme.
:meth:`~wx.PyApp.SetTopWindow`                                                   Sets the 'top' window.
:meth:`~wx.PyApp.SetUseBestVisual`                                               Allows the programmer to specify whether the application will use the best visual on systems that support several visual on the same display.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.PyApp.AssertMode`                                                     See :meth:`~wx.PyApp.GetAssertMode` and :meth:`~wx.PyApp.SetAssertMode`
:attr:`~wx.PyApp.DisplayMode`                                                    See :meth:`~wx.PyApp.GetDisplayMode` and :meth:`~wx.PyApp.SetDisplayMode`
:attr:`~wx.PyApp.ExitOnFrameDelete`                                              See :meth:`~wx.PyApp.GetExitOnFrameDelete` and :meth:`~wx.PyApp.SetExitOnFrameDelete`
:attr:`~wx.PyApp.LayoutDirection`                                                See :meth:`~wx.PyApp.GetLayoutDirection`
:attr:`~wx.PyApp.TopWindow`                                                      See :meth:`~wx.PyApp.GetTopWindow` and :meth:`~wx.PyApp.SetTopWindow`
:attr:`~wx.PyApp.UseBestVisual`                                                  See :meth:`~wx.PyApp.GetUseBestVisual` and :meth:`~wx.PyApp.SetUseBestVisual`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.PyApp(AppConsole)

   **Possible constructors**::

       PyApp()
       
   
   The App class represents the application itself when USE_GUI=1.



   .. method:: __init__(self)

      Constructor.                  

      Called implicitly with a definition of a :ref:`wx.App`  object.                   





   .. method:: GetAssertMode(self)

      Returns the current mode for how the application responds to  asserts. 

      :rtype: :ref:`wx.AppAssertMode`








   .. staticmethod:: GetComCtl32Version()

                      Returns 400, 470, 471, etc. for comctl32.dll 4.00, 4.70, 4.71 or 0 if
                      it wasn't found at all.  Raises an exception on non-Windows platforms. 

      :rtype: `int`








   .. method:: GetDisplayMode(self)

      Get display mode that is used use.                  

      This is only used in framebuffer wxWidgets ports such as wxDFB.                  

      :rtype: :ref:`wx.VideoMode`








   .. method:: GetExitOnFrameDelete(self)

      Returns ``True`` if the application will exit when the top-level frame is deleted.                  

                

      :rtype: `bool`







      .. seealso:: :meth:`SetExitOnFrameDelete`     








   .. method:: GetLayoutDirection(self)

      Return the layout direction for the current locale or  ``Layout_Default``   if it's unknown.                   

      :rtype: :ref:`wx.LayoutDirection`








   .. staticmethod:: GetShell32Version()

                      Returns 400, 470, 471, etc. for shell32.dll 4.00, 4.70, 4.71 or 0 if
                      it wasn't found at all.  Raises an exception on non-Windows platforms. 

      :rtype: `int`








   .. method:: GetTopWindow(self)

      Returns a pointer to the top window.                  

                

      :rtype: :ref:`wx.Window`







      .. note:: 

         If the top window hasn't been set using :meth:`SetTopWindow` , this function will find the first top-level window (frame or dialog or instance of :ref:`wx.TopLevelWindow`) from the internal top level window list and return that.  







      .. seealso:: :meth:`SetTopWindow`     








   .. method:: GetUseBestVisual(self)

      Returns ``True`` if the application will use the best visual on systems that support different visuals, ``False`` otherwise.                  

                

      :rtype: `bool`







      .. seealso:: :meth:`SetUseBestVisual`     








   .. method:: IsActive(self)

      Returns ``True`` if the application is active, i.e. if one of its windows is currently in the foreground.                  

      If this function returns ``False`` and you need to attract users attention to the application, you may use :meth:`wx.TopLevelWindow.RequestUserAttention`   to do it.                  

      :rtype: `bool`








   .. staticmethod:: IsDisplayAvailable()

                      Returns True if the application is able to connect to the system's
                      display, or whatever the equivallent is for the platform. 

      :rtype: `bool`








   .. method:: MacHideApp(self)

                              Hide all application windows just as the user can do with the
                              system Hide command.  Mac only.  





   .. method:: MacNewFile(self)

      Called in response of an "open-application" Apple event.                  

      Override this to create a new document in your app. 





      .. availability:: Only available for OSX.  








   .. method:: MacOpenFile(self, fileName)

      Called in response of an "open-document" Apple event.                  






      :param `fileName`: 
      :type `fileName`: string






      .. wxdeprecated:: 
         This function is kept mostly for backwards compatibility. Please override :meth:`wx.App.MacOpenFiles`   method instead in any new code.   







      .. availability:: Only available for OSX.  








   .. method:: MacOpenFiles(self, fileNames)

      Called in response of an openFiles message with Cocoa, or an "open-document" Apple event with Carbon.                  

      You need to override this method in order to open one or more document files after the user double clicked on it or if the files and/or folders were dropped on either the application in the dock or the application icon in Finder. 

      By default this method calls MacOpenFile for each file/folder. 



                


      :param `fileNames`: 
      :type `fileNames`: list of strings






      .. versionadded:: 2.9.3 
     







      .. availability:: Only available for OSX.  








   .. method:: MacOpenURL(self, url)

      Called in response of a "get-url" Apple event.                  




      :param `url`: 
      :type `url`: string






      .. availability:: Only available for OSX.  








   .. method:: MacPrintFile(self, fileName)

      Called in response of a "print-document" Apple event.                  




      :param `fileName`: 
      :type `fileName`: string






      .. availability:: Only available for OSX.  








   .. method:: MacReopenApp(self)

      Called in response of a "reopen-application" Apple event.                  





      .. availability:: Only available for OSX.  








   .. method:: OSXIsGUIApplication(self)

      May be overridden to indicate that the application is not a foreground GUI application under OS X.                  

      This method is called during the application startup and returns ``True`` by default. In this case, wxWidgets ensures that the application is ran as a foreground, GUI application so that the user can interact with it normally, even if it is not bundled. If this is undesired, i.e. if the application doesn't need to be brought to the foreground, this method can be overridden to return ``False``. 

      Notice that overriding it doesn't make any difference for the bundled applications which are always foreground unless  ``LSBackgroundOnly``   key is specified in the   ``Info.plist``   file. 



                

      :rtype: `bool`







      .. versionadded:: 3.0.1 
     







      .. availability:: Only available for OSX.  








   .. method:: SafeYield(self, win, onlyIfNeeded)

      This function is similar to :ref:`wx.Yield`, except that it disables the user input to all program windows before calling :meth:`wx.AppConsole.Yield`   and re-enables it again afterwards.                  

      If `win`  is not ``None``, this window will remain enabled, allowing the implementation of some limited user interaction. Returns the result of the call to :meth:`wx.AppConsole.Yield` . 

                


      :param `win`: 
      :type `win`: wx.Window
      :param `onlyIfNeeded`: 
      :type `onlyIfNeeded`: bool




      :rtype: `bool`







      .. seealso:: :ref:`wx.SafeYield`    








   .. method:: SafeYieldFor(self, win, eventsToProcess)

      Works like :ref:`wx.SafeYield`  with `onlyIfNeeded`  == ``True`` except that it allows the caller to specify a mask of events to be processed.                  

      See `AppConsole.YieldFor` for more info.                  


      :param `win`: 
      :type `win`: wx.Window
      :param `eventsToProcess`: 
      :type `eventsToProcess`: long




      :rtype: `bool`








   .. method:: SetAssertMode(self, AppAssertMode)

                      Set the mode indicating how the application responds to  assertion
                      statements. Valid settings are a combination of these flags:

                              - wx.``wx.APP_ASSERT_SUPPRESS``
                              - wx.``wx.APP_ASSERT_EXCEPTION``
                              - wx.``wx.APP_ASSERT_DIALOG``
                              - wx.``wx.APP_ASSERT_LOG``

                      The default behavior is to raise a wx.wxAssertionError exception.
                 


      :param `wxAppAssertMode`: 
      :type `wxAppAssertMode`: wx.AppAssertMode







   .. method:: SetDisplayMode(self, info)

      Set display mode to use.                  

      This is only used in framebuffer wxWidgets ports such as wxDFB.                  


      :param `info`: 
      :type `info`: wx.VideoMode




      :rtype: `bool`








   .. method:: SetExitOnFrameDelete(self, flag)

      Allows the programmer to specify whether the application will exit when the top-level frame is deleted.                  




      :param `flag`: If ``True`` (the default), the application will exit when the top-level frame is deleted. If ``False``, the application will continue to run.  
      :type `flag`: bool




                  



      .. seealso:: :meth:`GetExitOnFrameDelete` , :ref:`Application Shutdown <application shutdown>`    








   .. method:: SetNativeTheme(self, theme)

      Allows runtime switching of the UI environment theme.                  

      Currently implemented for GTK2-only. Return ``True`` if theme was successfully changed. 




      :param `theme`: The name of the new theme or an absolute path to a gtkrc-theme-file   
      :type `theme`: string






      :rtype: `bool`



                  





   .. method:: SetTopWindow(self, window)

      Sets the 'top' window.                  

      You can call this from within :meth:`OnInit`   to let wxWidgets know which is the main window. You don't have to set the top window; it is only a convenience so that (for example) certain dialogs without parents can use a specific window as the top window. 

      If no top window is specified by the application, wxWidgets just uses the first frame or dialog (or better, any :ref:`wx.TopLevelWindow`) in its top-level window list, when it needs to use the top window. If you previously called :meth:`SetTopWindow`   and now you need to restore this automatic behaviour you can call::

           wx.App.SetTopWindow(None)






      :param `window`: The new top window.  
      :type `window`: wx.Window




                  



      .. seealso:: :meth:`GetTopWindow` , :meth:`OnInit`     








   .. method:: SetUseBestVisual(self, flag, forceTrueColour=False)

      Allows the programmer to specify whether the application will use the best visual on systems that support several visual on the same display.                  

      This is typically the case under Solaris and ``IRIX``, where the default visual is only 8-bit whereas certain applications are supposed to run in TrueColour mode. 

      Note that this function has to be called in the constructor of the :ref:`wx.App`  instance and won't have any effect when called later on. This function currently only has effect under GTK. 




      :param `flag`: If ``True``, the app will use the best visual.   
      :type `flag`: bool
      :param `forceTrueColour`: If ``True`` then the application will try to force using a TrueColour visual and abort the app if none is found.   
      :type `forceTrueColour`: bool






                  





   .. attribute:: AssertMode

      See :meth:`~wx.PyApp.GetAssertMode` and :meth:`~wx.PyApp.SetAssertMode`


   .. attribute:: DisplayMode

      See :meth:`~wx.PyApp.GetDisplayMode` and :meth:`~wx.PyApp.SetDisplayMode`


   .. attribute:: ExitOnFrameDelete

      See :meth:`~wx.PyApp.GetExitOnFrameDelete` and :meth:`~wx.PyApp.SetExitOnFrameDelete`


   .. attribute:: LayoutDirection

      See :meth:`~wx.PyApp.GetLayoutDirection`


   .. attribute:: TopWindow

      See :meth:`~wx.PyApp.GetTopWindow` and :meth:`~wx.PyApp.SetTopWindow`


   .. attribute:: UseBestVisual

      See :meth:`~wx.PyApp.GetUseBestVisual` and :meth:`~wx.PyApp.SetUseBestVisual`

