From e8f394bc2c0981fcd7b849dca9f43dac1a2db3c5 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 13 Oct 2020 15:40:17 -0700 Subject: [PATCH 1/5] Switch the CheckListCtrlMixin demo to just use the new built-in checkbox functionality --- ...CheckListCtrlMixin.py => CheckListCtrl.py} | 33 ++++++++++--------- demo/demodata.py | 3 +- 2 files changed, 19 insertions(+), 17 deletions(-) rename demo/{CheckListCtrlMixin.py => CheckListCtrl.py} (74%) diff --git a/demo/CheckListCtrlMixin.py b/demo/CheckListCtrl.py similarity index 74% rename from demo/CheckListCtrlMixin.py rename to demo/CheckListCtrl.py index d57dfb33..bb79b39d 100644 --- a/demo/CheckListCtrlMixin.py +++ b/demo/CheckListCtrl.py @@ -2,32 +2,33 @@ import sys import wx -from wx.lib.mixins.listctrl import CheckListCtrlMixin from ListCtrl import musicdata #---------------------------------------------------------------------- -class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin): +class CheckListCtrl(wx.ListCtrl): def __init__(self, parent, log): wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT) - CheckListCtrlMixin.__init__(self) self.log = log - self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) + self.EnableCheckBoxes() + self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) + self.Bind(wx.EVT_LIST_ITEM_CHECKED, self.OnItemCheckChanged) + self.Bind(wx.EVT_LIST_ITEM_UNCHECKED, self.OnItemCheckChanged) + + def ToggleItem(self, index): + toggle = not self.IsItemChecked(index) + self.CheckItem(index, toggle) def OnItemActivated(self, evt): self.ToggleItem(evt.Index) - - # this is called by the base class when an item is checked/unchecked - def OnCheckItem(self, index, flag): + def OnItemCheckChanged(self, evt): + index = evt.Index data = self.GetItemData(index) title = musicdata[data][1] - if flag: - what = "checked" - else: - what = "unchecked" + what = "checked" if self.IsItemChecked(index) else "unchecked" self.log.write('item "%s", at index %d was %s\n' % (title, index, what)) @@ -56,8 +57,8 @@ class TestPanel(wx.Panel): self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE) self.list.SetColumnWidth(2, 100) - self.list.CheckItem(4) - self.list.CheckItem(7) + self.list.CheckItem(4, True) + self.list.CheckItem(7, True) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.list) @@ -81,10 +82,10 @@ def runTest(frame, nb, log): overview = """ -

+

CheckListCtrl

