Does someone know how do change the Item-BackgroundColour in an EditableListBox to the default value?
OnSearch the Background color should change when the search_item is found. That actually works the first time, but if cancel the first search and repeat the search(for example search_item is “5”) the Background color isn’t completely visible anymore. I use win10, python 3.8.10 and wx.python 4.2.1EditableListBox
# -*- coding: utf-8 -*-
import wx
import wx.adv
## Class MainFrame ##
class MainFrame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY,
title = wx.EmptyString, pos = wx.DefaultPosition,
size = wx.Size( 500,300 ),
style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHints( wx.Size( 500,300 ), wx.DefaultSize )
self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT ) )
gSizer = wx.GridSizer( 1, 2, 3, 3 )
self.m_EDL1 = wx.adv.EditableListBox(
self, wx.ID_ANY, u"List_1", wx.DefaultPosition,
wx.DefaultSize,
style=wx.adv.EL_DEFAULT_STYLE |
#wx.adv.EL_NO_REORDER |
wx.adv.EL_ALLOW_NEW |
wx.adv.EL_ALLOW_EDIT |
wx.adv.EL_ALLOW_DELETE)
self.m_EDL1.SetStrings(["1a","2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16","17","18","19",])
self.m_EDL1.SetBackgroundColour(wx.Colour(128,128,128))
gSizer.Add( self.m_EDL1, 1, wx.EXPAND|wx.ALL, 5 )
self.m_EDL2 = wx.adv.EditableListBox(
self, wx.ID_ANY, u"List_2", wx.DefaultPosition,
wx.DefaultSize,
style=wx.adv.EL_DEFAULT_STYLE |
#wx.adv.EL_NO_REORDER |
wx.adv.EL_ALLOW_NEW |
wx.adv.EL_ALLOW_EDIT |
wx.adv.EL_ALLOW_DELETE)
self.m_EDL2.SetStrings(["A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S",])
self.m_EDL2.SetBackgroundColour(wx.Colour(128,128,128))
gSizer.Add( self.m_EDL2, 1, wx.EXPAND|wx.ALL, 5 )
self.SetSizer( gSizer )
self.Layout()
self.m_toolBar = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY )
self.m_toolBar.AddSeparator()
self.m_searchCtrl_ELB = wx.SearchCtrl( self.m_toolBar, wx.ID_ANY,
wx.EmptyString,
wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_searchCtrl_ELB.ShowSearchButton( True )
self.m_searchCtrl_ELB.ShowCancelButton( True )
self.m_toolBar.AddControl( self.m_searchCtrl_ELB )
self.m_toolBar.AddSeparator()
self.m_toolBar.Realize()
self.Centre( wx.BOTH )
## Connect Events ##
self.m_searchCtrl_ELB.Bind( wx.EVT_SEARCHCTRL_CANCEL_BTN, self.m_searchCtrl_ELBOnCancelButton )
#self.m_searchCtrl_ELB.Bind( wx.EVT_TEXT_ENTER, self.m_searchCtrl_ELBOnTextEnter )
self.m_searchCtrl_ELB.Bind( wx.EVT_SEARCHCTRL_SEARCH_BTN, self.m_searchCtrl_ELBOnTextEnter )
def __del__( self ):
pass
## Virtual event handlers ##
def m_searchCtrl_ELBOnCancelButton( self, event ):
self.m_EDL1.ListCtrl.SetBackgroundColour(wx.Colour(255,255,255))
for i in range(len(self.m_EDL1.GetStrings())):
self.m_EDL1.ListCtrl.SetItemBackgroundColour(i,wx.Colour(255,255,255))
self.m_EDL1.Refresh()
event.Skip()
def m_searchCtrl_ELBOnTextEnter( self, event ):
search_term = self.m_searchCtrl_ELB.GetValue()
list_EDL1 = self.m_EDL1.GetStrings()
for i in range(len(list_EDL1)):
if search_term in list_EDL1[i]:
self.m_EDL1.ListCtrl.SetItemBackgroundColour(i,wx.Colour(125,255,125))
self.m_EDL1.ListCtrl.SetBackgroundColour(wx.Colour(220,255,220))
self.m_EDL1.Refresh()
event.Skip()
app = wx.App()
frame = MainFrame(None)
frame.Show(True)
app.MainLoop()
I tried
self.m_EDL1.ListCtrl.SetItemBackgroundColour(i,wx.Colour(-1,-1,-1,0))
but that doesn’t seem to be the default-value…
Q_RIS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.