1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Definitions of miscelaneous functions and classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include <wx/resource.h>
18 #include <wx/tooltip.h>
19 #include <wx/busyinfo.h>
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
32 static wxString wxPyEmptyStr("");
35 //---------------------------------------------------------------------------
42 const char* GetClassName() {
43 return self->GetClassInfo()->GetClassName();
52 //---------------------------------------------------------------------------
61 wxSize(long w=0, long h=0);
63 void Set(long w, long h);
68 void SetWidth(long w);
69 void SetHeight(long h);
73 PyObject* tup = PyTuple_New(2);
74 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
75 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
79 int __cmp__(const wxSize* sz) {
81 if (*self == *sz) return 0;
86 %pragma(python) addtoclass = "
87 def __str__(self): return str(self.asTuple())
88 def __repr__(self): return str(self.asTuple())
89 def __len__(self): return len(self.asTuple())
90 def __getitem__(self, index): return self.asTuple()[index]
91 def __setitem__(self, index, val):
92 if index == 0: self.width = val
93 elif index == 1: self.height = val
94 else: raise IndexError
99 //---------------------------------------------------------------------------
105 wxRealPoint(double x=0.0, double y=0.0);
109 void Set(double x, double y) {
113 PyObject* asTuple() {
114 PyObject* tup = PyTuple_New(2);
115 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
116 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
120 wxRealPoint __add__(const wxRealPoint* p) {
121 if (! p) return *self;
125 wxRealPoint __sub__(const wxRealPoint* p) {
126 if (! p) return *self;
130 int __cmp__(const wxRealPoint* p) {
132 if (*self == *p) return 0;
136 %pragma(python) addtoclass = "
137 def __str__(self): return str(self.asTuple())
138 def __repr__(self): return str(self.asTuple())
139 def __len__(self): return len(self.asTuple())
140 def __getitem__(self, index): return self.asTuple()[index]
141 def __setitem__(self, index, val):
142 if index == 0: self.width = val
143 elif index == 1: self.height = val
144 else: raise IndexError
153 wxPoint(long x=0, long y=0);
157 void Set(long x, long y) {
161 PyObject* asTuple() {
162 PyObject* tup = PyTuple_New(2);
163 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
164 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
168 wxPoint __add__(const wxPoint* p) {
169 if (! p) return *self;
173 wxPoint __sub__(const wxPoint* p) {
174 if (! p) return *self;
178 int __cmp__(const wxPoint* p) {
180 if (*self == *p) return 0;
184 %pragma(python) addtoclass = "
185 def __str__(self): return str(self.asTuple())
186 def __repr__(self): return str(self.asTuple())
187 def __len__(self): return len(self.asTuple())
188 def __getitem__(self, index): return self.asTuple()[index]
189 def __setitem__(self, index, val):
190 if index == 0: self.x = val
191 elif index == 1: self.y = val
192 else: raise IndexError
196 //---------------------------------------------------------------------------
200 wxRect(int x=0, int y=0, int w=0, int h=0);
201 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
209 void SetWidth(int w);
211 void SetHeight(int h);
214 wxPoint GetPosition();
222 void SetLeft(int left);
223 void SetRight(int right);
224 void SetTop(int top);
225 void SetBottom(int bottom);
227 void Inflate(int dx, int dy);
228 bool Inside(int cx, int cy);
230 int x, y, width, height;
233 PyObject* asTuple() {
234 PyObject* tup = PyTuple_New(4);
235 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
236 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
237 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
238 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
242 wxRect __add__(const wxRect* rect) {
243 if (! rect) return *self;
244 return *self + *rect;
247 int __cmp__(const wxRect* rect) {
248 if (! rect) return 1;
249 if (*self == *rect) return 0;
254 %pragma(python) addtoclass = "
255 def __str__(self): return str(self.asTuple())
256 def __repr__(self): return str(self.asTuple())
257 def __len__(self): return len(self.asTuple())
258 def __getitem__(self, index): return self.asTuple()[index]
259 def __setitem__(self, index, val):
260 if index == 0: self.x = val
261 elif index == 1: self.y = val
262 elif index == 2: self.width = val
263 elif index == 3: self.height = val
264 else: raise IndexError
266 # override the __getattr__ made by SWIG
267 def __getattr__(self, name):
269 'x' : miscc.wxRect_x_get,
270 'y' : miscc.wxRect_y_get,
271 'width' : miscc.wxRect_width_get,
272 'height' : miscc.wxRect_height_get,
273 'top' : miscc.wxRect_GetTop,
274 'bottom' : miscc.wxRect_GetBottom,
275 'left' : miscc.wxRect_GetLeft,
276 'right' : miscc.wxRect_GetRight,
281 raise AttributeError,name
284 # and also the __setattr__
285 def __setattr__(self, name, value):
287 'x' : miscc.wxRect_x_set,
288 'y' : miscc.wxRect_y_set,
289 'width' : miscc.wxRect_width_set,
290 'height' : miscc.wxRect_height_set,
291 'top' : miscc.wxRect_SetTop,
292 'bottom' : miscc.wxRect_SetBottom,
293 'left' : miscc.wxRect_SetLeft,
294 'right' : miscc.wxRect_SetRight,
299 self.__dict__[name] = value
308 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
311 wxRect dest(0,0,0,0);
314 reg1.Intersect(reg2);
315 dest = reg1.GetBox();
317 if (dest != wxRect(0,0,0,0)) {
318 wxPyTState* state = wxPyBeginBlockThreads();
319 wxRect* newRect = new wxRect(dest);
320 obj = wxPyConstructObject((void*)newRect, "wxRect");
321 PyObject* one = PyInt_FromLong(1);
322 PyObject_SetAttrString(obj, "thisown", one);
324 wxPyEndBlockThreads(state);
333 //---------------------------------------------------------------------------
334 // Miscellaneous functions
337 void wxRegisterId(long id);
338 %name(NewId) long wxNewId();
339 %name(RegisterId) void wxRegisterId(long id);
340 long wxGetCurrentId();
343 void wxEndBusyCursor();
345 long wxGetElapsedTime(bool resetTimer = TRUE);
347 long wxGetFreeMemory();
349 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
352 bool wxShell(const wxString& command = wxPyEmptyStr);
354 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
355 wxString wxGetOsDescription();
357 void wxSleep(int secs);
358 void wxUsleep(unsigned long milliseconds);
360 bool wxYieldIfNeeded();
361 void wxEnableTopLevelWindows(bool enable);
364 char* wxGetResource(char *section, char *entry, char *file = NULL) {
366 wxGetResource(section, entry, &retval, file);
371 wxString wxStripMenuCodes(const wxString& in);
374 wxString wxGetEmailAddress();
375 wxString wxGetHostName();
376 wxString wxGetFullHostName();
377 wxString wxGetUserId();
378 wxString wxGetUserName();
379 wxString wxGetHomeDir();
382 //----------------------------------------------------------------------
384 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
385 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
386 enum wxRelationship { wxUnconstrained = 0,
397 class wxIndividualLayoutConstraint : public wxObject {
399 // wxIndividualLayoutConstraint();
400 // ~wxIndividualLayoutConstraint();
402 void Above(wxWindow *otherWin, int margin=0);
403 void Absolute(int value);
405 void Below(wxWindow *otherWin, int margin=0);
406 void Unconstrained();
407 void LeftOf(wxWindow *otherWin, int margin=0);
408 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
409 void RightOf(wxWindow *otherWin, int margin=0);
410 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
411 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
415 class wxLayoutConstraints : public wxObject {
417 wxLayoutConstraints();
420 wxIndividualLayoutConstraint bottom;
421 wxIndividualLayoutConstraint centreX;
422 wxIndividualLayoutConstraint centreY;
423 wxIndividualLayoutConstraint height;
424 wxIndividualLayoutConstraint left;
425 wxIndividualLayoutConstraint right;
426 wxIndividualLayoutConstraint top;
427 wxIndividualLayoutConstraint width;
433 //---------------------------------------------------------------------------
434 // Accelerator Entry and Table
436 class wxAcceleratorEntry {
438 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
439 ~wxAcceleratorEntry();
441 void Set(int flags, int keyCode, int Cmd);
448 class wxAcceleratorTable : public wxObject {
450 // Can also accept a list of 3-tuples
451 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
452 ~wxAcceleratorTable();
456 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
460 #if 0 // we want to use the definition from the header, not the
461 // one SWIG will generate.
463 extern wxAcceleratorTable wxNullAcceleratorTable;
469 //---------------------------------------------------------------------------
471 class wxBusyInfo : public wxObject {
473 wxBusyInfo(const wxString& message);
477 //---------------------------------------------------------------------------