Merge branch 'master' into release-prep

This commit is contained in:
Robin Dunn
2017-04-13 20:51:26 -07:00
7 changed files with 69 additions and 64 deletions

View File

@@ -196,15 +196,14 @@ def run():
return 1;
if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy))
return 1;
if (PySequence_Check(sipPy)) {
if (PyTuple_Check(sipPy) || PyList_Check(sipPy)) {
size_t len = PySequence_Size(sipPy);
if (len != 3 && len != 4)
return 0;
// ensure all the items in the sequence are numbers
for (int idx=0; idx<len; idx+=1) {
PyObject* o = PySequence_ITEM(sipPy, idx);
PyObject* o = PySequence_Fast_GET_ITEM(sipPy, idx);
bool isNum = PyNumber_Check(o);
Py_DECREF(o);
if (!isNum)
return 0;
}
@@ -212,6 +211,7 @@ def run():
}
return 0;
}
// otherwise do the conversion
// is it None?
if (sipPy == Py_None) {
@@ -254,23 +254,19 @@ def run():
}
}
// Is it a 3 or 4 element sequence?
else if (PySequence_Check(sipPy)) {
size_t len = PyObject_Length(sipPy);
else if (PyTuple_Check(sipPy) || PyList_Check(sipPy)) {
size_t len = PySequence_Size(sipPy);
PyObject* o1 = PySequence_GetItem(sipPy, 0);
PyObject* o2 = PySequence_GetItem(sipPy, 1);
PyObject* o3 = PySequence_GetItem(sipPy, 2);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
PyObject* o3 = PySequence_Fast_GET_ITEM(sipPy, 2);
if (len == 3)
*sipCppPtr = new wxColour(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2), wxPyInt_AsLong(o3));
else {
PyObject* o4 = PySequence_GetItem(sipPy, 3);
PyObject* o4 = PySequence_Fast_GET_ITEM(sipPy, 3);
*sipCppPtr = new wxColour(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2), wxPyInt_AsLong(o3),
wxPyInt_AsLong(o4));
Py_DECREF(o4);
}
Py_DECREF(o1);
Py_DECREF(o2);
Py_DECREF(o3);
return sipGetState(sipTransferObj);
}

View File

@@ -91,8 +91,10 @@ def run():
c.addItem(etgtools.WigCode("""\
wxPoint operator+(const wxPoint& other);
wxPoint operator+(const wxSize& other);
wxPoint operator-();
wxPoint operator-(const wxPoint& other);
wxPoint operator-(const wxSize& other);
wxPoint operator*(int i);
wxPoint operator/(int i);
"""))

View File

@@ -626,14 +626,12 @@ def convertTwoIntegersTemplate(CLASS):
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
return 1;
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 2) {{
if ((PyTuple_Check(sipPy) || PyList_Check(sipPy)) && PySequence_Size(sipPy) == 2) {{
int rval = 1;
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
if (!PyNumber_Check(o1) || !PyNumber_Check(o2))
rval = 0;
Py_DECREF(o1);
Py_DECREF(o2);
return rval;
}}
return 0;
@@ -648,11 +646,9 @@ def convertTwoIntegersTemplate(CLASS):
}}
// or create a new instance
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
*sipCppPtr = new {CLASS}(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2));
Py_DECREF(o1);
Py_DECREF(o2);
return SIP_TEMPORARY;
""".format(**locals())
@@ -666,18 +662,14 @@ def convertFourIntegersTemplate(CLASS):
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
return 1;
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 4) {{
if ((PyTuple_Check(sipPy) || PyList_Check(sipPy)) && PySequence_Size(sipPy) == 4) {{
int rval = 1;
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o3 = PySequence_ITEM(sipPy, 2);
PyObject* o4 = PySequence_ITEM(sipPy, 3);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
PyObject* o3 = PySequence_Fast_GET_ITEM(sipPy, 2);
PyObject* o4 = PySequence_Fast_GET_ITEM(sipPy, 3);
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4))
rval = 0;
Py_DECREF(o1);
Py_DECREF(o2);
Py_DECREF(o3);
Py_DECREF(o4);
return rval;
}}
return 0;
@@ -691,14 +683,12 @@ def convertFourIntegersTemplate(CLASS):
return 0; // not a new instance
}}
// or create a new instance
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o3 = PySequence_ITEM(sipPy, 2);
PyObject* o4 = PySequence_ITEM(sipPy, 3);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
PyObject* o3 = PySequence_Fast_GET_ITEM(sipPy, 2);
PyObject* o4 = PySequence_Fast_GET_ITEM(sipPy, 3);
*sipCppPtr = new {CLASS}(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2),
wxPyInt_AsLong(o3), wxPyInt_AsLong(o4));
Py_DECREF(o1);
Py_DECREF(o2);
return SIP_TEMPORARY;
""".format(**locals())
@@ -713,14 +703,12 @@ def convertTwoDoublesTemplate(CLASS):
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
return 1;
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 2) {{
if ((PyTuple_Check(sipPy) || PyList_Check(sipPy)) && PySequence_Size(sipPy) == 2) {{
int rval = 1;
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
if (!PyNumber_Check(o1) || !PyNumber_Check(o2))
rval = 0;
Py_DECREF(o1);
Py_DECREF(o2);
return rval;
}}
return 0;
@@ -735,11 +723,9 @@ def convertTwoDoublesTemplate(CLASS):
}}
// or create a new instance
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
*sipCppPtr = new {CLASS}(PyFloat_AsDouble(o1), PyFloat_AsDouble(o2));
Py_DECREF(o1);
Py_DECREF(o2);
return SIP_TEMPORARY;
""".format(**locals())
@@ -753,18 +739,14 @@ def convertFourDoublesTemplate(CLASS):
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
return 1;
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 4) {{
if ((PyTuple_Check(sipPy) || PyList_Check(sipPy)) && PySequence_Size(sipPy) == 4) {{
int rval = 1;
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o3 = PySequence_ITEM(sipPy, 2);
PyObject* o4 = PySequence_ITEM(sipPy, 3);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
PyObject* o3 = PySequence_Fast_GET_ITEM(sipPy, 2);
PyObject* o4 = PySequence_Fast_GET_ITEM(sipPy, 3);
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4))
rval = 0;
Py_DECREF(o1);
Py_DECREF(o2);
Py_DECREF(o3);
Py_DECREF(o4);
return rval;
}}
return 0;
@@ -779,14 +761,12 @@ def convertFourDoublesTemplate(CLASS):
}}
// or create a new instance
PyObject* o1 = PySequence_ITEM(sipPy, 0);
PyObject* o2 = PySequence_ITEM(sipPy, 1);
PyObject* o3 = PySequence_ITEM(sipPy, 2);
PyObject* o4 = PySequence_ITEM(sipPy, 3);
PyObject* o1 = PySequence_Fast_GET_ITEM(sipPy, 0);
PyObject* o2 = PySequence_Fast_GET_ITEM(sipPy, 1);
PyObject* o3 = PySequence_Fast_GET_ITEM(sipPy, 2);
PyObject* o4 = PySequence_Fast_GET_ITEM(sipPy, 3);
*sipCppPtr = new {CLASS}(PyFloat_AsDouble(o1), PyFloat_AsDouble(o2),
PyFloat_AsDouble(o3), PyFloat_AsDouble(o4));
Py_DECREF(o1);
Py_DECREF(o2);
PyFloat_AsDouble(o3), PyFloat_AsDouble(o4));
return SIP_TEMPORARY;
""".format(**locals())

