]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/aui.i
e5047351e1e9178f6804ddf27abeb071e6dcc2f6
[wxWidgets.git] / wxPython / src / aui.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: aui.i
3 // Purpose: Wrappers for the wxAUI classes.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 5-July-2006
8 // RCS-ID: $Id$
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
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.
18
19 **Vision and Design Principles**
20
21 wx.aui attempts to encapsulate the following aspects of the user
22 interface:
23
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.
28
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.
34
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.
40
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
45 animation.
46
47 **PyAUI adheres to the following principles**
48
49 - Use native floating frames to obtain a native look and feel for
50 all platforms;
51
52 - Use existing wxPython code where possible, such as sizer
53 implementation for frame management;
54
55 - Use standard wxPython coding conventions.
56
57
58 **Usage**
59
60 The following example shows a simple implementation that utilizes
61 `wx.aui.FrameManager` to manage three text controls in a frame window::
62
63 import wx
64 import wx.aui
65
66 class MyFrame(wx.Frame):
67
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)
71
72 self._mgr = wx.aui.FrameManager(self)
73
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)
78
79 text2 = wx.TextCtrl(self, -1, 'Pane 2 - sample text',
80 wx.DefaultPosition, wx.Size(200,150),
81 wx.NO_BORDER | wx.TE_MULTILINE)
82
83 text3 = wx.TextCtrl(self, -1, 'Main content window',
84 wx.DefaultPosition, wx.Size(200,150),
85 wx.NO_BORDER | wx.TE_MULTILINE)
86
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)
91
92 # tell the manager to 'commit' all the changes just made
93 self._mgr.Update()
94
95 self.Bind(wx.EVT_CLOSE, self.OnClose)
96
97
98 def OnClose(self, event):
99 # deinitialize the frame manager
100 self._mgr.UnInit()
101 # delete the frame
102 self.Destroy()
103
104
105 app = wx.App()
106 frame = MyFrame(None)
107 frame.Show()
108 app.MainLoop()
109 "
110 %enddef
111
112
113
114 %module(package="wx", docstring=DOCSTRING) aui
115
116 %{
117 #include "wx/wxPython/wxPython.h"
118 #include "wx/wxPython/pyclasses.h"
119 #include <wx/aui/aui.h>
120 %}
121
122 //---------------------------------------------------------------------------
123
124 %import core.i
125 %import windows.i
126
127 %pythoncode { wx = _core }
128 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
129
130
131 %include _aui_docstrings.i
132
133 //---------------------------------------------------------------------------
134
135
136 #define wxUSE_AUI 1
137 #define WXDLLIMPEXP_AUI
138 #define unsigned
139 #define wxDEPRECATED(decl)
140
141
142 // We'll let SWIG handle the function overloading for these
143 %ignore wxPaneInfo::MaxSize(int x, int y);
144 %ignore wxPaneInfo::MinSize(int x, int y);
145 %ignore wxPaneInfo::BestSize(int x, int y);
146 %ignore wxPaneInfo::FloatingPosition(int x, int y);
147 %ignore wxPaneInfo::FloatingSize(int x, int y);
148
149 // But for these we will do the overloading (see %pythoncode below) so let's
150 // rename the C++ versions
151 %rename(_GetPaneByWidget) wxFrameManager::GetPane(wxWindow* window);
152 %rename(_GetPaneByName) wxFrameManager::GetPane(const wxString& name);
153
154 %rename(_AddPane1) wxFrameManager::AddPane(wxWindow* window, const wxPaneInfo& pane_info);
155 %rename(_AddPane2) wxFrameManager::AddPane(wxWindow* window, int direction = wxLEFT,
156 const wxString& caption = wxEmptyString);
157
158 %rename(AddPaneAtPos) wxFrameManager::AddPane(wxWindow* window,
159 const wxPaneInfo& pane_info,
160 const wxPoint& drop_pos);
161
162 // A typemap for the return value of wxFrameManager::GetAllPanes
163 %typemap(out) wxPaneInfoArray& {
164 $result = PyList_New(0);
165 for (size_t i=0; i < $1->GetCount(); i++) {
166 PyObject* pane_obj = SWIG_NewPointerObj((void*)(&$1->Item(i)), SWIGTYPE_p_wxPaneInfo, 0);
167 PyList_Append($result, pane_obj);
168 }
169 }
170
171
172 //---------------------------------------------------------------------------
173 // Get all our defs from the REAL header files.
174 %include framemanager.h
175 %include dockart.h
176 %include floatpane.h
177
178
179 //---------------------------------------------------------------------------
180 // Methods to inject into the FrameManager class that will sort out calls to
181 // the overloaded versions of GetPane and AddPane
182
183 %extend wxFrameManager {
184 %pythoncode {
185 def GetPane(self, item):
186 """
187 GetPane(self, window_or_info item) -> PaneInfo
188
189 GetPane is used to search for a `PaneInfo` object either by
190 widget reference or by pane name, which acts as a unique id
191 for a window pane. The returned `PaneInfo` object may then be
192 modified to change a pane's look, state or position. After one
193 or more modifications to the `PaneInfo`, `FrameManager.Update`
194 should be called to realize the changes to the user interface.
195
196 If the lookup failed (meaning the pane could not be found in
197 the manager) GetPane returns an empty `PaneInfo`, a condition
198 which can be checked by calling `PaneInfo.IsOk`.
199 """
200 if isinstance(item, wx.Window):
201 return self._GetPaneByWidget(item)
202 else:
203 return self._GetPaneByName(item)
204
205 def AddPane(self, window, info=None, caption=None):
206 """
207 AddPane(self, window, info=None, caption=None) -> bool
208
209 AddPane tells the frame manager to start managing a child
210 window. There are two versions of this function. The first
211 verison accepts a `PaneInfo` object for the ``info`` parameter
212 and allows the full spectrum of pane parameter
213 possibilities. (Say that 3 times fast!)
214
215 The second version is used for simpler user interfaces which
216 do not require as much configuration. In this case the
217 ``info`` parameter specifies the direction property of the
218 pane info, and defaults to ``wx.LEFT``. The pane caption may
219 also be specified as an extra parameter in this form.
220 """
221 if type(info) == PaneInfo:
222 return self._AddPane1(window, info)
223 else:
224 # This Is AddPane2
225 if info is None:
226 info = wx.LEFT
227 if caption is None:
228 caption = ""
229 return self._AddPane2(window, info, caption)
230 }
231
232 // For backwards compatibility
233 %pythoncode {
234 SetFrame = wx._deprecated(SetManagedWindow,
235 "SetFrame is deprecated, use `SetManagedWindow` instead.")
236 GetFrame = wx._deprecated(GetManagedWindow,
237 "GetFrame is deprecated, use `GetManagedWindow` instead.")
238 }
239 }
240
241 //---------------------------------------------------------------------------
242
243 %{
244 class wxPyDockArt : public wxDefaultDockArt
245 {
246 wxPyDockArt() : wxDefaultDockArt() {}
247
248 DEC_PYCALLBACK_INT_INT(GetMetric);
249 DEC_PYCALLBACK_VOID_INTINT(SetMetric);
250 DEC_PYCALLBACK__INTFONT(SetFont);
251 DEC_PYCALLBACK_FONT_INT(GetFont);
252 DEC_PYCALLBACK_COLOUR_INT(GetColour);
253 DEC_PYCALLBACK__INTCOLOUR(SetColour);
254
255 virtual void DrawSash(wxDC& dc,
256 int orientation,
257 const wxRect& rect)
258 {
259 bool found;
260 wxPyBlock_t blocked = wxPyBeginBlockThreads();
261 if ((found = wxPyCBH_findCallback(m_myInst, "DrawSash"))) {
262 PyObject* odc = wxPyMake_wxObject(&dc, false);
263 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
264 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)",
265 odc, orientation, orect));
266 Py_DECREF(odc);
267 Py_DECREF(orect);
268 }
269 wxPyEndBlockThreads(blocked);
270 if (! found)
271 wxDefaultDockArt::DrawSash(dc, orientation, rect);
272 }
273
274 virtual void DrawBackground(wxDC& dc,
275 int orientation,
276 const wxRect& rect)
277 {
278 bool found;
279 wxPyBlock_t blocked = wxPyBeginBlockThreads();
280 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBackground"))) {
281 PyObject* odc = wxPyMake_wxObject(&dc, false);
282 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
283 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)",
284 odc, orientation, orect));
285 Py_DECREF(odc);
286 Py_DECREF(orect);
287 }
288 wxPyEndBlockThreads(blocked);
289 if (! found)
290 wxDefaultDockArt::DrawBackground(dc, orientation, rect);
291 }
292
293 virtual void DrawCaption(wxDC& dc,
294 const wxString& text,
295 const wxRect& rect,
296 wxPaneInfo& pane)
297 {
298 bool found;
299 wxPyBlock_t blocked = wxPyBeginBlockThreads();
300 if ((found = wxPyCBH_findCallback(m_myInst, "DrawCaption"))) {
301 PyObject* odc = wxPyMake_wxObject(&dc, false);
302 PyObject* otext = wx2PyString(text);
303 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
304 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
305 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOO)",
306 odc, otext, orect, opane));
307 Py_DECREF(odc);
308 Py_DECREF(otext);
309 Py_DECREF(orect);
310 Py_DECREF(opane);
311 }
312 wxPyEndBlockThreads(blocked);
313 if (! found)
314 wxDefaultDockArt::DrawCaption(dc, text, rect, pane);
315 }
316
317 virtual void DrawGripper(wxDC& dc,
318 const wxRect& rect,
319 wxPaneInfo& pane)
320 {
321 bool found;
322 wxPyBlock_t blocked = wxPyBeginBlockThreads();
323 if ((found = wxPyCBH_findCallback(m_myInst, "DrawGripper"))) {
324 PyObject* odc = wxPyMake_wxObject(&dc, false);
325 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
326 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
327 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, orect, opane));
328 Py_DECREF(odc);
329 Py_DECREF(orect);
330 Py_DECREF(opane);
331 }
332 wxPyEndBlockThreads(blocked);
333 if (! found)
334 wxDefaultDockArt::DrawGripper(dc, rect, pane);
335 }
336
337 virtual void DrawBorder(wxDC& dc,
338 const wxRect& rect,
339 wxPaneInfo& pane)
340 {
341 bool found;
342 wxPyBlock_t blocked = wxPyBeginBlockThreads();
343 if ((found = wxPyCBH_findCallback(m_myInst, "DrawBorder"))) {
344 PyObject* odc = wxPyMake_wxObject(&dc, false);
345 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
346 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
347 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", odc, orect, opane));
348 Py_DECREF(odc);
349 Py_DECREF(orect);
350 Py_DECREF(opane);
351 }
352 wxPyEndBlockThreads(blocked);
353 if (! found)
354 wxDefaultDockArt::DrawBorder(dc, rect, pane);
355 }
356
357 virtual void DrawPaneButton(wxDC& dc,
358 int button,
359 int button_state,
360 const wxRect& rect,
361 wxPaneInfo& pane)
362 {
363 bool found;
364 wxPyBlock_t blocked = wxPyBeginBlockThreads();
365 if ((found = wxPyCBH_findCallback(m_myInst, "DrawPaneButton"))) {
366 PyObject* odc = wxPyMake_wxObject(&dc, false);
367 PyObject* orect = wxPyConstructObject((void*)&rect, wxT("wxRect"), 0);
368 PyObject* opane = wxPyConstructObject((void*)&pane, wxT("wxPaneInfo"), 0);
369 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiIOO)",
370 odc, button, button_state,
371 orect, opane));
372 Py_DECREF(odc);
373 Py_DECREF(orect);
374 Py_DECREF(opane);
375 }
376 wxPyEndBlockThreads(blocked);
377 if (! found)
378 wxDefaultDockArt::DrawPaneButton(dc, button, button_state, rect, pane);
379 }
380
381 PYPRIVATE;
382
383 };
384
385 IMP_PYCALLBACK_INT_INT(wxPyDockArt, wxDefaultDockArt, GetMetric);
386 IMP_PYCALLBACK_VOID_INTINT(wxPyDockArt, wxDefaultDockArt, SetMetric);
387 IMP_PYCALLBACK__INTFONT(wxPyDockArt, wxDefaultDockArt, SetFont);
388 IMP_PYCALLBACK_FONT_INT(wxPyDockArt, wxDefaultDockArt, GetFont);
389 IMP_PYCALLBACK_COLOUR_INT(wxPyDockArt, wxDefaultDockArt, GetColour);
390 IMP_PYCALLBACK__INTCOLOUR(wxPyDockArt, wxDefaultDockArt, SetColour);
391
392 %}
393
394
395 DocStr(wxPyDockArt,
396 "This version of the `DockArt` class has been instrumented to be
397 subclassable in Python and to reflect all calls to the C++ base class
398 methods to the Python methods implemented in the derived class.", "");
399
400 class wxPyDockArt : public wxDefaultDockArt
401 {
402 %pythonAppend wxPyDockArt "self._setCallbackInfo(self, PyDockArt)"
403 PyDocArt();
404
405 };
406
407
408
409 #undef wxUSE_AUI
410 #undef WXDLLIMPEXP_AUI
411
412 //---------------------------------------------------------------------------
413