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
140 // We'll let SWIG handle the function overloading for these
141 %ignore wxPaneInfo::MaxSize(int x, int y);
142 %ignore wxPaneInfo::MinSize(int x, int y);
143 %ignore wxPaneInfo::BestSize(int x, int y);
144 %ignore wxPaneInfo::FloatingPosition(int x, int y);
145 %ignore wxPaneInfo::FloatingSize(int x, int y);
147 // But for these we will do the overloading (see %pythoncode below) so let's
148 // rename the C++ versions
149 %rename(_GetPaneByWidget) wxFrameManager::GetPane(wxWindow* window);
150 %rename(_GetPaneByName) wxFrameManager::GetPane(const wxString& name);
152 %rename(_AddPane1) wxFrameManager::AddPane(wxWindow* window, const wxPaneInfo& pane_info);
153 %rename(_AddPane2) wxFrameManager::AddPane(wxWindow* window, int direction = wxLEFT,
154 const wxString& caption = wxEmptyString);
157 // A typemap for the return value of wxFrameManager::GetAllPanes
158 %typemap(out) wxPaneInfoArray& {
159 $result = PyList_New(0);
160 for (size_t i=0; i < $1->GetCount(); i++) {
161 PyObject* pane_obj = SWIG_NewPointerObj((void*)(&$1->Item(i)), SWIGTYPE_p_wxPaneInfo, 0);
162 PyList_Append($result, pane_obj);
167 //---------------------------------------------------------------------------
168 // Get all our defs from the REAL header files.
169 %include framemanager.h
174 //---------------------------------------------------------------------------
175 // Methods to inject into the FrameManager class that will sort out calls to
176 // the overloaded versions of GetPane and AddPane
178 %extend wxFrameManager {
180 def GetPane(self, item):
182 GetPane(self, window_or_info item) -> PaneInfo
184 GetPane is used to search for a `PaneInfo` object either by
185 widget reference or by pane name, which acts as a unique id
186 for a window pane. The returned `PaneInfo` object may then be
187 modified to change a pane's look, state or position. After one
188 or more modifications to the `PaneInfo`, `FrameManager.Update`
189 should be called to realize the changes to the user interface.
191 If the lookup failed (meaning the pane could not be found in
192 the manager) GetPane returns an empty `PaneInfo`, a condition
193 which can be checked by calling `PaneInfo.IsOk`.
195 if isinstance(item, wx.Window):
196 return self._GetPaneByWidget(item)
198 return self._GetPaneByName(item)
200 def AddPane(self, window, info=None, caption=None):
202 AddPane(self, window, info=None, caption=None) -> bool
204 AddPane tells the frame manager to start managing a child
205 window. There are two versions of this function. The first
206 verison accepts a `PaneInfo` object for the ``info`` parameter
207 and allows the full spectrum of pane parameter
208 possibilities. (Say that 3 times fast!)
210 The second version is used for simpler user interfaces which
211 do not require as much configuration. In this case the
212 ``info`` parameter specifies the direction property of the
213 pane info, and defaults to ``wx.LEFT``. The pane caption may
214 also be specified as an extra parameter in this form.
216 if type(info) == PaneInfo:
217 return self._AddPane1(window, info)
224 return self._AddPane2(window, info, caption)
228 //---------------------------------------------------------------------------
231 class wxPyDockArt : public wxDefaultDockArt
233 wxPyDockArt() : wxDefaultDockArt() {}
235 DEC_PYCALLBACK_INT_INT(GetMetric);
236 DEC_PYCALLBACK_VOID_INTINT(SetMetric);
237 DEC_PYCALLBACK__INTFONT(SetFont);
238 DEC_PYCALLBACK_FONT_INT(GetFont);
239 DEC_PYCALLBACK_COLOUR_INT(GetColour);
240 DEC_PYCALLBACK__INTCOLOUR(SetColour);
242 virtual void DrawSash(wxDC& dc,
247 wxPyBlock_t blocked = wxPyBeginBlockThreads();
248 if ((found = wxPyCBH_findCallback(m_myInst, "DrawSash"))) {
249 PyObject* odc = wxPyMake_wxObject(&dc, false);
250 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
251 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)",
252 odc, orientation, orect));
256 wxPyEndBlockThreads(blocked);
258 wxDefaultDockArt::DrawSash(dc, orientation, rect);
261 virtual void DrawBackground(wxDC& dc,
266 wxPyBlock_t blocked = wxPyBeginBlockThreads();
267 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBackground"))) {
268 PyObject* odc = wxPyMake_wxObject(&dc, false);
269 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
270 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)",
271 odc, orientation, orect));
275 wxPyEndBlockThreads(blocked);
277 wxDefaultDockArt::DrawBackground(dc, orientation, rect);
280 virtual void DrawCaption(wxDC& dc,
281 const wxString& text,
286 wxPyBlock_t blocked = wxPyBeginBlockThreads();
287 if ((found = wxPyCBH_findCallback(m_myInst, "DrawCaption"))) {
288 PyObject* odc = wxPyMake_wxObject(&dc, false);
289 PyObject* otext = wx2PyString(text);
290 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
291 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
292 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOO)",
293 odc, otext, orect, opane));
299 wxPyEndBlockThreads(blocked);
301 wxDefaultDockArt::DrawCaption(dc, text, rect, pane);
304 virtual void DrawGripper(wxDC& dc,
309 wxPyBlock_t blocked = wxPyBeginBlockThreads();
310 if ((found = wxPyCBH_findCallback(m_myInst, "DrawGripper"))) {
311 PyObject* odc = wxPyMake_wxObject(&dc, false);
312 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
313 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
314 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, orect, opane));
319 wxPyEndBlockThreads(blocked);
321 wxDefaultDockArt::DrawGripper(dc, rect, pane);
324 virtual void DrawBorder(wxDC& dc,
329 wxPyBlock_t blocked = wxPyBeginBlockThreads();
330 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBorder"))) {
331 PyObject* odc = wxPyMake_wxObject(&dc, false);
332 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
333 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
334 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, orect, opane));
339 wxPyEndBlockThreads(blocked);
341 wxDefaultDockArt::DrawBorder(dc, rect, pane);
344 virtual void DrawPaneButton(wxDC& dc,
351 wxPyBlock_t blocked = wxPyBeginBlockThreads();
352 if ((found = wxPyCBH_findCallback(m_myInst, "DrawPaneButton"))) {
353 PyObject* odc = wxPyMake_wxObject(&dc, false);
354 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
355 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
356 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiIOO)",
357 odc, button, button_state,
363 wxPyEndBlockThreads(blocked);
365 wxDefaultDockArt::DrawPaneButton(dc, button, button_state, rect, pane);
372 IMP_PYCALLBACK_INT_INT(wxPyDockArt, wxDefaultDockArt, GetMetric);
373 IMP_PYCALLBACK_VOID_INTINT(wxPyDockArt, wxDefaultDockArt, SetMetric);
374 IMP_PYCALLBACK__INTFONT(wxPyDockArt, wxDefaultDockArt, SetFont);
375 IMP_PYCALLBACK_FONT_INT(wxPyDockArt, wxDefaultDockArt, GetFont);
376 IMP_PYCALLBACK_COLOUR_INT(wxPyDockArt, wxDefaultDockArt, GetColour);
377 IMP_PYCALLBACK__INTCOLOUR(wxPyDockArt, wxDefaultDockArt, SetColour);
383 "This version of the `DockArt` class has been instrumented to be
384 subclassable in Python and to reflect all calls to the C++ base class
385 methods to the Python methods implemented in the derived class.", "");
387 class wxPyDockArt : public wxDefaultDockArt
389 %pythonAppend wxPyDockArt "self._setCallbackInfo(self, PyDockArt)"
397 #undef WXDLLIMPEXP_AUI
399 //---------------------------------------------------------------------------