Add CheckBox stuff to ListCtrl Demo

This commit is contained in:
Metallicow
2019-06-30 02:45:14 -05:00
parent 2bfa54af35
commit d1c282eb21

View File

@@ -122,6 +122,7 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
sizer.Add(self.list, 1, wx.EXPAND)
self.list.EnableCheckBoxes(enable=True)
self.PopulateList()
@@ -246,12 +247,12 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
event.Skip()
def OnItemDeselected(self, evt):
item = evt.GetItem()
self.log.WriteText("OnItemDeselected: %d" % evt.Index)
def OnItemDeselected(self, event):
item = event.GetItem()
self.log.WriteText("OnItemDeselected: %d" % event.Index)
# Show how to reselect something we don't want deselected
if evt.Index == 11:
if event.Index == 11:
wx.CallAfter(self.list.SetItemState, 11, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
def OnItemActivated(self, event):
@@ -295,6 +296,21 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
def OnColEndDrag(self, event):
self.log.WriteText("OnColEndDrag\n")
def OnCheckAllBoxes(self, event):
itemcount = self.list.GetItemCount()
[self.list.CheckItem(item=i, check=True) for i in range(itemcount)]
self.log.WriteText("OnCheckAllBoxes\n")
def OnUnCheckAllBoxes(self, event):
itemcount = self.list.GetItemCount()
[self.list.CheckItem(item=i, check=False) for i in range(itemcount)]
self.log.WriteText("OnUnCheckAllBoxes\n")
def OnGetItemsChecked(self, event):
itemcount = self.list.GetItemCount()
itemschecked = [i for i in range(itemcount) if self.list.IsItemChecked(item=i)]
self.log.WriteText("OnGetItemsChecked: %s \n" % itemschecked)
def OnDoubleClick(self, event):
self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem))
event.Skip()
@@ -310,6 +326,9 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
self.popupID4 = wx.NewIdRef()
self.popupID5 = wx.NewIdRef()
self.popupID6 = wx.NewIdRef()
self.popupID7 = wx.NewIdRef()
self.popupID8 = wx.NewIdRef()
self.popupID9 = wx.NewIdRef()
self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
@@ -317,6 +336,9 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
self.Bind(wx.EVT_MENU, self.OnCheckAllBoxes, id=self.popupID7)
self.Bind(wx.EVT_MENU, self.OnUnCheckAllBoxes, id=self.popupID8)
self.Bind(wx.EVT_MENU, self.OnGetItemsChecked, id=self.popupID9)
# make a menu
menu = wx.Menu()
@@ -327,6 +349,9 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
menu.Append(self.popupID4, "DeleteAllItems")
menu.Append(self.popupID5, "GetItem")
menu.Append(self.popupID6, "Edit")
menu.Append(self.popupID7, "Check All Boxes")
menu.Append(self.popupID8, "UnCheck All Boxes")
menu.Append(self.popupID9, "Get Checked Items")
# Popup the menu. If an item is selected then its handler
# will be called before PopupMenu returns.