]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/misc.i
My RPM spec now uses the --enable-rpath
[wxWidgets.git] / wxPython / src / misc.i
CommitLineData
7bf85405
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: misc.i
3// Purpose: Definitions of miscelaneous functions and classes
4//
5// Author: Robin Dunn
6//
7// Created: 7/3/97
8// RCS-ID: $Id$
9// Copyright: (c) 1998 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
03e9bead 13%module misc
7bf85405 14
03e9bead 15%{
7bf85405
RD
16#include "helpers.h"
17#include <wx/resource.h>
af309447 18#include <wx/tooltip.h>
2abc0a0f 19#include <wx/busyinfo.h>
7bf85405
RD
20%}
21
22//----------------------------------------------------------------------
23
24%include typemaps.i
25%include my_typemaps.i
26
27// Import some definitions of other classes, etc.
28%import _defs.i
29
7bf85405 30
137b5242
RD
31//---------------------------------------------------------------------------
32%{
33 // Put some wx default wxChar* values into wxStrings.
34 static const wxString wxPyEmptyString(wxT(""));
35%}
bb0054cd 36//---------------------------------------------------------------------------
7bf85405
RD
37
38
9416aa89
RD
39class wxObject {
40public:
41
42 %addmethods {
c8bc7bb8 43 wxString GetClassName() {
9416aa89
RD
44 return self->GetClassInfo()->GetClassName();
45 }
46
47 void Destroy() {
48 delete self;
49 }
50 }
51};
52
53//---------------------------------------------------------------------------
54
7bf85405
RD
55class wxSize {
56public:
af309447
RD
57 long x;
58 long y;
7bf85405
RD
59 %name(width) long x;
60 %name(height)long y;
61
62 wxSize(long w=0, long h=0);
63 ~wxSize();
64 void Set(long w, long h);
af309447
RD
65 long GetX();
66 long GetY();
bb0054cd
RD
67 long GetWidth();
68 long GetHeight();
69 void SetWidth(long w);
70 void SetHeight(long h);
7bf85405
RD
71
72 %addmethods {
af309447 73 PyObject* asTuple() {
7cdaed0b 74 wxPyBeginBlockThreads();
7bf85405
RD
75 PyObject* tup = PyTuple_New(2);
76 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
77 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
7cdaed0b 78 wxPyEndBlockThreads();
7bf85405
RD
79 return tup;
80 }
419c299a
RD
81
82 int __cmp__(const wxSize* sz) {
83 if (! sz) return 1;
84 if (*self == *sz) return 0;
85 return -1;
86 }
7bf85405 87 }
1b62f00d
RD
88
89 %pragma(python) addtoclass = "
90 def __str__(self): return str(self.asTuple())
91 def __repr__(self): return str(self.asTuple())
211a46cf 92 def __len__(self): return len(self.asTuple())
1b62f00d
RD
93 def __getitem__(self, index): return self.asTuple()[index]
94 def __setitem__(self, index, val):
95 if index == 0: self.width = val
96 elif index == 1: self.height = val
97 else: raise IndexError
98"
af309447 99
7bf85405
RD
100};
101
102//---------------------------------------------------------------------------
103
104class wxRealPoint {
105public:
106 double x;
107 double y;
108 wxRealPoint(double x=0.0, double y=0.0);
109 ~wxRealPoint();
efc5f224
RD
110
111 %addmethods {
112 void Set(double x, double y) {
113 self->x = x;
114 self->y = y;
115 }
116 PyObject* asTuple() {
7cdaed0b 117 wxPyBeginBlockThreads();
efc5f224
RD
118 PyObject* tup = PyTuple_New(2);
119 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
120 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
7cdaed0b 121 wxPyEndBlockThreads();
efc5f224
RD
122 return tup;
123 }
c368d904
RD
124
125 wxRealPoint __add__(const wxRealPoint* p) {
126 if (! p) return *self;
127 return *self + *p;
128 }
129
130 wxRealPoint __sub__(const wxRealPoint* p) {
131 if (! p) return *self;
132 return *self - *p;
133 }
134
135 int __cmp__(const wxRealPoint* p) {
419c299a
RD
136 if (! p) return 1;
137 if (*self == *p) return 0;
138 return -1;
c368d904 139 }
efc5f224 140 }
1b62f00d
RD
141 %pragma(python) addtoclass = "
142 def __str__(self): return str(self.asTuple())
143 def __repr__(self): return str(self.asTuple())
211a46cf 144 def __len__(self): return len(self.asTuple())
1b62f00d
RD
145 def __getitem__(self, index): return self.asTuple()[index]
146 def __setitem__(self, index, val):
147 if index == 0: self.width = val
148 elif index == 1: self.height = val
149 else: raise IndexError
150"
7bf85405
RD
151};
152
efc5f224 153
7bf85405
RD
154class wxPoint {
155public:
156 long x;
157 long y;
158 wxPoint(long x=0, long y=0);
159 ~wxPoint();
160
161 %addmethods {
162 void Set(long x, long y) {
163 self->x = x;
164 self->y = y;
165 }
af309447 166 PyObject* asTuple() {
7cdaed0b 167 wxPyBeginBlockThreads();
7bf85405
RD
168 PyObject* tup = PyTuple_New(2);
169 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
170 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
7cdaed0b 171 wxPyEndBlockThreads();
7bf85405
RD
172 return tup;
173 }
c368d904
RD
174
175 wxPoint __add__(const wxPoint* p) {
176 if (! p) return *self;
177 return *self + *p;
178 }
179
180 wxPoint __sub__(const wxPoint* p) {
181 if (! p) return *self;
182 return *self - *p;
183 }
184
185 int __cmp__(const wxPoint* p) {
419c299a
RD
186 if (! p) return 1;
187 if (*self == *p) return 0;
188 return -1;
c368d904 189 }
7bf85405 190 }
1b62f00d
RD
191 %pragma(python) addtoclass = "
192 def __str__(self): return str(self.asTuple())
193 def __repr__(self): return str(self.asTuple())
211a46cf 194 def __len__(self): return len(self.asTuple())
1b62f00d
RD
195 def __getitem__(self, index): return self.asTuple()[index]
196 def __setitem__(self, index, val):
197 if index == 0: self.x = val
198 elif index == 1: self.y = val
199 else: raise IndexError
200"
7bf85405
RD
201};
202
203//---------------------------------------------------------------------------
204
205class wxRect {
206public:
eb715945
RD
207 wxRect(int x=0, int y=0, int w=0, int h=0);
208 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
209 ~wxRect();
7bf85405 210
eb715945
RD
211 int GetX();
212 void SetX(int X);
213 int GetY();
214 void SetY(int Y);
215 int GetWidth();
216 void SetWidth(int w);
217 int GetHeight();
218 void SetHeight(int h);
7bf85405
RD
219
220
eb715945
RD
221 wxPoint GetPosition();
222 wxSize GetSize();
3b5ccda1
RD
223 void SetPosition( const wxPoint &p );
224 void SetSize( const wxSize &s );
7bf85405 225
eb715945
RD
226 int GetLeft();
227 int GetTop();
228 int GetBottom();
229 int GetRight();
7bf85405 230
eb715945
RD
231 void SetLeft(int left);
232 void SetRight(int right);
233 void SetTop(int top);
234 void SetBottom(int bottom);
235
f6bcfd97
BP
236 void Inflate(int dx, int dy);
237 bool Inside(int cx, int cy);
eb715945
RD
238
239 int x, y, width, height;
af309447
RD
240
241 %addmethods {
242 PyObject* asTuple() {
7cdaed0b 243 wxPyBeginBlockThreads();
af309447
RD
244 PyObject* tup = PyTuple_New(4);
245 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
246 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
f0261a72
RD
247 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
248 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
7cdaed0b 249 wxPyEndBlockThreads();
af309447
RD
250 return tup;
251 }
f6bcfd97
BP
252
253 wxRect __add__(const wxRect* rect) {
254 if (! rect) return *self;
255 return *self + *rect;
256 }
257
258 int __cmp__(const wxRect* rect) {
419c299a
RD
259 if (! rect) return 1;
260 if (*self == *rect) return 0;
261 return -1;
f6bcfd97 262 }
af309447 263 }
f6bcfd97 264
9b3d3bc4 265 %pragma(python) addtoclass = "
1b62f00d
RD
266 def __str__(self): return str(self.asTuple())
267 def __repr__(self): return str(self.asTuple())
211a46cf 268 def __len__(self): return len(self.asTuple())
1b62f00d
RD
269 def __getitem__(self, index): return self.asTuple()[index]
270 def __setitem__(self, index, val):
271 if index == 0: self.x = val
272 elif index == 1: self.y = val
273 elif index == 2: self.width = val
274 elif index == 3: self.height = val
275 else: raise IndexError
276
9b3d3bc4
RD
277 # override the __getattr__ made by SWIG
278 def __getattr__(self, name):
279 d = {
280 'x' : miscc.wxRect_x_get,
281 'y' : miscc.wxRect_y_get,
282 'width' : miscc.wxRect_width_get,
283 'height' : miscc.wxRect_height_get,
284 'top' : miscc.wxRect_GetTop,
285 'bottom' : miscc.wxRect_GetBottom,
286 'left' : miscc.wxRect_GetLeft,
287 'right' : miscc.wxRect_GetRight,
288 }
289 try:
290 func = d[name]
291 except KeyError:
292 raise AttributeError,name
293 return func(self)
294
295 # and also the __setattr__
296 def __setattr__(self, name, value):
297 d = {
298 'x' : miscc.wxRect_x_set,
299 'y' : miscc.wxRect_y_set,
300 'width' : miscc.wxRect_width_set,
301 'height' : miscc.wxRect_height_set,
302 'top' : miscc.wxRect_SetTop,
303 'bottom' : miscc.wxRect_SetBottom,
304 'left' : miscc.wxRect_SetLeft,
305 'right' : miscc.wxRect_SetRight,
306 }
307 try:
308 func = d[name]
309 except KeyError:
310 self.__dict__[name] = value
311 return
312 func(self, value)
313 "
314
7bf85405
RD
315};
316
317
eb715945
RD
318%inline %{
319 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
320 wxRegion reg1(*r1);
321 wxRegion reg2(*r2);
322 wxRect dest(0,0,0,0);
323 PyObject* obj;
324
325 reg1.Intersect(reg2);
326 dest = reg1.GetBox();
327
328 if (dest != wxRect(0,0,0,0)) {
4268f798 329 wxPyBeginBlockThreads();
eb715945
RD
330 wxRect* newRect = new wxRect(dest);
331 obj = wxPyConstructObject((void*)newRect, "wxRect");
de20db99
RD
332 PyObject* one = PyInt_FromLong(1);
333 PyObject_SetAttrString(obj, "thisown", one);
334 Py_DECREF(one);
4268f798 335 wxPyEndBlockThreads();
eb715945
RD
336 return obj;
337 }
338 Py_INCREF(Py_None);
339 return Py_None;
340 }
341%}
7bf85405 342
7bf85405
RD
343
344//---------------------------------------------------------------------------
345// Miscellaneous functions
346
cf694132
RD
347long wxNewId();
348void wxRegisterId(long id);
349%name(NewId) long wxNewId();
350%name(RegisterId) void wxRegisterId(long id);
83b18bab 351long wxGetCurrentId();
cf694132 352
7bf85405 353void wxBell();
7bf85405 354void wxEndBusyCursor();
c368d904 355
7bf85405 356long wxGetElapsedTime(bool resetTimer = TRUE);
bc29c5e0 357#ifdef __WXMSW__
7bf85405 358long wxGetFreeMemory();
bc29c5e0 359#endif
7bf85405
RD
360void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
361bool wxIsBusy();
362wxString wxNow();
137b5242 363bool wxShell(const wxString& command = wxPyEmptyString);
7bf85405 364void wxStartTimer();
fb5e0af0 365int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
c368d904 366wxString wxGetOsDescription();
fb5e0af0 367
b7fc54be
RD
368enum wxShutdownFlags
369{
370 wxSHUTDOWN_POWEROFF, // power off the computer
371 wxSHUTDOWN_REBOOT // shutdown and reboot
372};
373
374// Shutdown or reboot the PC
375bool wxShutdown(wxShutdownFlags wFlags);
376
377
bb0054cd 378void wxSleep(int secs);
c368d904 379void wxUsleep(unsigned long milliseconds);
7bf85405 380bool wxYield();
83b18bab 381bool wxYieldIfNeeded();
bb0054cd 382void wxEnableTopLevelWindows(bool enable);
7bf85405 383
7bf85405 384%inline %{
c8bc7bb8 385 wxString wxGetResource(const wxString& section, const wxString& entry,
137b5242 386 const wxString& file = wxPyEmptyString) {
c8bc7bb8 387 wxChar * retval;
7bf85405
RD
388 wxGetResource(section, entry, &retval, file);
389 return retval;
390 }
391%}
392
694759cf 393wxString wxStripMenuCodes(const wxString& in);
7bf85405 394
c368d904
RD
395
396wxString wxGetEmailAddress();
397wxString wxGetHostName();
398wxString wxGetFullHostName();
399wxString wxGetUserId();
400wxString wxGetUserName();
401wxString wxGetHomeDir();
137b5242 402wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
c368d904 403
0815db26 404unsigned long wxGetProcessId();
f9bd2c1b
RD
405
406// When wxApp gets the virtual method magic then enable this.
407// bool wxHandleFatalExceptions(bool doIt = TRUE);
408
7bf85405
RD
409//----------------------------------------------------------------------
410
7bf85405
RD
411enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
412 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
413enum wxRelationship { wxUnconstrained = 0,
414 wxAsIs,
415 wxPercentOf,
416 wxAbove,
417 wxBelow,
418 wxLeftOf,
419 wxRightOf,
420 wxSameAs,
421 wxAbsolute };
422
423
9416aa89 424class wxIndividualLayoutConstraint : public wxObject {
7bf85405
RD
425public:
426// wxIndividualLayoutConstraint();
427// ~wxIndividualLayoutConstraint();
428
429 void Above(wxWindow *otherWin, int margin=0);
430 void Absolute(int value);
08127323 431 void AsIs();
7bf85405 432 void Below(wxWindow *otherWin, int margin=0);
08127323 433 void Unconstrained();
7bf85405
RD
434 void LeftOf(wxWindow *otherWin, int margin=0);
435 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
436 void RightOf(wxWindow *otherWin, int margin=0);
437 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
438 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
439};
440
441
9416aa89 442class wxLayoutConstraints : public wxObject {
7bf85405
RD
443public:
444 wxLayoutConstraints();
445
446%readonly
447 wxIndividualLayoutConstraint bottom;
448 wxIndividualLayoutConstraint centreX;
449 wxIndividualLayoutConstraint centreY;
450 wxIndividualLayoutConstraint height;
451 wxIndividualLayoutConstraint left;
452 wxIndividualLayoutConstraint right;
453 wxIndividualLayoutConstraint top;
454 wxIndividualLayoutConstraint width;
455%readwrite
456}
457
458
b639c3c5 459
7bf85405
RD
460//---------------------------------------------------------------------------
461// Accelerator Entry and Table
462
463class wxAcceleratorEntry {
464public:
465 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
2f90df85 466 ~wxAcceleratorEntry();
7bf85405
RD
467
468 void Set(int flags, int keyCode, int Cmd);
469 int GetFlags();
470 int GetKeyCode();
471 int GetCommand();
472};
473
474
9416aa89 475class wxAcceleratorTable : public wxObject {
7bf85405
RD
476public:
477 // Can also accept a list of 3-tuples
eec92d76 478 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
2f90df85 479 ~wxAcceleratorTable();
7bf85405
RD
480
481};
faf3cb35 482
c368d904 483wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
f6bcfd97
BP
484
485%readonly
486%{
487#if 0 // we want to use the definition from the header, not the
488 // one SWIG will generate.
489%}
490extern wxAcceleratorTable wxNullAcceleratorTable;
491%{
492#endif
493%}
494%readwrite
495
8bf5d46e 496//---------------------------------------------------------------------------
2abc0a0f 497
9416aa89 498class wxBusyInfo : public wxObject {
2abc0a0f
RD
499public:
500 wxBusyInfo(const wxString& message);
501 ~wxBusyInfo();
502};
503
68bc8549 504
8bf5d46e
RD
505//---------------------------------------------------------------------------
506
507
c368d904 508