diff --git a/etg/colour.py b/etg/colour.py index d5be436b..10d0a455 100644 --- a/etg/colour.py +++ b/etg/colour.py @@ -196,7 +196,7 @@ 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; @@ -212,6 +212,7 @@ def run(): } return 0; } + // otherwise do the conversion // is it None? if (sipPy == Py_None) { diff --git a/etg/gdicmn.py b/etg/gdicmn.py index 48ad903e..00c8e63e 100644 --- a/etg/gdicmn.py +++ b/etg/gdicmn.py @@ -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); """)) diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index d4797ab5..ed83f6f9 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -626,7 +626,7 @@ 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); @@ -666,7 +666,7 @@ 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); @@ -713,7 +713,7 @@ 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); @@ -753,7 +753,7 @@ 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); diff --git a/unittests/test_colour.py b/unittests/test_colour.py index 5ad7bd87..9a7995da 100644 --- a/unittests/test_colour.py +++ b/unittests/test_colour.py @@ -34,6 +34,14 @@ class Colour(wtc.WidgetTestCase): c1 = wx.Colour(1,2,3,4) p = c1.GetPixel() + def test_converters(self): + # Ensure that comparing different types don't accidentally work + # because of making the classes look like sequences + c = wx.Colour(1,2,3,4) + r = wx.Rect(1,2,3,4) + self.assertFalse( c == r ) + self.assertFalse( r == c ) + if hasattr(wx, 'testColourTypeMap'): def test_ColourTypemaps(self): diff --git a/unittests/test_gdicmn.py b/unittests/test_gdicmn.py index 71847797..daa3eaf7 100644 --- a/unittests/test_gdicmn.py +++ b/unittests/test_gdicmn.py @@ -117,6 +117,14 @@ class Point(unittest.TestCase): self.assertEqual(p6, (-4,-6)) + def test_converters(self): + # Ensure that comparing different types don't accidentally work + # because of making the classes look like sequences + p = wx.Point(10,20) + s = wx.Size(10,20) + self.assertFalse( p == s ) + self.assertFalse( s == p ) + #---------------------------------------------------------------------------