#!/usr/bin/env python
# -*- coding: utf-8 -*-#

"""
This is the second in a few/many tutorials on how to create AND control the 
initial layout using the wx.lib.agw.aui widget set.

This second tutorial will be a bit more complex and will also show some of the
great things one can do with wx.lib.agw.aui.

As we have enough screen estate we like to show all the panes instead of 
using a notebook.

+---------------------------+---------------------------+
|                           | StaticText + TextCtrl T2  |
|                           | StaticText + TextCtrl     |
|                           | StaticText + TextCtrl     |
|                           |---------------------------+
|                           | StaticText + TextCtrl T3  |
|                           | StaticText + TextCtrl     |
|                           | StaticText + TextCtrl     |
+---------------------------+---------------------------+
| StaticText + TextCtrl T1  | StaticText + TextCtrl T4  |
| StaticText + TextCtrl     | StaticText + TextCtrl     |
| StaticText + TextCtrl     | StaticText + TextCtrl     |
+---------------------------+---------------------------+

So, we have on top left e.g. a ListCtrl (as a placeholder, and to simplify the
code we just use a TextCtrl for this, then we have below the tab 1 from out 
first tutorial and to spice it up a bit we like to see the three other pane
on the right.

The tabs with StaticText should use up enough space to show all the controls
on each pane.

We use the sized_controls for Frame, and panels as they will handle the
setup of sizers for us.
"""

import wx
import wx.lib.agw.aui as aui
import wx.lib.sized_controls as sc

########################################################################
class MainFrame(sc.SizedFrame):
    """The main frame holding all the controls, could also be a dialog"""

    #----------------------------------------------------------------------
    def __init__(self, parent, **kwds):
        """Constructure is pretty simple for this
        
        :param Window `parent`: a :class:`Window` or None
        
        """
        super(MainFrame, self).__init__(parent, wx.ID_ANY, **kwds)
        
        self.SetTitle("wx.lib.agw.aui - Tutorial 1")
        
        self.createControls()

    def createControls(self):
        """Create all the controls"""

        # SizedFrame is setting up a pane to hold controls
        paneContent = self.GetContentsPane()

        # setup the AUI manager
        self._mgr = aui.AuiManager()
        self._mgr.SetManagedWindow(paneContent)

        # the top pane, which holds a TextCtrl as a place holder
        paneTop = sc.SizedPanel(paneContent, wx.ID_ANY)
        # tell it to use up as much space as is available
        paneTop.SetSizerProps(expand=True, proportion=1)
        tc = wx.TextCtrl(paneTop, wx.ID_ANY, 'the place holder TextCtrl')
        tc.SetSizerProps(expand=True, proportion=1)

        # pane tab 1
        paneTab1 = sc.SizedPanel(paneContent, wx.ID_ANY)
        paneTab1.SetSizerType('grid', {'cols': 2})
        st = wx.StaticText(paneTab1, wx.ID_ANY, 'static 1')
        tc = wx.TextCtrl(paneTab1, wx.ID_ANY, 'tc 1')
        st = wx.StaticText(paneTab1, wx.ID_ANY, 'static 2')
        tc = wx.TextCtrl(paneTab1, wx.ID_ANY, 'tc 2')
        st = wx.StaticText(paneTab1, wx.ID_ANY, 'static 3')
        tc = wx.TextCtrl(paneTab1, wx.ID_ANY, 'tc 3')

        # pane tab 2
        paneTab2 = sc.SizedPanel(paneContent, wx.ID_ANY)
        paneTab2.SetSizerType('grid', {'cols': 2})
        st = wx.StaticText(paneTab2, wx.ID_ANY, 'static2 1')
        tc = wx.TextCtrl(paneTab2, wx.ID_ANY, 'tc2 1')
        st = wx.StaticText(paneTab2, wx.ID_ANY, 'static2 2')
        tc = wx.TextCtrl(paneTab2, wx.ID_ANY, 'tc2 2')
        st = wx.StaticText(paneTab2, wx.ID_ANY, 'static2 3')
        tc = wx.TextCtrl(paneTab2, wx.ID_ANY, 'tc2 3')

        # pane tab 3
        paneTab3 = sc.SizedPanel(paneContent, wx.ID_ANY)
        paneTab3.SetSizerType('grid', {'cols': 2})
        st = wx.StaticText(paneTab3, wx.ID_ANY, 'static3 1')
        tc = wx.TextCtrl(paneTab3, wx.ID_ANY, 'tc3 1')
        st = wx.StaticText(paneTab3, wx.ID_ANY, 'static3 2')
        tc = wx.TextCtrl(paneTab3, wx.ID_ANY, 'tc3 2')
        st = wx.StaticText(paneTab3, wx.ID_ANY, 'static3 3')
        tc = wx.TextCtrl(paneTab3, wx.ID_ANY, 'tc3 3')

        # pane tab 4
        paneTab4 = sc.SizedPanel(paneContent, wx.ID_ANY)
        paneTab4.SetSizerType('grid', {'cols': 2})
        st = wx.StaticText(paneTab4, wx.ID_ANY, 'static4 1')
        tc = wx.TextCtrl(paneTab4, wx.ID_ANY, 'tc4 1')
        st = wx.StaticText(paneTab4, wx.ID_ANY, 'static4 2')
        tc = wx.TextCtrl(paneTab4, wx.ID_ANY, 'tc4 2')
        st = wx.StaticText(paneTab4, wx.ID_ANY, 'static4 3')
        tc = wx.TextCtrl(paneTab4, wx.ID_ANY, 'tc4 3')

        self._mgr.AddPane(paneTop, aui.AuiPaneInfo().
                          Name("paneTop").
                          Caption("Top pane").
                          Center().
                          CaptionVisible(False).
                          CloseButton(False).
                          MaximizeButton(True).
                          MinimizeButton(True))
        self._mgr.AddPane(paneTab1, aui.AuiPaneInfo().
                          Name("paneTab1").
                          Caption("Pane tab 1").
                          CaptionVisible(True).
                          Center().
                          CloseButton(False).
                          MaximizeButton(True).
                          MinimizeButton(True))
        self._mgr.AddPane(paneTab2, aui.AuiPaneInfo().
                          Name("paneTab2").
                          Caption("Pane tab 2").
                          CaptionVisible(True).
                          Right().
                          CloseButton(False).
                          MaximizeButton(True).
                          MinimizeButton(True))
        self._mgr.AddPane(paneTab3, aui.AuiPaneInfo().
                          Name("paneTab3").
                          Caption("Pane tab 3").
                          CaptionVisible(True).
                          Right().
                          CloseButton(False).
                          MaximizeButton(True).
                          MinimizeButton(True))
        self._mgr.AddPane(paneTab4, aui.AuiPaneInfo().
                          Name("paneTab4").
                          Caption("Pane tab 4").
                          CaptionVisible(True).
                          Right().
                          CloseButton(False).
                          MaximizeButton(True).
                          MinimizeButton(True))
        self._mgr.Update()


if __name__ == '__main__':
    # we use the WIT for the app, it is a very powerfull tool to help debug
    # layout issues and many other things, run it and try ctrl-alt-i
    # for more detail check out the wiki:
    # http://wiki.wxpython.org/Widget%20Inspection%20Tool
    import wx.lib.mixins.inspection as WIT
    app = WIT.InspectableApp(redirect=False)

    frame = MainFrame(None)
    frame.Show()
    app.MainLoop()
        
        
    
    