WxPython: wx.ListItem output, but wx.ListCtrl returns only the old class

I have a little problem with derived classes, namely wx.ListItemwith wx.ListCtrl. I successfully got wx.ListItemhow MediaItem, the code is not finished, but you get the point:

class MediaItem(wx.ListItem):
    def __init__ (self, fullname):
        wx.ListItem.__init__(self)
        self.fullname = fullname
        self.filename = os.path.basename(fullname)
        # snap...

    def getFullname(self):
        return self.fullname

wx.ListCtrlgladly accepts this because of the Pythons duck philosophy. But now the problem is that using the method wx.ListCtrl.GetItem(index)returns a ListItem, not MediaItem. Python complained about wx.ListItemhaving no attribute getFullname.

Casting objects seems to be the wrong approach to solving. This probably has nothing to do with the problem, but I also insert the violation line:

filename = self.filelist.GetItem(event.GetIndex()).getFullname()

Where self.filelistthere is wx.ListCtrl.

+3
1

, . , , wxPython.

( , ) - wxPython. Python, ++, . - : ++ wx , wx.ListItem, wx.ListItem wxPython.

"", , wx.ListCtrl wx.ListItem, .

+2

Source: https://habr.com/ru/post/1752516/


All Articles