diff --git a/etg/mimetype.py b/etg/mimetype.py index f87331c6..db3c5af7 100644 --- a/etg/mimetype.py +++ b/etg/mimetype.py @@ -142,6 +142,33 @@ def run(): c.find('GetAllCommands.verbs').out = True c.find('GetAllCommands.commands').out = True + c.addCppMethod('PyObject*', 'GetIconInfo', '()', + doc="""\ + Returns a tuple containing the Icon for this file type, the file where the + icon is found, and the index of the image in that file, if applicable. + """, + body="""\ + wxIconLocation loc; + if (self->GetIcon(&loc)) { + wxString iconFile = loc.GetFileName(); + int iconIndex = -1; + #ifdef __WXMSW__ + iconIndex = loc.GetIndex(); + #endif + // Make a tuple and put the values in it + wxPyThreadBlocker blocker; + PyObject* tuple = PyTuple_New(3); + PyTuple_SetItem(tuple, 0, + wxPyConstructObject(new wxIcon(loc), wxT("wxIcon"), true)); + PyTuple_SetItem(tuple, 1, wx2PyString(iconFile)); + PyTuple_SetItem(tuple, 2, wxPyInt_FromLong(iconIndex)); + return tuple; + } + else + RETURN_NONE(); + """) + + #----------------------------------------------------------------- c = module.find('wxFileTypeInfo') diff --git a/unittests/test_mimetype.py b/unittests/test_mimetype.py index d56d994c..a4cd13fd 100644 --- a/unittests/test_mimetype.py +++ b/unittests/test_mimetype.py @@ -39,7 +39,17 @@ class mimetype_Tests(wtc.WidgetTestCase): self.assertEqual(fti.GetDescription(), 'desc') self.assertEqual(fti.GetExtensions(), ['ext1', 'ext2', 'ext3']) self.assertEqual(fti.GetExtensionsCount(), 3) - + + def test_mimetype5(self): + ft = wx.TheMimeTypesManager.GetFileTypeFromMimeType('image/png') + if ft: + info = ft.GetIconInfo() + if info is not None: + self.assertTrue(isinstance(info, tuple)) + self.assertTrue(len(info) == 3) + self.assertTrue(isinstance(info[0], wx.Icon)) + + #--------------------------------------------------------------------------- if __name__ == '__main__':