1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Wrappers for the wxAUI classes.
7 // Created: 5-July-2006
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 "The wx.aui moduleis an Advanced User Interface library that aims to
15 implement \"cutting-edge\" interface usability and design features so
16 developers can quickly and easily create beautiful and usable
17 application interfaces.
19 **Vision and Design Principles**
21 wx.aui attempts to encapsulate the following aspects of the user
24 * Frame Management: Frame management provides the means to open,
25 move and hide common controls that are needed to interact with the
26 document, and allow these configurations to be saved into
27 different perspectives and loaded at a later time.
29 * Toolbars: Toolbars are a specialized subset of the frame
30 management system and should behave similarly to other docked
31 components. However, they also require additional functionality,
32 such as \"spring-loaded\" rebar support, \"chevron\" buttons and
33 end-user customizability.
35 * Modeless Controls: Modeless controls expose a tool palette or set
36 of options that float above the application content while allowing
37 it to be accessed. Usually accessed by the toolbar, these controls
38 disappear when an option is selected, but may also be \"torn off\"
39 the toolbar into a floating frame of their own.
41 * Look and Feel: Look and feel encompasses the way controls are
42 drawn, both when shown statically as well as when they are being
43 moved. This aspect of user interface design incorporates \"special
44 effects\" such as transparent window dragging as well as frame
47 **wx.aui adheres to the following principles**
49 - Use native floating frames to obtain a native look and feel for
52 - Use existing wxPython code where possible, such as sizer
53 implementation for frame management;
55 - Use standard wxPython coding conventions.
60 The following example shows a simple implementation that utilizes
61 `wx.aui.FrameManager` to manage three text controls in a frame window::
66 class MyFrame(wx.Frame):
68 def __init__(self, parent, id=-1, title='wx.aui Test',
69 size=(800, 600), style=wx.DEFAULT_FRAME_STYLE):
70 wx.Frame.__init__(self, parent, id, title, pos, size, style)
72 self._mgr = wx.aui.AuiManager(self)
74 # create several text controls
75 text1 = wx.TextCtrl(self, -1, 'Pane 1 - sample text',
76 wx.DefaultPosition, wx.Size(200,150),
77 wx.NO_BORDER | wx.TE_MULTILINE)
79 text2 = wx.TextCtrl(self, -1, 'Pane 2 - sample text',
80 wx.DefaultPosition, wx.Size(200,150),
81 wx.NO_BORDER | wx.TE_MULTILINE)
83 text3 = wx.TextCtrl(self, -1, 'Main content window',
84 wx.DefaultPosition, wx.Size(200,150),
85 wx.NO_BORDER | wx.TE_MULTILINE)
87 # add the panes to the manager
88 self._mgr.AddPane(text1, wx.LEFT, 'Pane Number One')
89 self._mgr.AddPane(text2, wx.BOTTOM, 'Pane Number Two')
90 self._mgr.AddPane(text3, wx.CENTER)
92 # tell the manager to 'commit' all the changes just made
95 self.Bind(wx.EVT_CLOSE, self.OnClose)
98 def OnClose(self, event):
99 # deinitialize the frame manager
106 frame = MyFrame(None)
114 %module(package="wx", docstring=DOCSTRING) aui
117 #include "wx/wxPython/wxPython.h"
118 #include "wx/wxPython/pyclasses.h"
119 #include <wx/aui/aui.h>
122 //---------------------------------------------------------------------------
127 %pythoncode { wx = _core }
128 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
131 %include _aui_docstrings.i
133 //---------------------------------------------------------------------------
137 #define WXDLLIMPEXP_AUI
139 #define wxDEPRECATED(decl)
142 // We'll skip making wrappers for these, they have overloads that take a
144 %ignore wxAuiPaneInfo::MaxSize(int x, int y);
145 %ignore wxAuiPaneInfo::MinSize(int x, int y);
146 %ignore wxAuiPaneInfo::BestSize(int x, int y);
147 %ignore wxAuiPaneInfo::FloatingPosition(int x, int y);
148 %ignore wxAuiPaneInfo::FloatingSize(int x, int y);
150 // But for these we will do the overloading (see %pythoncode below) so let's
151 // rename the C++ versions
152 %rename(_GetPaneByWidget) wxAuiManager::GetPane(wxWindow* window);
153 %rename(_GetPaneByName) wxAuiManager::GetPane(const wxString& name);
155 %rename(_AddPane1) wxAuiManager::AddPane(wxWindow* window, const wxAuiPaneInfo& pane_info);
156 %rename(_AddPane2) wxAuiManager::AddPane(wxWindow* window, int direction = wxLEFT,
157 const wxString& caption = wxEmptyString);
159 %rename(AddPaneAtPos) wxAuiManager::AddPane(wxWindow* window,
160 const wxPaneInfo& pane_info,
161 const wxPoint& drop_pos);
163 // A typemap for the return value of wxFrameManager::GetAllPanes
164 %typemap(out) wxAuiPaneInfoArray& {
165 $result = PyList_New(0);
166 for (size_t i=0; i < $1->GetCount(); i++) {
167 PyObject* pane_obj = SWIG_NewPointerObj((void*)(&$1->Item(i)), SWIGTYPE_p_wxAuiPaneInfo, 0);
168 PyList_Append($result, pane_obj);
173 %nokwargs wxAuiTabContainer::SetActivePage;
175 %pythonAppend wxAuiTabCtrl::wxAuiTabCtrl "self._setOORInfo(self)";
177 %pythonAppend wxAuiNotebook::wxAuiNotebook "self._setOORInfo(self)";
178 %pythonAppend wxAuiNotebook::wxAuiNotebook() "self._setOORInfo(self)";
179 %ignore wxAuiiNotebook::~wxAuiNotebook;
180 %rename(PreAuiNotebook) wxAuiNotebook::wxAuiNotebook();
184 %ignore wxAuiDefaultTabArt::SetWindow; // Link error...
186 // ignore this overload
187 %ignore wxAuiTabContainer::GetPage(size_t idx) const;
190 //---------------------------------------------------------------------------
191 // Get all our defs from the REAL header files.
192 %include framemanager.h
197 //---------------------------------------------------------------------------
198 // Methods to inject into the FrameManager class that will sort out calls to
199 // the overloaded versions of GetPane and AddPane
201 %extend wxAuiManager {
203 def GetPane(self, item):
205 GetPane(self, window_or_info item) -> PaneInfo
207 GetPane is used to search for a `PaneInfo` object either by
208 widget reference or by pane name, which acts as a unique id
209 for a window pane. The returned `PaneInfo` object may then be
210 modified to change a pane's look, state or position. After one
211 or more modifications to the `PaneInfo`, `FrameManager.Update`
212 should be called to realize the changes to the user interface.
214 If the lookup failed (meaning the pane could not be found in
215 the manager) GetPane returns an empty `PaneInfo`, a condition
216 which can be checked by calling `PaneInfo.IsOk`.
218 if isinstance(item, wx.Window):
219 return self._GetPaneByWidget(item)
221 return self._GetPaneByName(item)
223 def AddPane(self, window, info=None, caption=None):
225 AddPane(self, window, info=None, caption=None) -> bool
227 AddPane tells the frame manager to start managing a child
228 window. There are two versions of this function. The first
229 verison accepts a `PaneInfo` object for the ``info`` parameter
230 and allows the full spectrum of pane parameter
231 possibilities. (Say that 3 times fast!)
233 The second version is used for simpler user interfaces which
234 do not require as much configuration. In this case the
235 ``info`` parameter specifies the direction property of the
236 pane info, and defaults to ``wx.LEFT``. The pane caption may
237 also be specified as an extra parameter in this form.
239 if type(info) == AuiPaneInfo:
240 return self._AddPane1(window, info)
247 return self._AddPane2(window, info, caption)
250 // For backwards compatibility
252 SetFrame = wx._deprecated(SetManagedWindow,
253 "SetFrame is deprecated, use `SetManagedWindow` instead.")
254 GetFrame = wx._deprecated(GetManagedWindow,
255 "GetFrame is deprecated, use `GetManagedWindow` instead.")
259 %extend wxAuiDockInfo {
263 %extend wxAuiDockUIPart {
264 ~wxAuiDockUIPart() {}
267 %extend wxAuiPaneButton {
268 ~wxAuiPaneButton() {}
271 //---------------------------------------------------------------------------
274 // A wxDocArt class that knows how to forward virtuals to Python methods
275 class wxPyAuiDockArt : public wxAuiDefaultDockArt
277 wxPyAuiDockArt() : wxAuiDefaultDockArt() {}
279 DEC_PYCALLBACK_INT_INT(GetMetric);
280 DEC_PYCALLBACK_VOID_INTINT(SetMetric);
281 DEC_PYCALLBACK__INTFONT(SetFont);
282 DEC_PYCALLBACK_FONT_INT(GetFont);
283 DEC_PYCALLBACK_COLOUR_INT(GetColour);
284 DEC_PYCALLBACK__INTCOLOUR(SetColour);
286 virtual void DrawSash(wxDC& dc,
292 wxPyBlock_t blocked = wxPyBeginBlockThreads();
293 if ((found = wxPyCBH_findCallback(m_myInst, "DrawSash"))) {
294 PyObject* odc = wxPyMake_wxObject(&dc, false);
295 PyObject* owin = wxPyMake_wxObject(window, false);
296 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
297 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOiO)",
298 odc, owin, orientation, orect));
303 wxPyEndBlockThreads(blocked);
305 wxAuiDefaultDockArt::DrawSash(dc, window, orientation, rect);
308 virtual void DrawBackground(wxDC& dc,
314 wxPyBlock_t blocked = wxPyBeginBlockThreads();
315 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBackground"))) {
316 PyObject* odc = wxPyMake_wxObject(&dc, false);
317 PyObject* owin = wxPyMake_wxObject(window, false);
318 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
319 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOiO)",
320 odc, owin, orientation, orect));
325 wxPyEndBlockThreads(blocked);
327 wxAuiDefaultDockArt::DrawBackground(dc, window, orientation, rect);
330 virtual void DrawCaption(wxDC& dc,
332 const wxString& text,
337 wxPyBlock_t blocked = wxPyBeginBlockThreads();
338 if ((found = wxPyCBH_findCallback(m_myInst, "DrawCaption"))) {
339 PyObject* odc = wxPyMake_wxObject(&dc, false);
340 PyObject* owin = wxPyMake_wxObject(window, false);
341 PyObject* otext = wx2PyString(text);
342 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
343 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxAuiPaneInfo"), 0);
344 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOO)",
345 odc, owin, otext, orect, opane));
352 wxPyEndBlockThreads(blocked);
354 wxAuiDefaultDockArt::DrawCaption(dc, window, text, rect, pane);
357 virtual void DrawGripper(wxDC& dc,
363 wxPyBlock_t blocked = wxPyBeginBlockThreads();
364 if ((found = wxPyCBH_findCallback(m_myInst, "DrawGripper"))) {
365 PyObject* odc = wxPyMake_wxObject(&dc, false);
366 PyObject* owin = wxPyMake_wxObject(window, false);
367 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
368 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxAuiPaneInfo"), 0);
369 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOO)", odc, owin, orect, opane));
374 wxPyEndBlockThreads(blocked);
376 wxAuiDefaultDockArt::DrawGripper(dc, window, rect, pane);
379 virtual void DrawBorder(wxDC& dc,
385 wxPyBlock_t blocked = wxPyBeginBlockThreads();
386 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBorder"))) {
387 PyObject* odc = wxPyMake_wxObject(&dc, false);
388 PyObject* owin = wxPyMake_wxObject(window, false);
389 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
390 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxAuiPaneInfo"), 0);
391 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, orect, opane));
397 wxPyEndBlockThreads(blocked);
399 wxAuiDefaultDockArt::DrawBorder(dc, window, rect, pane);
402 virtual void DrawPaneButton(wxDC& dc,
410 wxPyBlock_t blocked = wxPyBeginBlockThreads();
411 if ((found = wxPyCBH_findCallback(m_myInst, "DrawPaneButton"))) {
412 PyObject* odc = wxPyMake_wxObject(&dc, false);
413 PyObject* owin = wxPyMake_wxObject(window, false);
414 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
415 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxAuiPaneInfo"), 0);
416 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOiIOO)",
417 odc, owin, button, button_state,
424 wxPyEndBlockThreads(blocked);
426 wxAuiDefaultDockArt::DrawPaneButton(dc, window, button, button_state, rect, pane);
433 IMP_PYCALLBACK_INT_INT(wxPyAuiDockArt, wxAuiDefaultDockArt, GetMetric);
434 IMP_PYCALLBACK_VOID_INTINT(wxPyAuiDockArt, wxAuiDefaultDockArt, SetMetric);
435 IMP_PYCALLBACK__INTFONT(wxPyAuiDockArt, wxAuiDefaultDockArt, SetFont);
436 IMP_PYCALLBACK_FONT_INT(wxPyAuiDockArt, wxAuiDefaultDockArt, GetFont);
437 IMP_PYCALLBACK_COLOUR_INT(wxPyAuiDockArt, wxAuiDefaultDockArt, GetColour);
438 IMP_PYCALLBACK__INTCOLOUR(wxPyAuiDockArt, wxAuiDefaultDockArt, SetColour);
443 DocStr(wxPyAuiDockArt,
444 "This version of the `AuiDockArt` class has been instrumented to be
445 subclassable in Python and to reflect all calls to the C++ base class
446 methods to the Python methods implemented in the derived class.", "");
448 class wxPyAuiDockArt : public wxAuiDefaultDockArt
450 %pythonAppend wxPyAuiDockArt setCallbackInfo(PyAuiDockArt)
456 //---------------------------------------------------------------------------
458 %extend wxAuiNotebook {
459 %property(PageCount, GetPageCount, doc="See `GetPageCount`");
460 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
464 %extend wxAuiNotebookEvent {
465 %property(OldSelection, GetOldSelection, SetOldSelection, doc="See `GetOldSelection` and `SetOldSelection`");
466 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
470 %extend wxAuiTabContainer {
471 %property(ActivePage, GetActivePage, SetActivePage, doc="See `GetActivePage` and `SetActivePage`");
472 %property(PageCount, GetPageCount, doc="See `GetPageCount`");
473 %property(Pages, GetPages, doc="See `GetPages`");
477 %extend wxAuiManager {
478 %property(AllPanes, GetAllPanes, doc="See `GetAllPanes`");
479 %property(ArtProvider, GetArtProvider, SetArtProvider, doc="See `GetArtProvider` and `SetArtProvider`");
480 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
481 %property(ManagedWindow, GetManagedWindow, SetManagedWindow, doc="See `GetManagedWindow` and `SetManagedWindow`");
485 %extend wxAuiManagerEvent {
486 %property(Button, GetButton, SetButton, doc="See `GetButton` and `SetButton`");
487 %property(DC, GetDC, SetDC, doc="See `GetDC` and `SetDC`");
488 %property(Pane, GetPane, SetPane, doc="See `GetPane` and `SetPane`");
492 //---------------------------------------------------------------------------
495 // A wxTabArt class that knows how to forward virtuals to Python methods
496 class wxPyAuiTabArt : public wxAuiDefaultTabArt
498 wxPyAuiTabArt() : wxAuiDefaultTabArt() {}
501 virtual void DrawBackground( wxDC& dc,
506 wxPyBlock_t blocked = wxPyBeginBlockThreads();
507 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBackground"))) {
508 PyObject* odc = wxPyMake_wxObject(&dc, false);
509 PyObject* ownd = wxPyMake_wxObject(wnd, false);
510 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
511 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, ownd, orect));
516 wxPyEndBlockThreads(blocked);
518 wxAuiDefaultTabArt::DrawBackground(dc, wnd, rect);
521 virtual void DrawTab( wxDC& dc,
523 const wxAuiNotebookPage& pane,
524 const wxRect& in_rect,
525 int close_button_state,
526 wxRect* out_tab_rect,
527 wxRect* out_button_rect,
531 const char* errmsg = "DrawTab should return a sequence containing (tab_rect, button_rect, x_extent)";
532 wxPyBlock_t blocked = wxPyBeginBlockThreads();
533 if ((found = wxPyCBH_findCallback(m_myInst, "DrawTab"))) {
534 PyObject* odc = wxPyMake_wxObject(&dc, false);
535 PyObject* ownd = wxPyMake_wxObject(wnd, false);
536 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxAuiNotebookPage"), 0);
537 PyObject* orect = wxPyConstructObject((void*)&in_rect, wxT("wxRect"), 0);
539 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue(
541 odc, ownd, orect, opane,
542 close_button_state));
544 if (PySequence_Check(ro) && PyObject_Length(ro) == 3) {
545 PyObject* o1 = PySequence_GetItem(ro, 0);
546 PyObject* o2 = PySequence_GetItem(ro, 1);
547 PyObject* o3 = PySequence_GetItem(ro, 2);
548 if (!wxRect_helper(o1, &out_tab_rect))
549 PyErr_SetString(PyExc_TypeError, errmsg);
550 else if (!wxRect_helper(o2, &out_button_rect))
551 PyErr_SetString(PyExc_TypeError, errmsg);
552 else if (!PyInt_Check(o3))
553 PyErr_SetString(PyExc_TypeError, errmsg);
555 *x_extent = PyInt_AsLong(o3);
562 PyErr_SetString(PyExc_TypeError, errmsg);
572 wxPyEndBlockThreads(blocked);
574 wxAuiDefaultTabArt::DrawTab(dc, wnd, pane, in_rect, close_button_state, out_tab_rect, out_button_rect, x_extent);
578 virtual void DrawButton( wxDC& dc,
580 const wxRect& in_rect,
587 const char* errmsg = "DrawButton should return a wxRect";
588 wxPyBlock_t blocked = wxPyBeginBlockThreads();
589 if ((found = wxPyCBH_findCallback(m_myInst, "DrawButton"))) {
590 PyObject* odc = wxPyMake_wxObject(&dc, false);
591 PyObject* ownd = wxPyMake_wxObject(wnd, false);
592 PyObject* orect = wxPyConstructObject((void*)&in_rect, wxT("wxRect"), 0);
594 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOiiiO)", odc, ownd, orect,
595 bitmap_id, button_state, orientation));
597 if (!wxRect_helper(ro, &out_rect))
598 PyErr_SetString(PyExc_TypeError, errmsg);
606 wxPyEndBlockThreads(blocked);
608 wxAuiDefaultTabArt::DrawButton(dc, wnd, in_rect, bitmap_id, button_state, orientation, out_rect);
612 virtual wxSize GetTabSize( wxDC& dc,
614 const wxString& caption,
615 const wxBitmap& bitmap,
617 int close_button_state,
621 wxSize rv, *prv = &rv;
622 const char* errmsg = "GetTabSize should return a sequence containing (size, x_extent)";
623 wxPyBlock_t blocked = wxPyBeginBlockThreads();
624 if ((found = wxPyCBH_findCallback(m_myInst, "GetTabSize"))) {
625 PyObject* odc = wxPyMake_wxObject(&dc, false);
626 PyObject* ownd = wxPyMake_wxObject(wnd, false);
627 PyObject* otext = wx2PyString(caption);
628 PyObject* obmp = wxPyMake_wxObject((wxObject*)&bitmap, false);
630 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue(
631 "(OOOOii)", odc, ownd, otext, obmp, (int)active, close_button_state));
633 if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
634 PyObject* o1 = PySequence_GetItem(ro, 0);
635 PyObject* o2 = PySequence_GetItem(ro, 1);
636 if (!wxSize_helper(o1, &prv))
637 PyErr_SetString(PyExc_TypeError, errmsg);
638 else if (!PyInt_Check(o2))
639 PyErr_SetString(PyExc_TypeError, errmsg);
641 *x_extent = PyInt_AsLong(o2);
647 PyErr_SetString(PyExc_TypeError, errmsg);
657 wxPyEndBlockThreads(blocked);
659 rv = wxAuiDefaultTabArt::GetTabSize(dc, wnd, caption, bitmap, active, close_button_state, x_extent);
664 // virtual int ShowDropDown(
666 // const wxAuiNotebookPageArray& items,
669 // virtual int GetIndentSize();
671 // virtual int GetBestTabCtrlSize(wxWindow* wnd,
672 // const wxAuiNotebookPageArray& pages,
673 // const wxSize& required_bmp_size);
674 // virtual wxAuiTabArt* Clone();
675 // virtual void SetFlags(unsigned int flags);
676 // virtual void SetSizingInfo(const wxSize& tab_ctrl_size,
677 // size_t tab_count);
678 // virtual int GetIndentSize();
682 DEC_PYCALLBACK__FONT(SetNormalFont);
683 DEC_PYCALLBACK__FONT(SetSelectedFont);
684 DEC_PYCALLBACK__FONT(SetMeasuringFont);
685 // DEC_PYCALLBACK_INT_WIN(GetBestTabCtrlSize);
691 IMP_PYCALLBACK__FONT(wxPyAuiTabArt, wxAuiDefaultTabArt, SetNormalFont);
692 IMP_PYCALLBACK__FONT(wxPyAuiTabArt, wxAuiDefaultTabArt, SetSelectedFont);
693 IMP_PYCALLBACK__FONT(wxPyAuiTabArt, wxAuiDefaultTabArt, SetMeasuringFont);
694 //IMP_PYCALLBACK_INT_WIN(wxPyAuiTabArt, wxAuiDefaultTabArt, GetBestTabCtrlSize);
698 DocStr(wxPyAuiTabArt,
699 "This version of the `TabArt` class has been instrumented to be
700 subclassable in Python and to reflect all calls to the C++ base class
701 methods to the Python methods implemented in the derived class.", "");
703 class wxPyAuiTabArt : public wxAuiDefaultTabArt
705 %pythonAppend wxPyAuiTabArt setCallbackInfo(PyAuiTabArt)
711 //---------------------------------------------------------------------------
714 #undef WXDLLIMPEXP_AUI
716 //---------------------------------------------------------------------------