views:

51

answers:

2

Is there a wxpython list widget that displays alternating row colours even when empty the list is empty? or Is there even one that will display a background colour(other than white) when it is empty?

+1  A: 

You could do it with a wx.Grid or you might look at the new UltimateListCtrl, which is a pure python widget. You can hack it if it doesn't do what you want it to!

Mike Driscoll
Never thought of using a grid, good idea , however I think a grid would be alot of work especially compared to the OLV and probably the ULC too (using OLVs has spoilt me :). I was already pondering over using a ULC but I couldn't figure out if it offered what I was looking for but I think Ill give it a go given its hackable nature hopefully I can achieve what I want. Thanks
volting
+1  A: 

Indeed. Create your list as a custom class:

import wx.lib.mixins.listctrl as listmix

class CustomList(wx.ListCtrl, listmix.ListRowHighlighter):

    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent)
        listmix.ListRowHighlighter.__init__(self, (206, 218, 255))

See: http://www.wxpython.org/docs/api/wx.lib.mixins.listctrl.ListRowHighlighter-class.html

Steven Sproat
From wxpython doc: "The background of the rows are highlighted automatically as items are added" Are you sure solution will work even when the list is empty? I just tried it out and it didnt... Thanks
volting
Guess not but you could always swap the foreground and background colours to give that appearance. Anyway, it's preferable to using a grid, IMO
Steven Sproat
I don't see how swapping the foreground and background colours would work, wouldn't you still just have a single solid colour instead of the alternating strips when the list is empty? Anything would be preferable to using a grid so I will probably check out the ULC and see what can be done with it although it would be nice to see if and how somebody has achieved this.. rather than wasting time.
volting