Commit 13d3d99a authored by eric pellegrini's avatar eric pellegrini
Browse files

Merge branch 'bugfix-uncheckable_items_in_checkable_combo_box' into 'develop'

Bugfix uncheckable items in checkable combo box

See merge request !31
parents eafedbe8 48b37437
Pipeline #4267 passed with stages
in 27 minutes and 19 seconds
......@@ -7,6 +7,7 @@ version 1.2.0
* FIXED issue #25 The plotter is now compliant with all matplotlib versions (was crashing on ubuntu-xenial)
* FIXED issue #21 "Save a template for new analysis" button produced an error
* FIXED issue #20 Opening the theoretical help on MacOS is now OK
* FIXED issue #18 The items of the checkable combobox are now checkable on Windows
* FIXED issue #16 The file filter combo box is now available from the input file dialog on MacOS
* CHANGED (internal) MDANSE is now built with system python (2.7.10)
import wx.combo
class ComboCheckbox(wx.combo.ComboPopup):
class ComboCheckbox(wx.CheckListBox,wx.combo.ComboPopup):
def __init__(self, items, maxNumberOfItems=None):
self._items = items
self._maxNumberOfItems = maxNumberOfItems
self._currentItem = -1
def items(self):
return self._items
......@@ -15,31 +19,49 @@ class ComboCheckbox(wx.combo.ComboPopup):
def checklistbox(self):
return self._checklistbox
return self
def OnMotion(self, event):
def Create(self, parent):
self._checklistbox = wx.CheckListBox(parent, -1, choices=self._items)
self._checklistbox.Bind(wx.EVT_CHECKLISTBOX, self.on_check_item)
if not self._checklistbox.IsEmpty():
item = self.HitTest(event.GetPosition())
if item >= 0:
self._currentItem = item
def Create(self, parent):
wx.CheckListBox.Create(self,parent, -1, choices=self._items)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_LEFT_DOWN, self.on_check_item)
if not self.IsEmpty():
return True
def GetControl(self):
return self._checklistbox
return self
def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
return self._checklistbox.GetSize()
size = self.GetControl().GetSize()
return wx.Size(minWidth, size[1])
def GetStringValue(self):
return self._checklistbox.GetCheckedStrings()
return self.GetCheckedStrings()
def on_check_item(self, event):
if self._maxNumberOfItems is None:
nCheckedItems = len(self._checklistbox.GetChecked())
if nCheckedItems > self._maxNumberOfItems:
self._checklistbox.Check(event.GetInt(), False)
\ No newline at end of file
# Control only if ele;ent is checked
if not self.IsChecked(self._currentItem):
# Control max number of items
if self._maxNumberOfItems is None:
# Accept the event
self.Check(self._currentItem, True)
# Control the number of checked items
nCheckedItems = len(self.GetChecked())
if nCheckedItems < self._maxNumberOfItems:
# Chech the item
self.Check(self._currentItem, True)
self.Check(self._currentItem, False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment