Added a version save isinsnace function
Added wxPoint2DDouble git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18190 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1 +1 @@
|
||||
ver = '2.3.4p1'
|
||||
ver = '2.3.4p2'
|
||||
|
@@ -533,6 +533,17 @@ enum {
|
||||
wxMOUSE_BTN_MIDDLE,
|
||||
wxMOUSE_BTN_RIGHT,
|
||||
|
||||
// It looks like wxTabCtrl may rise from the dead. Uncomment these if
|
||||
// it gets an implementation for all platforms...
|
||||
// wxTC_RIGHTJUSTIFY,
|
||||
// wxTC_FIXEDWIDTH,
|
||||
// wxTC_TOP,
|
||||
// wxTC_LEFT,
|
||||
// wxTC_RIGHT,
|
||||
// wxTC_BOTTOM,
|
||||
// wxTC_MULTILINE,
|
||||
// wxTC_OWNERDRAW,
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@@ -587,7 +587,7 @@ wxColor = wxColour
|
||||
wxNamedColor = wxNamedColour
|
||||
wxPen = wxPyPen
|
||||
wxScrollbar = wxScrollBar
|
||||
|
||||
wxPoint2D = wxPoint2DDouble
|
||||
|
||||
# backwards compatibility
|
||||
wxNoRefBitmap = wxBitmap
|
||||
@@ -601,6 +601,7 @@ wxSystemSettings_GetSystemMetric = wxSystemSettings_GetMetric
|
||||
|
||||
wxPyAssertionError = wxc.wxPyAssertionError
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# wxGTK sets the locale when initialized. Doing this at the Python
|
||||
# level should set it up to match what GTK is doing at the C level.
|
||||
@@ -661,6 +662,18 @@ def wxPyTypeCast(obj, typeStr):
|
||||
theObj.thisown = obj.thisown
|
||||
return theObj
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# An isinstance for Pythons < 2.2 that can check a sequence of class objects
|
||||
# like the one in 2.2 can.
|
||||
|
||||
def wxPy_isinstance(obj, klasses):
|
||||
import types
|
||||
if sys.version[:3] < "2.2" and type(klasses) in [types.TupleType, types.ListType]:
|
||||
for klass in klasses:
|
||||
if isinstance(obj, klass): return true
|
||||
return false
|
||||
else:
|
||||
return isinstance(obj, klasses)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
_wxCallAfterId = None
|
||||
|
@@ -209,9 +209,9 @@ void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
|
||||
%pragma(python) code = "
|
||||
import types
|
||||
def wxMemoryFSHandler_AddFile(filename, a, b=''):
|
||||
if isinstance(a, wxImage):
|
||||
if wx.wxPy_isinstance(a, (wxImage, wxImagePtr)):
|
||||
__wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
|
||||
elif isinstance(a, wxBitmap):
|
||||
elif wx.wxPy_isinstance(a, (wxBitmap, wxBitmapPtr)):
|
||||
__wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
|
||||
elif type(a) == types.StringType:
|
||||
#__wxMemoryFSHandler_AddFile_wxString(filename, a)
|
||||
|
@@ -883,7 +883,7 @@ public:
|
||||
def DrawPointList(self, points, pens=None):
|
||||
if pens is None:
|
||||
pens = []
|
||||
elif isinstance(pens, wxPenPtr):
|
||||
elif wx.wxPy_isinstance(pens, (wxPen, wxPenPtr)):
|
||||
pens = [pens]
|
||||
elif len(pens) != len(points):
|
||||
raise ValueError('points and pens must have same length')
|
||||
@@ -892,7 +892,7 @@ public:
|
||||
def DrawLineList(self, lines, pens=None):
|
||||
if pens is None:
|
||||
pens = []
|
||||
elif isinstance(pens, wxPenPtr):
|
||||
elif wx.wxPy_isinstance(pens, (wxPen, wxPenPtr)):
|
||||
pens = [pens]
|
||||
elif len(pens) != len(lines):
|
||||
raise ValueError('lines and pens must have same length')
|
||||
|
@@ -1976,6 +1976,7 @@ bool wxSize_helper(PyObject* source, wxSize** obj) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
bool wxPoint_helper(PyObject* source, wxPoint** obj) {
|
||||
|
||||
// If source is an object instance then it may already be the right type
|
||||
@@ -2112,12 +2113,43 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
|
||||
|
||||
error:
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Expected a wxColour object or a string containing a colour "
|
||||
"name or '#RRGGBB'.");
|
||||
"Expected a wxColour object or a string containing a colour name or '#RRGGBB'.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxPoint2DDouble_helper(PyObject* source, wxPoint2DDouble** obj) {
|
||||
// If source is an object instance then it may already be the right type
|
||||
if (PyInstance_Check(source)) {
|
||||
wxPoint2DDouble* ptr;
|
||||
if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxPoint2DDouble_p"))
|
||||
goto error;
|
||||
*obj = ptr;
|
||||
return TRUE;
|
||||
}
|
||||
// otherwise a length-2 sequence of floats is expected
|
||||
if (PySequence_Check(source) && PySequence_Length(source) == 2) {
|
||||
PyObject* o1 = PySequence_GetItem(source, 0);
|
||||
PyObject* o2 = PySequence_GetItem(source, 1);
|
||||
// This should really check for integers, not numbers -- but that would break code.
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) {
|
||||
Py_DECREF(o1);
|
||||
Py_DECREF(o2);
|
||||
goto error;
|
||||
}
|
||||
**obj = wxPoint2DDouble(PyFloat_AsDouble(o1), PyFloat_AsDouble(o2));
|
||||
Py_DECREF(o1);
|
||||
Py_DECREF(o2);
|
||||
return TRUE;
|
||||
}
|
||||
error:
|
||||
PyErr_SetString(PyExc_TypeError, "Expected a 2-tuple of floats or a wxPoint2DDouble object.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
PyObject* wxArrayString2PyList_helper(const wxArrayString& arr) {
|
||||
|
@@ -14,7 +14,7 @@
|
||||
#define __wxp_helpers__
|
||||
|
||||
#include <wx/wx.h>
|
||||
|
||||
#include <wx/geometry.h>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -87,6 +87,9 @@ bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
|
||||
bool wxRect_helper(PyObject* source, wxRect** obj);
|
||||
bool wxColour_helper(PyObject* source, wxColour** obj);
|
||||
|
||||
bool wxPoint2DDouble_helper(PyObject* source, wxPoint2DDouble** obj);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Other helpful stuff
|
||||
|
||||
@@ -256,6 +259,7 @@ struct wxPyCoreAPI {
|
||||
bool (*p_wxRealPoint_helper)(PyObject* source, wxRealPoint** obj);
|
||||
bool (*p_wxRect_helper)(PyObject* source, wxRect** obj);
|
||||
bool (*p_wxColour_helper)(PyObject* source, wxColour** obj);
|
||||
bool (*p_wxPoint2DDouble_helper)(PyObject* source, wxPoint2DDouble** obj);
|
||||
|
||||
void (*p_wxPyCBH_setCallbackInfo)(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
|
||||
bool (*p_wxPyCBH_findCallback)(const wxPyCallbackHelper& cbh, const char* name);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include <wx/resource.h>
|
||||
#include <wx/tooltip.h>
|
||||
#include <wx/busyinfo.h>
|
||||
#include <wx/geometry.h>
|
||||
%}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@@ -79,12 +80,6 @@ public:
|
||||
return tup;
|
||||
}
|
||||
|
||||
int __cmp__(const wxSize* sz) {
|
||||
if (! sz) return 1;
|
||||
if (*self == *sz) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool __eq__(const wxSize& o) { return *self == o; }
|
||||
bool __ne__(const wxSize& o) { return *self != o; }
|
||||
}
|
||||
@@ -126,25 +121,18 @@ public:
|
||||
return tup;
|
||||
}
|
||||
|
||||
wxRealPoint __add__(const wxRealPoint* p) {
|
||||
if (! p) return *self;
|
||||
return *self + *p;
|
||||
wxRealPoint __add__(const wxRealPoint& p) {
|
||||
return *self + p;
|
||||
}
|
||||
|
||||
wxRealPoint __sub__(const wxRealPoint* p) {
|
||||
if (! p) return *self;
|
||||
return *self - *p;
|
||||
}
|
||||
|
||||
int __cmp__(const wxRealPoint* p) {
|
||||
if (! p) return 1;
|
||||
if (*self == *p) return 0;
|
||||
return -1;
|
||||
wxRealPoint __sub__(const wxRealPoint& p) {
|
||||
return *self - p;
|
||||
}
|
||||
|
||||
bool __eq__(const wxRealPoint& o) { return *self == o; }
|
||||
bool __ne__(const wxRealPoint& o) { return *self != o; }
|
||||
}
|
||||
|
||||
%pragma(python) addtoclass = "
|
||||
def __str__(self): return str(self.asTuple())
|
||||
def __repr__(self): return str(self.asTuple())
|
||||
@@ -180,25 +168,18 @@ public:
|
||||
return tup;
|
||||
}
|
||||
|
||||
wxPoint __add__(const wxPoint* p) {
|
||||
if (! p) return *self;
|
||||
return *self + *p;
|
||||
wxPoint __add__(const wxPoint& p) {
|
||||
return *self + p;
|
||||
}
|
||||
|
||||
wxPoint __sub__(const wxPoint* p) {
|
||||
if (! p) return *self;
|
||||
return *self - *p;
|
||||
}
|
||||
|
||||
int __cmp__(const wxPoint* p) {
|
||||
if (! p) return 1;
|
||||
if (*self == *p) return 0;
|
||||
return -1;
|
||||
wxPoint __sub__(const wxPoint& p) {
|
||||
return *self - p;
|
||||
}
|
||||
|
||||
bool __eq__(const wxPoint& o) { return *self == o; }
|
||||
bool __ne__(const wxPoint& o) { return *self != o; }
|
||||
}
|
||||
|
||||
%pragma(python) addtoclass = "
|
||||
def __str__(self): return str(self.asTuple())
|
||||
def __repr__(self): return str(self.asTuple())
|
||||
@@ -262,15 +243,8 @@ public:
|
||||
return tup;
|
||||
}
|
||||
|
||||
wxRect __add__(const wxRect* rect) {
|
||||
if (! rect) return *self;
|
||||
return *self + *rect;
|
||||
}
|
||||
|
||||
int __cmp__(const wxRect* rect) {
|
||||
if (! rect) return 1;
|
||||
if (*self == *rect) return 0;
|
||||
return -1;
|
||||
wxRect __add__(const wxRect& rect) {
|
||||
return *self + rect;
|
||||
}
|
||||
|
||||
bool __eq__(const wxRect& o) { return *self == o; }
|
||||
@@ -357,6 +331,88 @@ public:
|
||||
%}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxPoint2Ds represent a point or a vector in a 2d coordinate system
|
||||
|
||||
class wxPoint2DDouble
|
||||
{
|
||||
public:
|
||||
double m_x;
|
||||
double m_y;
|
||||
|
||||
%name(x)double m_x;
|
||||
%name(y)double m_y;
|
||||
|
||||
wxPoint2DDouble( double x=0 , double y=0 );
|
||||
%name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
|
||||
%name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
|
||||
|
||||
// two different conversions to integers, floor and rounding
|
||||
void GetFloor( int* OUTPUT , int* OUTPUT ) const;
|
||||
void GetRounded( int* OUTPUT , int* OUTPUT ) const;
|
||||
|
||||
double GetVectorLength() const;
|
||||
double GetVectorAngle() const ;
|
||||
void SetVectorLength( double length );
|
||||
void SetVectorAngle( double degrees );
|
||||
// LinkError: void SetPolarCoordinates( double angle , double length );
|
||||
// LinkError: void Normalize();
|
||||
%pragma(python) addtoclass = "
|
||||
def SetPolarCoordinates(self, angle, length):
|
||||
self.SetVectorLength(length)
|
||||
self.SetVectorAngle(angle)
|
||||
def Normalize(self):
|
||||
self.SetVectorLength(1.0)
|
||||
"
|
||||
|
||||
double GetDistance( const wxPoint2DDouble &pt ) const;
|
||||
double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
|
||||
double GetDotProduct( const wxPoint2DDouble &vec ) const;
|
||||
double GetCrossProduct( const wxPoint2DDouble &vec ) const;
|
||||
|
||||
%addmethods {
|
||||
// the reflection of this point
|
||||
wxPoint2DDouble __neg__() { return -(*self); }
|
||||
|
||||
wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
|
||||
wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
|
||||
wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
|
||||
wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
|
||||
|
||||
// TODO:
|
||||
//wxPoint2DDouble& operator*=(double n);
|
||||
//wxPoint2DDouble& operator*=(int n);
|
||||
//wxPoint2DDouble& operator/=(double n);
|
||||
//wxPoint2DDouble& operator/=(int n);
|
||||
|
||||
bool __eq__(const wxPoint2DDouble& pt) { return (*self) == pt; }
|
||||
bool __ne__(const wxPoint2DDouble& pt) { return (*self) != pt; }
|
||||
|
||||
PyObject* asTuple() {
|
||||
wxPyBeginBlockThreads();
|
||||
PyObject* tup = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
|
||||
PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
|
||||
wxPyEndBlockThreads();
|
||||
return tup;
|
||||
}
|
||||
}
|
||||
|
||||
%pragma(python) addtoclass = "
|
||||
def __str__(self): return str(self.asTuple())
|
||||
def __repr__(self): return str(self.asTuple())
|
||||
def __len__(self): return len(self.asTuple())
|
||||
def __getitem__(self, index): return self.asTuple()[index]
|
||||
def __setitem__(self, index, val):
|
||||
if index == 0: self.m_x = val
|
||||
elif index == 1: self.m_yt = val
|
||||
else: raise IndexError
|
||||
def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
|
||||
"
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Miscellaneous functions
|
||||
|
||||
|
@@ -244,6 +244,12 @@ $function
|
||||
return NULL;
|
||||
}
|
||||
|
||||
%typemap(python,in) wxPoint2DDouble& (wxPoint2DDouble temp) {
|
||||
$target = &temp;
|
||||
if (! wxPoint2DDouble_helper($source, &$target))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Typemap to convert strings to wxColour. Two string formats are accepted,
|
||||
// either a colour name, or a hex colour spec like "#RRGGBB"
|
||||
|
@@ -207,6 +207,7 @@ static wxPyCoreAPI API = {
|
||||
wxRealPoint_helper,
|
||||
wxRect_helper,
|
||||
wxColour_helper,
|
||||
wxPoint2DDouble_helper,
|
||||
|
||||
wxPyCBH_setCallbackInfo,
|
||||
wxPyCBH_findCallback,
|
||||
|
@@ -71,6 +71,7 @@ static void wxPyCoreAPI_IMPORT() {
|
||||
#define wxRealPoint_helper(a,b) (wxPyCoreAPIPtr->p_wxRealPoint_helper(a,b))
|
||||
#define wxRect_helper(a,b) (wxPyCoreAPIPtr->p_wxRect_helper(a,b))
|
||||
#define wxColour_helper(a,b) (wxPyCoreAPIPtr->p_wxColour_helper(a,b))
|
||||
#define wxPoint2DDouble_helper(a,b) (wxPyCoreAPIPtr->p_wxPoint2DDouble_helper(a,b))
|
||||
|
||||
#define wxPyCBH_setCallbackInfo(a, b, c, d) (wxPyCoreAPIPtr->p_wxPyCBH_setCallbackInfo(a,b,c,d))
|
||||
#define wxPyCBH_findCallback(a, b) (wxPyCoreAPIPtr->p_wxPyCBH_findCallback(a, b))
|
||||
|
Reference in New Issue
Block a user