From a3af417f8ff4e77b84c87bcce7e08f0c9f25b3b1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 22:43:21 -0700 Subject: [PATCH 1/2] Fix the monkey-patch to use the new name of the real method --- wx/lib/mixins/listctrl.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/wx/lib/mixins/listctrl.py b/wx/lib/mixins/listctrl.py index 57b99413..d641ad15 100644 --- a/wx/lib/mixins/listctrl.py +++ b/wx/lib/mixins/listctrl.py @@ -698,7 +698,7 @@ HISTORY: 1.1 - Initial version """ -class CheckListCtrlMixin: +class CheckListCtrlMixin(object): """ This is a mixin for ListCtrl which add a checkbox in the first column of each row. It is inspired by limodou's CheckList.py(which @@ -738,8 +738,16 @@ class CheckListCtrlMixin: self.Bind(wx.EVT_LEFT_DOWN, self.__OnLeftDown_) - # override the default methods of ListCtrl/ListView - self.InsertStringItem = self.__InsertStringItem_ + # Monkey-patch in a new InsertItem so we can also set the image ID for the item + self._origInsertItem = self.InsertItem + self.InsertItem = self.__InsertItem_ + + + def __InsertItem_(self, *args, **kw): + index = self._origInsertItem(*args, **kw) + self.SetItemImage(index, self.uncheck_image) + return index + def __CreateBitmap(self, flag=0, size=(16, 16)): """Create a bitmap of the platforms native checkbox. The flag @@ -754,9 +762,6 @@ class CheckListCtrlMixin: dc.SelectObject(wx.NullBitmap) return bmp - def __InsertStringItem_(self, index, label): - index = self.InsertItem(index, label, 0) - return index def __OnLeftDown_(self, evt): (index, flags) = self.HitTest(evt.GetPosition()) From 8e1da1f2e0d155ea0004f7f99257a61502c046a0 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Jun 2017 22:46:35 -0700 Subject: [PATCH 2/2] Clear the bitmap with the white brush --- wx/lib/mixins/listctrl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wx/lib/mixins/listctrl.py b/wx/lib/mixins/listctrl.py index d641ad15..d52077f0 100644 --- a/wx/lib/mixins/listctrl.py +++ b/wx/lib/mixins/listctrl.py @@ -756,6 +756,7 @@ class CheckListCtrlMixin(object): """ bmp = wx.Bitmap(*size) dc = wx.MemoryDC(bmp) + dc.SetBackground(wx.WHITE_BRUSH) dc.Clear() wx.RendererNative.Get().DrawCheckBox(self, dc, (0, 0, size[0], size[1]), flag)