]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_app.i
added wxString::FromAscii(char*,size_t) for consistency with FromUTF8()
[wxWidgets.git] / wxPython / src / _app.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _app.i
3// Purpose: SWIG interface for wxApp
4//
5// Author: Robin Dunn
6//
7// Created: 9-Aug-2003
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17// TODOs:
18//
19// 1. Provide another app object that allows FilterEvent to be overloaded.
20// 2. Wrap wxAppTraits and allow wxApp::CreateTraits to be overloaded.
21//
22//---------------------------------------------------------------------------
23%newgroup;
24
25%{
26%}
27
28enum {
29 wxPYAPP_ASSERT_SUPPRESS = 1,
30 wxPYAPP_ASSERT_EXCEPTION = 2,
31 wxPYAPP_ASSERT_DIALOG = 4,
32 wxPYAPP_ASSERT_LOG = 8
33};
34
35enum
36{
37 wxPRINT_WINDOWS = 1,
38 wxPRINT_POSTSCRIPT = 2
39};
40
41
42
dce2bd22
RD
43DocStr(wxPyApp,
44"The ``wx.PyApp`` class is an *implementation detail*, please use the
d07d2bc9 45`wx.App` class (or some other derived class) instead.", "");
d14a1e28
RD
46
47class wxPyApp : public wxEvtHandler {
48public:
49
c25f90f6 50 %pythonAppend wxPyApp "self._setOORInfo(self, False);" setCallbackInfo(PyApp)
b39c3fa0 51 %typemap(out) wxPyApp*; // turn off this typemap
d14a1e28 52
856bf319 53 DocStr(wxPyApp,
d07d2bc9 54 "Create a new application object, starting the bootstrap process.", "");
d14a1e28
RD
55 %extend {
56 wxPyApp() {
57 wxPythonApp = new wxPyApp();
58 return wxPythonApp;
59 }
60 }
61
62 ~wxPyApp();
63
b39c3fa0
RD
64 // Turn it back on again
65 %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); }
66
67
c25f90f6 68 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref=false);
d14a1e28 69
d14a1e28 70
6c3b4aae
RD
71 DocDeclStr(
72 wxString, GetAppName() const,
d07d2bc9 73 "Get the application name.", "");
6c3b4aae
RD
74 DocDeclStr(
75 void, SetAppName(const wxString& name),
dce2bd22 76 "Set the application name. This value may be used automatically by
d07d2bc9 77`wx.Config` and such.", "");
6c3b4aae
RD
78
79 DocDeclStr(
80 wxString, GetClassName() const,
d07d2bc9 81 "Get the application's class name.", "");
6c3b4aae
RD
82 DocDeclStr(
83 void, SetClassName(const wxString& name),
dce2bd22 84 "Set the application's class name. This value may be used for
d07d2bc9 85X-resources if applicable for the platform", "");
6c3b4aae
RD
86
87 DocDeclStr(
88 const wxString&, GetVendorName() const,
d07d2bc9 89 "Get the application's vendor name.", "");
6c3b4aae
RD
90 DocDeclStr(
91 void, SetVendorName(const wxString& name),
dce2bd22 92 "Set the application's vendor name. This value may be used
d07d2bc9 93automatically by `wx.Config` and such.", "");
6c3b4aae
RD
94
95
96 DocDeclStr(
97 wxAppTraits*, GetTraits(),
dce2bd22
RD
98 "Return (and create if necessary) the app traits object to which we
99delegate for everything which either should be configurable by the
100user (then he can change the default behaviour simply by overriding
101CreateTraits() and returning his own traits object) or which is
102GUI/console dependent as then wx.AppTraits allows us to abstract the
103differences behind the common facade.
104
d07d2bc9 105:todo: Add support for overriding CreateAppTraits in wxPython.", "");
6c3b4aae
RD
106
107
108 DocDeclStr(
109 virtual void, ProcessPendingEvents(),
dce2bd22
RD
110 "Process all events in the Pending Events list -- it is necessary to
111call this function to process posted events. This normally happens
d07d2bc9 112during each event loop iteration.", "");
6c3b4aae
RD
113
114
0b0849b5
RD
115 DocDeclStr(
116 bool , HasPendingEvents() const,
117 "Check if there are pending events on global pending event list", "");
118
119
6c3b4aae 120 DocDeclStr(
a72f4631 121 virtual bool, Yield(bool onlyIfNeeded = false),
dce2bd22
RD
122 "Process all currently pending events right now, instead of waiting
123until return to the event loop. It is an error to call ``Yield``
124recursively unless the value of ``onlyIfNeeded`` is True.
125
126:warning: This function is dangerous as it can lead to unexpected
d07d2bc9
RD
127 reentrancies (i.e. when called from an event handler it may
128 result in calling the same event handler again), use with
129 extreme care or, better, don't use at all!
dce2bd22 130
d07d2bc9
RD
131:see: `wx.Yield`, `wx.YieldIfNeeded`, `wx.SafeYield`
132", "");
d14a1e28 133
6c3b4aae
RD
134
135 DocDeclStr(
136 virtual void, WakeUpIdle(),
dce2bd22 137 "Make sure that idle events are sent again.
d07d2bc9 138:see: `wx.WakeUpIdle`", "");
d14a1e28 139
45c82204
RD
140
141 DocDeclStr(
142 static bool , IsMainLoopRunning() const,
143 "Returns True if we're running the main loop, i.e. if the events can
144currently be dispatched.", "");
145
d14a1e28 146
6c3b4aae
RD
147 DocDeclStr(
148 virtual int, MainLoop(),
dce2bd22 149 "Execute the main GUI loop, the function doesn't normally return until
d07d2bc9 150all top level windows have been closed and destroyed.", "");
d14a1e28 151
6c3b4aae
RD
152
153 DocDeclStr(
154 virtual void, Exit(),
dce2bd22 155 "Exit the main loop thus terminating the application.
d07d2bc9 156:see: `wx.Exit`", "");
d14a1e28 157
6c3b4aae 158
e81b607b
RD
159 DocDeclStr(
160 virtual wxLayoutDirection , GetLayoutDirection() const,
161 "Return the layout direction for the current locale.", "");
162
163
6c3b4aae
RD
164 DocDeclStr(
165 virtual void, ExitMainLoop(),
dce2bd22 166 "Exit the main GUI loop during the next iteration of the main
d07d2bc9 167loop, (i.e. it does not stop the program immediately!)", "");
d14a1e28 168
6c3b4aae
RD
169
170 DocDeclStr(
171 virtual bool, Pending(),
d07d2bc9 172 "Returns True if there are unprocessed events in the event queue.", "");
d14a1e28 173
6c3b4aae
RD
174
175 DocDeclStr(
176 virtual bool, Dispatch(),
dce2bd22 177 "Process the first event in the event queue (blocks until an event
d07d2bc9 178appears if there are none currently)", "");
d14a1e28 179
d14a1e28 180
6c3b4aae
RD
181 DocDeclStr(
182 virtual bool, ProcessIdle(),
dce2bd22
RD
183 "Called from the MainLoop when the application becomes idle (there are
184no pending events) and sends a `wx.IdleEvent` to all interested
d07d2bc9 185parties. Returns True if more idle events are needed, False if not.", "");
6c3b4aae
RD
186
187
188 DocDeclStr(
189 virtual bool, SendIdleEvents(wxWindow* win, wxIdleEvent& event),
dce2bd22 190 "Send idle event to window and all subwindows. Returns True if more
d07d2bc9 191idle time is requested.", "");
d14a1e28 192
d14a1e28 193
6c3b4aae
RD
194 DocDeclStr(
195 virtual bool, IsActive() const,
d07d2bc9 196 "Return True if our app has focus.", "");
d14a1e28 197
6c3b4aae
RD
198
199 DocDeclStr(
200 void, SetTopWindow(wxWindow *win),
d07d2bc9 201 "Set the *main* top level window", "");
d14a1e28 202
6c3b4aae
RD
203 DocDeclStr(
204 virtual wxWindow*, GetTopWindow() const,
dce2bd22
RD
205 "Return the *main* top level window (if it hadn't been set previously
206with SetTopWindow(), will return just some top level window and, if
d07d2bc9 207there not any, will return None)", "");
d14a1e28 208
d14a1e28 209
6c3b4aae
RD
210 DocDeclStr(
211 void, SetExitOnFrameDelete(bool flag),
dce2bd22
RD
212 "Control the exit behaviour: by default, the program will exit the main
213loop (and so, usually, terminate) when the last top-level program
214window is deleted. Beware that if you disable this behaviour (with
215SetExitOnFrameDelete(False)), you'll have to call ExitMainLoop()
d07d2bc9 216explicitly from somewhere.", "");
6c3b4aae
RD
217
218
219 DocDeclStr(
220 bool, GetExitOnFrameDelete() const,
d07d2bc9 221 "Get the current exit behaviour setting.", "");
d14a1e28
RD
222
223#if 0
856bf319 224 // Get display mode that is in use. This is only used in framebuffer
d14a1e28
RD
225 // wxWin ports (such as wxMGL).
226 virtual wxVideoMode GetDisplayMode() const;
227
228 // Set display mode to use. This is only used in framebuffer wxWin
229 // ports (such as wxMGL). This method should be called from
230 // wxApp::OnInitGui
231 virtual bool SetDisplayMode(const wxVideoMode& info);
232#endif
233
6c3b4aae
RD
234
235 DocDeclStr(
f31ed3f1 236 void, SetUseBestVisual( bool flag, bool forceTrueColour = false ),
dce2bd22 237 "Set whether the app should try to use the best available visual on
d07d2bc9 238systems where more than one is available, (Sun, SGI, XFree86 4, etc.)", "");
6c3b4aae
RD
239
240 DocDeclStr(
241 bool, GetUseBestVisual() const,
d07d2bc9 242 "Get current UseBestVisual setting.", "");
6c3b4aae 243
d14a1e28
RD
244
245 // set/get printing mode: see wxPRINT_XXX constants.
246 //
247 // default behaviour is the normal one for Unix: always use PostScript
248 // printing.
249 virtual void SetPrintMode(int mode);
250 int GetPrintMode() const;
251
6c3b4aae
RD
252
253 DocDeclStr(
254 void, SetAssertMode(int mode),
d07d2bc9
RD
255 "Set the OnAssert behaviour for debug and hybrid builds.",
256 "The following flags may be or'd together:
dce2bd22
RD
257
258 ========================= =======================================
259 wx.PYAPP_ASSERT_SUPPRESS Don't do anything
260 wx.PYAPP_ASSERT_EXCEPTION Turn it into a Python exception if possible
261 (default)
262 wx.PYAPP_ASSERT_DIALOG Display a message dialog
263 wx.PYAPP_ASSERT_LOG Write the assertion info to the wx.Log
264 ========================= =======================================
265
266");
6c3b4aae
RD
267
268 DocDeclStr(
269 int, GetAssertMode(),
d07d2bc9 270 "Get the current OnAssert behaviour setting.", "");
d14a1e28
RD
271
272
e12096a9 273 static bool GetMacSupportPCMenuShortcuts(); // TODO, deprecate this
d14a1e28
RD
274 static long GetMacAboutMenuItemId();
275 static long GetMacPreferencesMenuItemId();
276 static long GetMacExitMenuItemId();
277 static wxString GetMacHelpMenuTitleName();
278
e12096a9 279 static void SetMacSupportPCMenuShortcuts(bool val); // TODO, deprecate this
d14a1e28
RD
280 static void SetMacAboutMenuItemId(long val);
281 static void SetMacPreferencesMenuItemId(long val);
282 static void SetMacExitMenuItemId(long val);
283 static void SetMacHelpMenuTitleName(const wxString& val);
284
d14a1e28 285
6c3b4aae
RD
286 DocDeclStr(
287 void, _BootstrapApp(),
d07d2bc9 288 "For internal use only", "");
6c3b4aae
RD
289
290 DocStr(GetComCtl32Version,
dce2bd22 291 "Returns 400, 470, 471, etc. for comctl32.dll 4.00, 4.70, 4.71 or 0 if
d07d2bc9 292it wasn't found at all. Raises an exception on non-Windows platforms.", "");
d14a1e28 293#ifdef __WXMSW__
d14a1e28
RD
294 static int GetComCtl32Version();
295#else
296 %extend {
297 static int GetComCtl32Version()
81cfe5e1 298 { wxPyRaiseNotImplemented(); return 0; }
d14a1e28
RD
299 }
300#endif
4d9de110
RD
301
302 %extend {
7012bb9f 303 DocStr(IsDisplayAvailable,
4d9de110
RD
304 "Tests if it is possible to create a GUI in the current environment.
305This will mean different things on the different platforms.
306
307 * On X Windows systems this function will return ``False`` if it is
308 not able to open a connection to the X display, which can happen
309 if $DISPLAY is not set, or is not set correctly.
310
311 * On Mac OS X a ``False`` return value will mean that wx is not
312 able to access the window manager, which can happen if logged in
313 remotely or if running from the normal version of python instead
314 of the framework version, (i.e., pythonw.)
315
316 * On MS Windows...
317", "");
7012bb9f 318 static bool IsDisplayAvailable() {
4d9de110
RD
319 return wxPyTestDisplayAvailable();
320 }
321 }
7012bb9f
RD
322
323
324 %property(AppName, GetAppName, SetAppName, doc="See `GetAppName` and `SetAppName`");
325 %property(AssertMode, GetAssertMode, SetAssertMode, doc="See `GetAssertMode` and `SetAssertMode`");
326 %property(ClassName, GetClassName, SetClassName, doc="See `GetClassName` and `SetClassName`");
327 %property(ExitOnFrameDelete, GetExitOnFrameDelete, SetExitOnFrameDelete, doc="See `GetExitOnFrameDelete` and `SetExitOnFrameDelete`");
328 %property(LayoutDirection, GetLayoutDirection, doc="See `GetLayoutDirection`");
329 %property(PrintMode, GetPrintMode, SetPrintMode, doc="See `GetPrintMode` and `SetPrintMode`");
330 %property(TopWindow, GetTopWindow, SetTopWindow, doc="See `GetTopWindow` and `SetTopWindow`");
331 %property(Traits, GetTraits, doc="See `GetTraits`");
332 %property(UseBestVisual, GetUseBestVisual, SetUseBestVisual, doc="See `GetUseBestVisual` and `SetUseBestVisual`");
333 %property(VendorName, GetVendorName, SetVendorName, doc="See `GetVendorName` and `SetVendorName`");
334
335 %property(Active, IsActive);
d14a1e28
RD
336};
337
338
339
340//---------------------------------------------------------------------------
341%newgroup;
342
d14a1e28 343
6c3b4aae
RD
344DocDeclStr(
345 void, wxExit(),
d07d2bc9 346 "Force an exit of the application. Convenience for wx.GetApp().Exit()", "");
6c3b4aae
RD
347
348
349DocDeclStr(
350 bool, wxYield(),
d07d2bc9 351 "Yield to other apps/messages. Convenience for wx.GetApp().Yield()", "");
d14a1e28 352
6c3b4aae
RD
353DocDeclStr(
354 bool, wxYieldIfNeeded(),
d07d2bc9 355 "Yield to other apps/messages. Convenience for wx.GetApp().Yield(True)", "");
d14a1e28 356
d14a1e28 357
6c3b4aae 358DocDeclStr(
a72f4631 359 bool, wxSafeYield(wxWindow* win=NULL, bool onlyIfNeeded=false),
dce2bd22
RD
360 "This function is similar to `wx.Yield`, except that it disables the
361user input to all program windows before calling `wx.Yield` and
362re-enables it again afterwards. If ``win`` is not None, this window
363will remain enabled, allowing the implementation of some limited user
364interaction.
365
d07d2bc9 366:Returns: the result of the call to `wx.Yield`.", "");
6c3b4aae
RD
367
368
369DocDeclStr(
370 void, wxWakeUpIdle(),
dce2bd22 371 "Cause the message queue to become empty again, so idle events will be
d07d2bc9 372sent.", "");
6c3b4aae
RD
373
374
375DocDeclStr(
376 void, wxPostEvent(wxEvtHandler *dest, wxEvent& event),
dce2bd22 377 "Send an event to a window or other wx.EvtHandler to be processed
d07d2bc9 378later.", "");
6c3b4aae
RD
379
380
381DocStr(wxApp_CleanUp,
d07d2bc9
RD
382 "For internal use only, it is used to cleanup after wxWidgets when
383Python shuts down.", "");
d14a1e28
RD
384%inline %{
385 void wxApp_CleanUp() {
386 __wxPyCleanup();
387 }
388%}
389
6c3b4aae 390
c92d9283
RD
391DocDeclStrName(
392 wxPyApp* , wxPyGetApp(),
393 "Return a reference to the current wx.App object.", "",
394 GetApp);
395%{
396 wxPyApp* wxPyGetApp() { return (wxPyApp*)wxTheApp; }
d14a1e28
RD
397%}
398
399
c92d9283 400
27c9e43c
RD
401
402
403DocDeclAStr(
404 void , wxSetDefaultPyEncoding(const char* encoding),
405 "SetDefaultPyEncoding(string encoding)",
406 "Sets the encoding that wxPython will use when it needs to convert a
669e06d7
RD
407Python string or unicode object to or from a wxString.
408
409The default encoding is the value of ``locale.getdefaultlocale()[1]``
410but please be aware that the default encoding within the same locale
411may be slightly different on different platforms. For example, please
412see http://www.alanwood.net/demos/charsetdiffs.html for differences
413between the common latin/roman encodings.", "");
27c9e43c
RD
414
415DocDeclAStr(
416 const char* , wxGetDefaultPyEncoding(),
417 "GetDefaultPyEncoding() -> string",
418 "Gets the current encoding that wxPython will use when it needs to
419convert a Python string or unicode object to or from a wxString.", "");
420
421
d14a1e28
RD
422//---------------------------------------------------------------------------
423// Include some extra wxApp related python code here
424
425%pythoncode "_app_ex.py"
426
427//---------------------------------------------------------------------------
428