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 **PyAUI 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.FrameManager(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 wxPaneInfo::MaxSize(int x, int y);
145 %ignore wxPaneInfo::MinSize(int x, int y);
146 %ignore wxPaneInfo::BestSize(int x, int y);
147 %ignore wxPaneInfo::FloatingPosition(int x, int y);
148 %ignore wxPaneInfo::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) wxFrameManager::GetPane(wxWindow* window);
153 %rename(_GetPaneByName) wxFrameManager::GetPane(const wxString& name);
155 %rename(_AddPane1) wxFrameManager::AddPane(wxWindow* window, const wxPaneInfo& pane_info);
156 %rename(_AddPane2) wxFrameManager::AddPane(wxWindow* window, int direction = wxLEFT,
157 const wxString& caption = wxEmptyString);
159 %rename(AddPaneAtPos) wxFrameManager::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) wxPaneInfoArray& {
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_wxPaneInfo, 0);
168 PyList_Append($result, pane_obj);
173 %nokwargs wxAuiTabContainer::SetActivePage;
175 %pythonAppend wxAuiTabCtrl::wxAuiTabCtrl "self._setOORInfo(self)";
177 %pythonAppend wxAuiMultiNotebook::wxAuiMultiNotebook "self._setOORInfo(self)";
178 %pythonAppend wxAuiMultiNotebook::wxAuiMultiNotebook() "self._setOORInfo(self)";
179 %ignore wxAuiMultiNotebook::~wxAuiMultiNotebook;
180 %rename(PreAuiMultiNotebook) wxAuiMultiNotebook::wxAuiMultiNotebook();
182 //---------------------------------------------------------------------------
183 // Get all our defs from the REAL header files.
184 %include framemanager.h
189 //---------------------------------------------------------------------------
190 // Methods to inject into the FrameManager class that will sort out calls to
191 // the overloaded versions of GetPane and AddPane
193 %extend wxFrameManager {
195 def GetPane(self, item):
197 GetPane(self, window_or_info item) -> PaneInfo
199 GetPane is used to search for a `PaneInfo` object either by
200 widget reference or by pane name, which acts as a unique id
201 for a window pane. The returned `PaneInfo` object may then be
202 modified to change a pane's look, state or position. After one
203 or more modifications to the `PaneInfo`, `FrameManager.Update`
204 should be called to realize the changes to the user interface.
206 If the lookup failed (meaning the pane could not be found in
207 the manager) GetPane returns an empty `PaneInfo`, a condition
208 which can be checked by calling `PaneInfo.IsOk`.
210 if isinstance(item, wx.Window):
211 return self._GetPaneByWidget(item)
213 return self._GetPaneByName(item)
215 def AddPane(self, window, info=None, caption=None):
217 AddPane(self, window, info=None, caption=None) -> bool
219 AddPane tells the frame manager to start managing a child
220 window. There are two versions of this function. The first
221 verison accepts a `PaneInfo` object for the ``info`` parameter
222 and allows the full spectrum of pane parameter
223 possibilities. (Say that 3 times fast!)
225 The second version is used for simpler user interfaces which
226 do not require as much configuration. In this case the
227 ``info`` parameter specifies the direction property of the
228 pane info, and defaults to ``wx.LEFT``. The pane caption may
229 also be specified as an extra parameter in this form.
231 if type(info) == PaneInfo:
232 return self._AddPane1(window, info)
239 return self._AddPane2(window, info, caption)
242 // For backwards compatibility
244 SetFrame = wx._deprecated(SetManagedWindow,
245 "SetFrame is deprecated, use `SetManagedWindow` instead.")
246 GetFrame = wx._deprecated(GetManagedWindow,
247 "GetFrame is deprecated, use `GetManagedWindow` instead.")
255 %extend wxDockUIPart {
259 %extend wxPaneButton {
263 //---------------------------------------------------------------------------
266 // A wxDocArt class that knows how to forward virtuals to Python methods
267 class wxPyDockArt : public wxDefaultDockArt
269 wxPyDockArt() : wxDefaultDockArt() {}
271 DEC_PYCALLBACK_INT_INT(GetMetric);
272 DEC_PYCALLBACK_VOID_INTINT(SetMetric);
273 DEC_PYCALLBACK__INTFONT(SetFont);
274 DEC_PYCALLBACK_FONT_INT(GetFont);
275 DEC_PYCALLBACK_COLOUR_INT(GetColour);
276 DEC_PYCALLBACK__INTCOLOUR(SetColour);
278 virtual void DrawSash(wxDC& dc,
284 wxPyBlock_t blocked = wxPyBeginBlockThreads();
285 if ((found = wxPyCBH_findCallback(m_myInst, "DrawSash"))) {
286 PyObject* odc = wxPyMake_wxObject(&dc, false);
287 PyObject* owin = wxPyMake_wxObject(window, false);
288 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
289 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOiO)",
290 odc, owin, orientation, orect));
295 wxPyEndBlockThreads(blocked);
297 wxDefaultDockArt::DrawSash(dc, window, orientation, rect);
300 virtual void DrawBackground(wxDC& dc,
306 wxPyBlock_t blocked = wxPyBeginBlockThreads();
307 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBackground"))) {
308 PyObject* odc = wxPyMake_wxObject(&dc, false);
309 PyObject* owin = wxPyMake_wxObject(window, false);
310 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
311 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOiO)",
312 odc, owin, orientation, orect));
317 wxPyEndBlockThreads(blocked);
319 wxDefaultDockArt::DrawBackground(dc, window, orientation, rect);
322 virtual void DrawCaption(wxDC& dc,
324 const wxString& text,
329 wxPyBlock_t blocked = wxPyBeginBlockThreads();
330 if ((found = wxPyCBH_findCallback(m_myInst, "DrawCaption"))) {
331 PyObject* odc = wxPyMake_wxObject(&dc, false);
332 PyObject* owin = wxPyMake_wxObject(window, false);
333 PyObject* otext = wx2PyString(text);
334 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
335 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
336 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOO)",
337 odc, owin, otext, orect, opane));
344 wxPyEndBlockThreads(blocked);
346 wxDefaultDockArt::DrawCaption(dc, window, text, rect, pane);
349 virtual void DrawGripper(wxDC& dc,
355 wxPyBlock_t blocked = wxPyBeginBlockThreads();
356 if ((found = wxPyCBH_findCallback(m_myInst, "DrawGripper"))) {
357 PyObject* odc = wxPyMake_wxObject(&dc, false);
358 PyObject* owin = wxPyMake_wxObject(window, false);
359 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
360 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
361 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOO)", odc, owin, orect, opane));
366 wxPyEndBlockThreads(blocked);
368 wxDefaultDockArt::DrawGripper(dc, window, rect, pane);
371 virtual void DrawBorder(wxDC& dc,
377 wxPyBlock_t blocked = wxPyBeginBlockThreads();
378 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBorder"))) {
379 PyObject* odc = wxPyMake_wxObject(&dc, false);
380 PyObject* owin = wxPyMake_wxObject(window, false);
381 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
382 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
383 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, orect, opane));
389 wxPyEndBlockThreads(blocked);
391 wxDefaultDockArt::DrawBorder(dc, window, rect, pane);
394 virtual void DrawPaneButton(wxDC& dc,
402 wxPyBlock_t blocked = wxPyBeginBlockThreads();
403 if ((found = wxPyCBH_findCallback(m_myInst, "DrawPaneButton"))) {
404 PyObject* odc = wxPyMake_wxObject(&dc, false);
405 PyObject* owin = wxPyMake_wxObject(window, false);
406 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
407 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
408 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOiIOO)",
409 odc, owin, button, button_state,
416 wxPyEndBlockThreads(blocked);
418 wxDefaultDockArt::DrawPaneButton(dc, window, button, button_state, rect, pane);
425 IMP_PYCALLBACK_INT_INT(wxPyDockArt, wxDefaultDockArt, GetMetric);
426 IMP_PYCALLBACK_VOID_INTINT(wxPyDockArt, wxDefaultDockArt, SetMetric);
427 IMP_PYCALLBACK__INTFONT(wxPyDockArt, wxDefaultDockArt, SetFont);
428 IMP_PYCALLBACK_FONT_INT(wxPyDockArt, wxDefaultDockArt, GetFont);
429 IMP_PYCALLBACK_COLOUR_INT(wxPyDockArt, wxDefaultDockArt, GetColour);
430 IMP_PYCALLBACK__INTCOLOUR(wxPyDockArt, wxDefaultDockArt, SetColour);
436 "This version of the `DockArt` class has been instrumented to be
437 subclassable in Python and to reflect all calls to the C++ base class
438 methods to the Python methods implemented in the derived class.", "");
440 class wxPyDockArt : public wxDefaultDockArt
442 %pythonAppend wxPyDockArt "self._setCallbackInfo(self, PyDockArt)"
448 //---------------------------------------------------------------------------
450 %extend wxAuiMultiNotebook {
451 %property(PageCount, GetPageCount, doc="See `GetPageCount`");
452 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
456 %extend wxAuiNotebookEvent {
457 %property(OldSelection, GetOldSelection, SetOldSelection, doc="See `GetOldSelection` and `SetOldSelection`");
458 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
462 %extend wxAuiTabContainer {
463 %property(ActivePage, GetActivePage, SetActivePage, doc="See `GetActivePage` and `SetActivePage`");
464 %property(PageCount, GetPageCount, doc="See `GetPageCount`");
465 %property(Pages, GetPages, doc="See `GetPages`");
469 %extend wxFrameManager {
470 %property(AllPanes, GetAllPanes, doc="See `GetAllPanes`");
471 %property(ArtProvider, GetArtProvider, SetArtProvider, doc="See `GetArtProvider` and `SetArtProvider`");
472 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
473 %property(ManagedWindow, GetManagedWindow, SetManagedWindow, doc="See `GetManagedWindow` and `SetManagedWindow`");
477 %extend wxFrameManagerEvent {
478 %property(Button, GetButton, SetButton, doc="See `GetButton` and `SetButton`");
479 %property(DC, GetDC, SetDC, doc="See `GetDC` and `SetDC`");
480 %property(Pane, GetPane, SetPane, doc="See `GetPane` and `SetPane`");
484 //---------------------------------------------------------------------------
487 // A wxTabArt class that knows how to forward virtuals to Python methods
488 class wxPyTabArt : public wxDefaultTabArt
490 wxPyTabArt() : wxDefaultTabArt() {}
493 virtual void DrawBackground( wxDC* dc,
497 wxPyBlock_t blocked = wxPyBeginBlockThreads();
498 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBackground"))) {
499 PyObject* odc = wxPyMake_wxObject(dc, false);
500 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
501 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", odc, orect));
505 wxPyEndBlockThreads(blocked);
507 wxDefaultTabArt::DrawBackground(dc, rect);
510 virtual void DrawTab( wxDC* dc,
511 const wxRect& in_rect,
512 const wxString& caption,
518 const char* errmsg = "DrawTab should return a sequence containing (out_rect, x_extent)";
519 wxPyBlock_t blocked = wxPyBeginBlockThreads();
520 if ((found = wxPyCBH_findCallback(m_myInst, "DrawTab"))) {
521 PyObject* odc = wxPyMake_wxObject(dc, false);
522 PyObject* orect = wxPyConstructObject((void*)&in_rect, wxT("wxRect"), 0);
523 PyObject* otext = wx2PyString(caption);
525 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOi)", odc, orect, otext, (int)active));
527 if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
528 PyObject* o1 = PySequence_GetItem(ro, 0);
529 PyObject* o2 = PySequence_GetItem(ro, 1);
530 if (!wxRect_helper(o1, &out_rect))
531 PyErr_SetString(PyExc_TypeError, errmsg);
532 else if (!PyInt_Check(o2))
533 PyErr_SetString(PyExc_TypeError, errmsg);
535 *x_extent = PyInt_AsLong(o2);
541 PyErr_SetString(PyExc_TypeError, errmsg);
550 wxPyEndBlockThreads(blocked);
552 wxDefaultTabArt::DrawTab(dc, in_rect, caption, active, out_rect, x_extent);
556 virtual void DrawButton( wxDC* dc,
557 const wxRect& in_rect,
561 const wxBitmap& bitmap_override,
565 const char* errmsg = "DrawButton should return a wxRect";
566 wxPyBlock_t blocked = wxPyBeginBlockThreads();
567 if ((found = wxPyCBH_findCallback(m_myInst, "DrawButton"))) {
568 PyObject* odc = wxPyMake_wxObject(dc, false);
569 PyObject* orect = wxPyConstructObject((void*)&in_rect, wxT("wxRect"), 0);
570 PyObject* obmp = wxPyConstructObject((void*)&bitmap_override, wxT("wxBitmap"), 0);
572 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOiiiO)", odc, orect,
573 bitmap_id, button_state, orientation,
576 if (!wxRect_helper(ro, &out_rect))
577 PyErr_SetString(PyExc_TypeError, errmsg);
585 wxPyEndBlockThreads(blocked);
587 wxDefaultTabArt::DrawButton(dc, in_rect, bitmap_id, button_state, orientation, bitmap_override, out_rect);
591 virtual wxSize GetTabSize( wxDC* dc,
592 const wxString& caption,
597 wxSize rv, *prv = &rv;
598 const char* errmsg = "GetTabSize should return a sequence containing (size, x_extent)";
599 wxPyBlock_t blocked = wxPyBeginBlockThreads();
600 if ((found = wxPyCBH_findCallback(m_myInst, "GetTabSize"))) {
601 PyObject* odc = wxPyMake_wxObject(dc, false);
602 PyObject* otext = wx2PyString(caption);
604 ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOi)", odc, otext, (int)active));
606 if (PySequence_Check(ro) && PyObject_Length(ro) == 2) {
607 PyObject* o1 = PySequence_GetItem(ro, 0);
608 PyObject* o2 = PySequence_GetItem(ro, 1);
609 if (!wxSize_helper(o1, &prv))
610 PyErr_SetString(PyExc_TypeError, errmsg);
611 else if (!PyInt_Check(o2))
612 PyErr_SetString(PyExc_TypeError, errmsg);
614 *x_extent = PyInt_AsLong(o2);
620 PyErr_SetString(PyExc_TypeError, errmsg);
628 wxPyEndBlockThreads(blocked);
630 rv = wxDefaultTabArt::GetTabSize(dc, caption, active, x_extent);
636 DEC_PYCALLBACK__FONT(SetNormalFont);
637 DEC_PYCALLBACK__FONT(SetSelectedFont);
638 DEC_PYCALLBACK__FONT(SetMeasuringFont);
639 DEC_PYCALLBACK_INT_WIN(GetBestTabCtrlSize);
645 IMP_PYCALLBACK__FONT(wxPyTabArt, wxDefaultTabArt, SetNormalFont);
646 IMP_PYCALLBACK__FONT(wxPyTabArt, wxDefaultTabArt, SetSelectedFont);
647 IMP_PYCALLBACK__FONT(wxPyTabArt, wxDefaultTabArt, SetMeasuringFont);
648 IMP_PYCALLBACK_INT_WIN(wxPyTabArt, wxDefaultTabArt, GetBestTabCtrlSize);
653 "This version of the `TabArt` class has been instrumented to be
654 subclassable in Python and to reflect all calls to the C++ base class
655 methods to the Python methods implemented in the derived class.", "");
657 class wxPyTabArt : public wxDefaultTabArt
659 %pythonAppend wxPyTabArt "self._setCallbackInfo(self, PyTabArt)"
665 //---------------------------------------------------------------------------
668 #undef WXDLLIMPEXP_AUI
670 //---------------------------------------------------------------------------