.. 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.adv.LayoutAlgorithm:

==========================================================================================================================================
|phoenix_title|  **wx.adv.LayoutAlgorithm**
==========================================================================================================================================

:ref:`wx.adv.LayoutAlgorithm`  implements layout of subwindows in MDI or SDI frames.          

It sends a :ref:`wx.adv.CalculateLayoutEvent`  event to children of the frame, asking them for information about their size. For MDI parent frames, the algorithm allocates the remaining space to the MDI client window (which contains the MDI child frames). 

For SDI (normal) frames, a 'main' window is specified as taking up the remaining space. 

Because the event system is used, this technique can be applied to any windows, which are not necessarily 'aware' of the layout classes (no virtual functions in :ref:`wx.Window`  refer to :ref:`wx.adv.LayoutAlgorithm`  or its events). However, you may wish to use :ref:`wx.adv.SashLayoutWindow`  for your subwindows since this class provides handlers for the required events, and accessors to specify the desired size of the window. The sash behaviour in the base class can be used, optionally, to make the windows user-resizable. 

:ref:`wx.adv.LayoutAlgorithm`  is typically used in ``IDE`` (integrated development environment) applications, where there are several resizable windows in addition to the MDI client window, or other primary editing window. Resizable windows might include toolbars, a project window, and a window for displaying error and warning messages. 

When a window receives an OnCalculateLayout event, it should call SetRect in the given event object, to be the old supplied rectangle minus whatever space the window takes up. It should also set its own size accordingly. :meth:`wx.adv.SashLayoutWindow.OnCalculateLayout`   generates an OnQueryLayoutInfo event which it sends to itself to determine the orientation, alignment and size of the window, which it gets from internal member variables set by the application. 

The algorithm works by starting off with a rectangle equal to the whole frame client area. It iterates through the frame children, generating `LayoutAlgorithm.OnCalculateLayout` events which subtract the window size and return the remaining rectangle for the next window to process. It is assumed (by :meth:`wx.adv.SashLayoutWindow.OnCalculateLayout` ) that a window stretches the full dimension of the frame client, according to the orientation it specifies. For example, a horizontal window will stretch the full width of the remaining portion of the frame client area. In the other orientation, the window will be fixed to whatever size was specified by `LayoutAlgorithm.OnQueryLayoutInfo.` An alignment setting will make the window 'stick' to the left, top, right or bottom of the remaining client area. This scheme implies that order of window creation is important. Say you wish to have an extra toolbar at the top of the frame, a project window to the left of the MDI client window, and an output window above the status bar. You should therefore create the windows in this order: toolbar, output window, project window. This ensures that the toolbar and output window take up space at the top and bottom, and then the remaining height in-between is used for the project window. 

:ref:`wx.adv.LayoutAlgorithm`  is quite independent of the way in which `LayoutAlgorithm.OnCalculateLayout` chooses to interpret a window's size and alignment. Therefore you could implement a different window class with a new `LayoutAlgorithm.OnCalculateLayout` event handler, that has a more sophisticated way of laying out the windows. It might allow specification of whether stretching occurs in the specified orientation, for example, rather than always assuming stretching. (This could, and probably should, be added to the existing implementation). 







.. _LayoutAlgorithm-events:

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

Handlers bound for the following event types will receive one of the :ref:`wx.adv.QueryLayoutInfoEvent`:ref:`wx.adv.CalculateLayoutEvent` parameters.


- EVT_QUERY_LAYOUT_INFO: Process a  ``wxEVT_QUERY_LAYOUT_INFO``   event, to get size, orientation and alignment from a window. See  :ref:`wx.adv.QueryLayoutInfoEvent`.  
- EVT_CALCULATE_LAYOUT: Process a  ``wxEVT_CALCULATE_LAYOUT``   event, which asks the window to take a 'bite' out of a rectangle provided by the algorithm. See  :ref:`wx.adv.CalculateLayoutEvent`.  

Note that the algorithm object does not respond to events, but itself generates the previous events in order to calculate window sizes.








         



.. note:: 

   :ref:`wx.adv.LayoutAlgorithm`  has nothing to do with :ref:`wx.LayoutConstraints`. It is an alternative way of specifying layouts for which the normal constraint system is unsuitable.  







.. seealso:: :ref:`wx.adv.SashEvent`, :ref:`wx.adv.SashLayoutWindow`, :ref:`Events and Event Handling <events and event handling>`    







|

|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>LayoutAlgorithm</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.adv.LayoutAlgorithm_inheritance.png" alt="Inheritance diagram of LayoutAlgorithm" 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.Object.html" title="wx.Object" alt="" coords="51,5,132,35"/> <area shape="rect" id="node2" href="wx.adv.LayoutAlgorithm.html" title="wx.adv.LayoutAlgorithm" alt="" coords="5,83,179,112"/> </map> 
   </p>

|


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

================================================================================ ================================================================================
:meth:`~wx.adv.LayoutAlgorithm.__init__`                                         Default constructor.
:meth:`~wx.adv.LayoutAlgorithm.LayoutFrame`                                      Lays out the children of a normal frame.
:meth:`~wx.adv.LayoutAlgorithm.LayoutMDIFrame`                                   Lays out the children of an MDI parent frame.
:meth:`~wx.adv.LayoutAlgorithm.LayoutWindow`                                     Lays out the children of a normal frame or other window.
================================================================================ ================================================================================


|


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


.. class:: wx.adv.LayoutAlgorithm(Object)

   **Possible constructors**::

       LayoutAlgorithm()
       
   
   LayoutAlgorithm implements layout of subwindows in MDI or SDI
   frames.



   .. method:: __init__(self)

      Default constructor.                   





   .. method:: LayoutFrame(self, frame, mainWindow=None)

      Lays out the children of a normal frame.                  

      `mainWindow`  is set to occupy the remaining space. This function simply calls :meth:`LayoutWindow` .                  


      :param `frame`: 
      :type `frame`: wx.Frame
      :param `mainWindow`: 
      :type `mainWindow`: wx.Window




      :rtype: `bool`








   .. method:: LayoutMDIFrame(self, frame, rect=None)

      Lays out the children of an MDI parent frame.                  

      If `rect`  is non-NULL, the given rectangle will be used as a starting point instead of the frame's client area. The MDI client window is set to occupy the remaining space.                  


      :param `frame`: 
      :type `frame`: wx.MDIParentFrame
      :param `rect`: 
      :type `rect`: wx.Rect




      :rtype: `bool`








   .. method:: LayoutWindow(self, parent, mainWindow=None)

      Lays out the children of a normal frame or other window.                  

      `mainWindow`  is set to occupy the remaining space. If this is not specified, then the last window that responds to a calculate layout event in query mode will get the remaining space (that is, a non-query OnCalculateLayout event will not be sent to this window and the window will be set to the remaining size).                  


      :param `parent`: 
      :type `parent`: wx.Window
      :param `mainWindow`: 
      :type `mainWindow`: wx.Window




      :rtype: `bool`