-CheckListCtrlMixin is a simple mixin class that can add a checkbox to -the first column of a wx.ListCtrl. +Starting with the wxPython 4.1 series the wx.ListCtrl is able to support checkboxes on the +items, and adds events to notify when the items are checked or unchecked. """ diff --git a/demo/demodata.py b/demo/demodata.py index 64d01442..33655571 100644 --- a/demo/demodata.py +++ b/demo/demodata.py @@ -48,6 +48,7 @@ _treeList = [ 'SVGImage_Render', 'ActivityIndicator', 'GenericCheckBox', + 'CheckListCtrl', ]), # managed windows == things with a (optional) caption you can close @@ -171,7 +172,7 @@ _treeList = [ 'BitmapComboBox', 'Calendar', 'CalendarCtrl', - 'CheckListCtrlMixin', + 'CheckListCtrl', 'CollapsiblePane', 'ComboCtrl', 'ContextHelp', From 9bef374ecff905686b96a8af603c4e5a032d27c9 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 13 Oct 2020 15:56:04 -0700 Subject: [PATCH 2/5] Give a warning about CheckListCtrlMixin's redundancy --- wx/lib/mixins/listctrl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wx/lib/mixins/listctrl.py b/wx/lib/mixins/listctrl.py index c770c116..5ec8529f 100644 --- a/wx/lib/mixins/listctrl.py +++ b/wx/lib/mixins/listctrl.py @@ -692,6 +692,11 @@ HISTORY: 1.1 - Initial version """ +_warning = ( +"The CheckListCtrlMixin class has been made redundant by new checkbox features in the " +"wx.ListCtrl class. It is advised to switch your code to use that instead of this mixin.") + + class CheckListCtrlMixin(object): """ This is a mixin for ListCtrl which add a checkbox in the first @@ -709,8 +714,14 @@ class CheckListCtrlMixin(object): CheckItem(). You should not set a imagelist for the ListCtrl once this mixin is used. + + WARNING: This class is obsolete as wx.ListCtrl now includes nearly the same + functionality. """ def __init__(self, check_image=None, uncheck_image=None, imgsz=(16,16)): + import warnings + warnings.warn(_warning) + if check_image is not None: imgsz = check_image.GetSize() elif uncheck_image is not None: From cafa02a2f2e1968d60b61a9e3760dcdd4364df92 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 13 Oct 2020 15:57:02 -0700 Subject: [PATCH 3/5] Remove old todo file --- demo/WIPzChecklistPhoenixDemo.txt | 319 ------------------------------ 1 file changed, 319 deletions(-) delete mode 100644 demo/WIPzChecklistPhoenixDemo.txt diff --git a/demo/WIPzChecklistPhoenixDemo.txt b/demo/WIPzChecklistPhoenixDemo.txt deleted file mode 100644 index a4621a5a..00000000 --- a/demo/WIPzChecklistPhoenixDemo.txt +++ /dev/null @@ -1,319 +0,0 @@ -__ __ _____ _____ -\ \ / /|_ _|| __ \ - \ \ /\ / / | | | |__) | ____ - \ \/ \/ / | | | ___/ |_ / - \ /\ / _| |_ | | / / - \/ \/ |_____||_| /___| -WIPz Phoenix Demos Checklist -""" -[X] Demo Works! Woot :) -[ ] Demo Still NEEDS work, has missing libs, other. :( -""" -When all done, this checklist.txt can be discarded. - -Frames and Dialogs Demos -======================== -[X] AUI_DockingWindowMgr -[X] AUI_MDI - TODO - Not working properly -[X] Dialog -[X] Frame -[X] MDIWindows -[X] MiniFrame -[X] Wizard - -Common Dialogs Demos -==================== -[X] AboutBox -[X] ColourDialog -[X] DirDialog -[X] FileDialog -[X] FindReplaceDialog -[X] FontDialog -[X] MessageDialog -[X] MultiChoiceDialog -[X] PageSetupDialog -[X] PrintDialog -[X] ProgressDialog -[X] SingleChoiceDialog -[X] TextEntryDialog - -More Dialogs Demos -================== -[X] ImageBrowser -[X] ScrolledMessageDialog - -Core Windows/Controls Demos -=========================== -[X] BitmapButton -[X] Button -[X] CheckBox -[X] CheckListBox -[X] Choice -[X] ComboBox -[X] CommandLinkButton -[X] DVC_CustomRenderer -[X] DVC_DataViewModel -[X] DVC_IndexListModel -[X] DVC_ListCtrl -[X] DVC_TreeCtrl -[X] Gauge -[X] Grid -[X] Grid_MegaExample -[X] GridLabelRenderer -[X] ListBox -[X] ListCtrl -[X] ListCtrl_virtual -[X] ListCtrl_edit -[X] Menu -[X] PopupMenu -[X] PopupWindow -[X] RadioBox -[X] RadioButton -[X] SashWindow -[X] ScrolledWindow -[X] SearchCtrl -[X] Slider -[X] SpinButton -[X] SpinCtrl -[X] SpinCtrlDouble -[X] SplitterWindow -[X] StaticBitmap -[X] StaticBox -[X] StaticText -[X] StatusBar -[X] StockButtons -[X] TextCtrl -[X] ToggleButton -[X] ToolBar -[X] TreeCtrl -[X] Validator - -"Book" Controls Demos -===================== -[X] AUI_Notebook - TODO - Not working properly -[X] Choicebook -[X] FlatNotebook -[X] Listbook -[X] Notebook -[X] Toolbook -[X] Treebook - -Custom Controls Demos -===================== -[X] AnalogClock -[X] ColourSelect -[X] ComboTreeBox -[X] Editor -[X] GenericButtons -[X] GenericDirCtrl -[X] ItemsPicker -[ ] LEDNumberCtrl -[X] MultiSash -[X] PlateButton -[X] PopupControl -[X] PyColourChooser -[X] TreeListCtrl - TODO - still need to adjust for selected image: smiley - -AGW Demos -========= -[X] AdvancedSplash -[X] AquaButton -[X] AUI -[X] BalloonTip -[X] ButtonPanel -[X] CubeColourDialog -[X] CustomTreeCtrl -[ ] FlatMenu - TODO - Crashes on opening menu -[X] FlatNotebook -[X] FloatSpin -[X] FoldPanelBar -[X] FourWaySplitter -[X] GenericMessageDialog -[X] GradientButton -[X] HyperLinkCtrl -[X] HyperTreeList -[X] AGWInfoBar -[X] KnobCtrl -[X] LabelBook -[X] MultiDirDialog -[X] PeakMeter -[X] PersistentControls -[X] PieCtrl -[X] PyBusyInfo -[X] PyCollapsiblePane -[X] PyGauge -[X] PyProgress - TODO - Also cancel button doesn't work -[X] RibbonBar -[X] RulerCtrl -[X] ShapedButton -[X] ShortcutEditor -[X] SpeedMeter - TODO - Traceback (most recent call last): -[X] SuperToolTip -[X] ThumbnailCtrl -[X] ToasterBox - TODO - is crashing on/after toasty -[X] UltimateListCtrl -[X] XLSGrid -[X] ZoomBar - -More Windows/Controls Demos -=========================== -[X] ActiveX_FlashWindow -[X] ActiveX_IEHtmlWindow -[X] ActiveX_PDFWindow -[X] BitmapComboBox -[X] Calendar -[X] CalendarCtrl - TODO - could use some work/cleanup -[X] CheckListCtrlMixin -[X] CollapsiblePane -[X] ComboCtrl -[X] ContextHelp - TODO - ContextHelp doesn't seem to be working yet tho... -[X] DatePickerCtrl -[ ] DynamicSashWindow -[X] EditableListBox -[X] ExpandoTextCtrl - TODO - Traceback (most recent call last): - File "ExpandoTextCtrl.py", line 82, in OnSetMaxHeight - dlg = wx.NumberEntryDialog(self, "", "Enter new max height:", - AttributeError: 'module' object has no attribute 'NumberEntryDialog' -[X] FancyText -[X] FileBrowseButton -[X] FloatBar -[X] FloatCanvas -[X] HtmlWindow - TODO - Traceback (most recent call last): - File "HtmlWindow.py", line 177, in OnViewSource - source = self.html.GetParser().GetSource() - AttributeError: 'MyHtmlWindow' object has no attribute 'GetParser' -[X] HTML2_WebView -[X] InfoBar -[X] IntCtrl -[X] MVCTree -[X] MaskedEditControls -[X] MaskedNumCtrl -[X] MediaCtrl -[X] MultiSplitterWindow -[X] OwnerDrawnComboBox -[X] Pickers -[ ] PropertyGrid -[X] PyCrust -[X] PyPlot -[X] PyShell -[X] ResizeWidget -[X] RichTextCtrl -[X] ScrolledPanel -[ ] SplitTree -[X] StyledTextCtrl_1 -[X] StyledTextCtrl_2 -[X] TablePrint -[X] Throbber -[X] Ticker -[X] TimeCtrl -[X] TreeMixin -[X] VListBox - -Window Layout Demos -=================== -[X] GridBagSizer -[X] LayoutAnchors -[X] LayoutConstraints -[X] Layoutf -[X] RowColSizer -[X] ScrolledPanel -[X] SizedControls -[X] Sizers -[X] WrapSizer -[X] XmlResource -[X] XmlResourceHandler -[X] XmlResourceSubclass - -Process and Events Demos -[X] DelayedResult -[X] EventManager -[X] KeyEvents -[X] Process -[X] PythonEvents -[X] Threads -[X] Timer -[ ] #'infoframe # needs better explanation and some fixing - -Clipboard and DnD Demos -======================= -[X] CustomDragAndDrop - TODO - DoodleDrop isn't showing upon drop -[X] DragAndDrop - TODO - TypeError: Invalid result type upon drops -[X] URLDragAndDrop - -Using Images Demos -================== -[X] AdjustChannels -[X] AlphaDrawing -[X] AnimateCtrl -[X] ArtProvider -[X] BitmapFromBuffer -[X] Cursor -[X] DragImage -[X] Image -[X] ImageAlpha -[X] ImageFromStream -[X] Img2PyArtProvider -[X] Mask -[X] RawBitmapAccess -[X] Throbber - -Miscellaneous Demos -=================== -[X] AlphaDrawing -[X] Cairo -[X] Cairo_Snippets -[X] ColourDB -[ ] #'DialogUnits # needs more explanations -[X] DragScroller -[X] DrawXXXList -[X] FileHistory -[X] FontEnumerator -[X] GraphicsContext -[X] GraphicsGradient -[X] GLCanvas - TODO - Cone not working -[X] I18N -[X] Joystick - TODO - Needs more work and tested with a joystick. I dont have one. -[X] MimeTypesManager -[X] MouseGestures -[X] OGL -[X] PDFViewer -[X] PenAndBrushStyles -[X] PrintFramework -[X] PseudoDC -[X] RendererNative -[X] ShapedWindow -[X] Sound -[X] StandardPaths -[X] SystemSettings -[X] UIActionSimulator -[X] Unicode From 15be2436d1bf521aa79527fe6aad57567d4a088d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 13 Oct 2020 16:04:49 -0700 Subject: [PATCH 4/5] Give CheckItem.check a default value so it will be less likely for code still using CheckListCtrlMixin to raise an exception. --- etg/listctrl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/etg/listctrl.py b/etg/listctrl.py index d50debd3..9acac2a0 100644 --- a/etg/listctrl.py +++ b/etg/listctrl.py @@ -197,6 +197,7 @@ def run(): return rv; """) + c.find('CheckItem.check').default = 'true' # Some deprecated aliases for Classic renames From 4d1e8f0b4704b8a755a5c92f65119bd0637f35a2 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 13 Oct 2020 16:14:46 -0700 Subject: [PATCH 5/5] Add notes in CHANGES and the MigrationGuide --- CHANGES.rst | 7 +++++++ docs/MigrationGuide.rst | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 10e6752e..3b4f9f18 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -61,6 +61,13 @@ New and improved in this release: * Added wx.lib.agw.aui.AUI_DOCKART_HINT_WINDOW_BORDER_COLOUR constant so the hint window border color can be themed as well. +* The wx.lib.mixins.listCtrl.CheckListCtrlMixin is now obsolete because + wx.ListCtrl has new functionality which does pretty much the same thing. In + fact there is some overlap in method names which may trip up some use cases. + It is advised to drop the use of CheckListCtrlMixin and just use the + wx.ListBox functionality. You will need to call EnableCheckBoxes to turn it on, + and you may need to change some event handlers or overloaded methods. + diff --git a/docs/MigrationGuide.rst b/docs/MigrationGuide.rst index 492f1dc5..39d2b716 100644 --- a/docs/MigrationGuide.rst +++ b/docs/MigrationGuide.rst @@ -722,6 +722,18 @@ error is raised. +CheckListCtrlMixin Redundancy +----------------------------- + +The wx.lib.mixins.listCtrl.CheckListCtrlMixin is now obsolete because +wx.ListCtrl has new functionality which does pretty much the same thing. In +fact there is some overlap in method names which may trip up some use cases. +It is advised to drop the use of CheckListCtrlMixin and just use the +wx.ListBox functionality. You will need to call EnableCheckBoxes to turn it on, +and you may need to change some event handlers or overloaded methods. + + + .. toctree:: :maxdepth: 2 :hidden: