I am developing an application that uses a CheckListBox.
With the SetItemBackground() method, I apply a color to the item of
CheckListBox.
My code works perfectly under Windows, but I get no result, under
Linux.
What is the problem?
Here's a semplified example
import wx
class CLBColorModel():
def __init__(self):
self.list = ['1', '2', '3']
class CLBColorView(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, None, -1, 'BG Color', size=(200, 300))
def createWidgets(self, list):
self.panel = wx.Panel(self, -1)
self.clb = wx.CheckListBox(self.panel, -1, size = ( 100,
150 ), choices = list, style = wx.LB_HSCROLL)
self.btn_exit = wx.Button(self.panel, wx.ID_ANY, 'Exit')
def SizerizeWidgets(self):
'''posiziona i vari widgets nella posizione stabilita'''
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.clb, 0, wx.ALL|wx.CENTER, 5)
self.vbox.Add(wx.StaticLine(self.panel,), 0, wx.ALL|wx.EXPAND,
5)
self.vbox.Add(self.btn_exit, 0, wx.CENTER)
self.panel.SetSizer(self.vbox)
self.Centre()
class CLBColorController:
def __init__(self):
'''Costruttore controller'''
self.model = CLBColorModel()
self.createView()
def createView(self):
'''crea la view e la rende visibile'''
self.view = CLBColorView(None)
self.view.createWidgets(self.model.list)
self.view.SizerizeWidgets()
self.view.Show()
for item in self.view.clb.GetItems():
index = (self.model.list.index(item))
if int(item) < 2 :
self.view.clb.SetItemBackgroundColour(index, 'Yellow')
self.view.clb.SetItemForegroundColour(index, 'Blue')
self.view.btn_exit.Bind(wx.EVT_BUTTON, self.onExit)
self.view.clb.Bind(wx.EVT_CHECKLISTBOX, self.onCLB )
def onCLB(self, evt):
'''handler click checklistbox'''
print "Clik...todo sth"
def onExit(self, evt):
'''handler button di uscita'''
self.view.Close()
if __name__ == '__main__':
app = wx.App(False)
controller = CLBColorController()
app.MainLoop()