Adjust all the custom wx.MenuItem methods. Return new instances, mark them as factories, etc.

This commit is contained in:
Robin Dunn
2022-05-17 17:20:59 -07:00
parent d37686d201
commit 323129f449
2 changed files with 23 additions and 17 deletions

View File

@@ -47,13 +47,16 @@ def run():
c.find('GetLabelFromText').ignore()
# These are MSW only. Make them be empty stubs for the other ports
c.find('GetBackgroundColour').type = 'const wxColour*'
# These are MSW only. Make them be empty stubs for the other ports. Several
# have incorrect details in the interface docs, so we need to tweak their
# return types too.
c.find('GetBackgroundColour').type = 'wxColour*'
c.find('GetBackgroundColour').factory = True
c.find('GetBackgroundColour').setCppCode("""\
#ifdef __WXMSW__
return &self->GetBackgroundColour();
return new wxColor(self->GetBackgroundColour());
#else
return &wxNullColour;
return new wxColour;
#endif
""")
@@ -63,12 +66,13 @@ def run():
#endif
""")
c.find('GetFont').type = 'const wxFont*'
c.find('GetFont').type = 'wxFont*'
c.find('GetFont').factory = True
c.find('GetFont').setCppCode("""\
#ifdef __WXMSW__
return &self->GetFont();
return new wxFont(self->GetFont());
#else
return &wxNullFont;
return new wxFont;
#endif
""")
@@ -92,12 +96,13 @@ def run():
#endif
""")
c.find('GetTextColour').type = 'const wxColour*'
c.find('GetTextColour').type = 'wxColour*'
c.find('GetTextColour').factory = True
c.find('GetTextColour').setCppCode("""\
#ifdef __WXMSW__
return &self->GetTextColour();
return new wxColour(self->GetTextColour());
#else
return &wxNullColour;
return new wxColour;
#endif
""")
@@ -108,13 +113,13 @@ def run():
""")
c.find('GetBitmap').type = 'const wxBitmap*'
c.find('GetBitmap').transferBack = True
c.find('GetBitmap').type = 'wxBitmap*'
c.find('GetBitmap').factory = True
c.find('GetBitmap').setCppCode("""\
#ifdef __WXMSW__
return new wxBitmap(self->GetBitmap(checked));
#else
return new wxBitmap(self->GetBitmap());
return new wxBitmap(self->GetBitmap()); // no checked arg in this case
#endif
""")
@@ -135,13 +140,13 @@ def run():
""")
c.find('GetDisabledBitmap').type = 'const wxBitmap*'
c.find('GetDisabledBitmap').transferBack = True # Python takes ownership of the return value
c.find('GetDisabledBitmap').type = 'wxBitmap*'
c.find('GetDisabledBitmap').factory = True
c.find('GetDisabledBitmap').setCppCode("""\
#ifdef __WXMSW__
return new wxBitmap(self->GetDisabledBitmap());
#else
return new wxBitmap(wxNullBitmap);
return new wxBitmap;
#endif
""")
@@ -151,6 +156,7 @@ def run():
#endif
""")
c.addAutoProperties()
c.addItem(etgtools.PropertyDef('Enabled', 'IsEnabled', 'Enable'))

View File

@@ -12,7 +12,7 @@ class menuitem_Tests(wtc.WidgetTestCase):
def test_menuitemCtor(self):
m1 = wx.MenuItem()
m2 = wx.MenuItem(None, -1, "Menu Item", "Help text", wx.ITEM_NORMAL)
m2.SetBitmap(wx.Bitmap(pngFile))
m2.SetBitmap(wx.BitmapBundle(wx.Bitmap(pngFile)))
def test_menuitemProperties(self):