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