View File

@@ -174,6 +174,7 @@ static void i_wxPyEndBlockThreads(wxPyBlock_t blocked)
//--------------------------------------------------------------------------
// Commonly used helpers for converting small sequences of numbers
// TODO: Are these still needed?
// A helper for converting a 2 element sequence to a pair of integers
static bool i_wxPy2int_seq_helper(PyObject* source, int* i1, int* i2)

View File

@@ -35,6 +35,13 @@ class Colour(wtc.WidgetTestCase):
p = c1.GetPixel()
def test_converters(self):
# Ensure that other types that are sequence-like can't be
# auto-converted, the copy constructor is good-enough for testing this
with self.assertRaises(TypeError):
p = wx.Colour(wx.Rect(1,2,3,4))
if hasattr(wx, 'testColourTypeMap'):
def test_ColourTypemaps(self):
c = wx.testColourTypeMap('red')

View File

@@ -117,6 +117,12 @@ class Point(unittest.TestCase):
self.assertEqual(p6, (-4,-6))
def test_converters(self):
# Ensure that other types that are sequence-like can't be
# auto-converted, the copy constructor is good-enough for testing this
with self.assertRaises(TypeError):
p = wx.Point(wx.Size(10,20))
#---------------------------------------------------------------------------
@@ -235,6 +241,13 @@ class Size(unittest.TestCase):
s[2]
def test_converters(self):
# Ensure that other types that are sequence-like can't be
# auto-converted, the copy constructor is good-enough for testing this
with self.assertRaises(TypeError):
p = wx.Size(wx.Point(10,20))
#---------------------------------------------------------------------------
@@ -299,6 +312,12 @@ class Rect(unittest.TestCase):
self.assertTrue(r.x == 0 and r.y == 0)
def test_converters(self):
# Ensure that other types that are sequence-like can't be
# auto-converted, the copy constructor is good-enough for testing this
with self.assertRaises(TypeError):
p = wx.Rect(wx.Colour(1,2,3,4))
# TODO: more tests!

View File

@@ -2138,7 +2138,7 @@ class ScaledBitmap(TextObjectMixin, DrawObject):
self.XY = XY
self.Height = Height
(self.bmpWidth, self.bmpHeight) = self.Image.GetWidth(), self.Image.GetHeight()
(self.bmpWidth, self.bmpHeight) = float(self.Image.GetWidth()), float(self.Image.GetHeight())
self.Width = self.bmpWidth / self.bmpHeight * Height
self.ShiftFun = self.ShiftFunDict[Position]
self.CalcBoundingBox()
@@ -2225,7 +2225,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ):
self.XY = N.array(XY, N.float)
self.Height = Height
(self.bmpWidth, self.bmpHeight) = self.Image.GetWidth(), self.Image.GetHeight()
(self.bmpWidth, self.bmpHeight) = float(self.Image.GetWidth()), float(self.Image.GetHeight())
self.bmpWH = N.array((self.bmpWidth, self.bmpHeight), N.int32)
## fixme: this should all accommodate different scales for X and Y
if Width is None: