DataViewListCtrl: how to use AppendIconTextColumn

565 views
Skip to first unread message

dario...@gmail.com

unread,
Mar 2, 2014, 7:56:20 AM3/2/14
to wxpytho...@googlegroups.com
I'm sorry but I haven't been able to find any examples for using AppendIconTextColumn in a DataViewListCtrl: how should I modify the following script in order to make the icon created with List.make_icon appear next to the 'Test' item?

####################################################
import wx
import wx.dataview


class List(wx.dataview.DataViewListCtrl):
    def __init__(self, parent):
        super(List, self).__init__(parent)
        imagelist = wx.ImageList(16, 16)
        imagelist.Add(self.make_icon())
        self.AppendIconTextColumn('Test', 0)
        self.AppendItem(('Test', ))

    def make_icon(self):
        bitmap = wx.EmptyBitmap(16, 16)
        dc = wx.MemoryDC()
        dc.SelectObject(bitmap)
        dc.SetBackground(wx.RED_BRUSH)
        dc.Clear()
        dc.SelectObject(wx.NullBitmap)
        return bitmap


app = wx.App()
frame = wx.Frame(None)
List(frame)
frame.Centre()
frame.Show()
app.MainLoop()
####################################################

Robin Dunn

unread,
Mar 15, 2014, 12:49:50 AM3/15/14
to wxpytho...@googlegroups.com
dario...@gmail.com wrote:
> I'm sorry but I haven't been able to find any examples for using
> AppendIconTextColumn in a DataViewListCtrl: how should I modify the
> following script in order to make the icon created with List.make_icon
> appear next to the 'Test' item?

Instead of using a plain string in the data for the row, try using a
wx.dataview.DataViewIconText. Like this:

self.AppendItem( (wx.dataview.DataViewIconText('Text', icon),) )


--
Robin Dunn
Software Craftsman
http://wxPython.org

Dario Giovannetti

unread,
Mar 16, 2014, 7:04:04 PM3/16/14
to wxpytho...@googlegroups.com
On 15/03/14 12:49, Robin Dunn wrote:
> dario...@gmail.com wrote:
>> I'm sorry but I haven't been able to find any examples for using
>> AppendIconTextColumn in a DataViewListCtrl: how should I modify the
>> following script in order to make the icon created with List.make_icon
>> appear next to the 'Test' item?
>
> Instead of using a plain string in the data for the row, try using a
> wx.dataview.DataViewIconText. Like this:
>
> self.AppendItem( (wx.dataview.DataViewIconText('Text', icon),) )
>
>
Uh now I get it, that does work indeed, thank you!
Reply all
Reply to author
Forward
0 new messages