combobox with checkable items

"[email protected]" <[email protected]> Fri, 3 Jun 2022 03:32:32 -0700 (PDT)
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
------=_Part_1196_960255748.1654252352125
Content-Type: multipart/alternative; 
	boundary="----=_Part_1197_1512336567.1654252352125"

------=_Part_1197_1512336567.1654252352125
Content-Type: text/plain; charset="UTF-8"

Hi all, 

I created some years ago (wxPython 3.0) a combobox with checkable items. 
Behind the scene, it used a mixin class between wx.CheckListBox and 
wx.combo.ComboPopup. Recently, I had to port this code to Phoenix and I can 
not make it work. You will find below a snippet reproducing the code. The 
error I get is: 

test.py:7: wxPyDeprecationWarning: Call to deprecated item. PostCreate is 
no longer necessary. 
  self.PostCreate(wx.CheckListBox()) 
wx._core.wxAssertionError: C++ assertion "m_treeview != __null" failed at 
/tmp/build/80754af9/wxpython_1547931003892/work/ext/wxWidgets/src/gtk/listbox.cpp(478) 
in DoClear(): invalid listbox 

The above exception was the direct cause of the following exception: 

Traceback (most recent call last): 
  File "test.py", line 92, in <module> 
    TestPanel(f) 
  File "test.py", line 66, in __init__ 
    popupCtrl = ComboCheckbox(['dfsfs','fsdfsf','sdfsfs']) 
  File "test.py", line 9, in __init__ 
    wx.ComboPopup.__init__(self) 
SystemError: <class 'property'> returned a result with an error set 

Would you have any idea about how to make this code work on phoenix ? 

Thanks for your help 

Eric 

##################################################### 

import wx 

class ComboCheckbox(wx.CheckListBox,wx.ComboPopup): 

    def __init__(self, items, maxNumberOfItems=None): 

        self.PostCreate(wx.CheckListBox()) 

        wx.ComboPopup.__init__(self) 

        self._items = items 
        self._maxNumberOfItems = maxNumberOfItems 
        self._currentItem = -1 

    def OnMotion(self, event): 

        item  = self.HitTest(event.GetPosition()) 
        if item >= 0: 
            self.Select(item) 
            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(): 
            self.Check(0) 

        return True 

    def GetControl(self): 
        return self 

    def GetAdjustedSize(self, minWidth, prefHeight, maxHeight): 
         size = self.GetControl().GetSize() 
         return wx.Size(minWidth, size[1]) 

    def GetStringValue(self): 
        return self.GetCheckedStrings() 

    def on_check_item(self, event): 

        # 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) 
            else: 
                # Control the number of checked items 
                nCheckedItems = len(self.GetChecked()) 
                if nCheckedItems < self._maxNumberOfItems: 
                    # Chech the item 
                    self.Check(self._currentItem, True) 
        else: 
            self.Check(self._currentItem, False) 

class TestPanel(wx.Panel): 
    def __init__(self, parent): 
        wx.Panel.__init__(self, parent, -1) 

        comboCtrl = wx.ComboCtrl(self, wx.ID_ANY, "", (20,20)) 

        popupCtrl = ComboCheckbox(['dfsfs','fsdfsf','sdfsfs']) 

        # It is important to call SetPopupControl() as soon as possible 
        comboCtrl.SetPopupControl(popupCtrl) 

        # Populate using wx.ListView methods 
        popupCtrl.AddItem("First Item") 
        popupCtrl.AddItem("Second Item") 
        popupCtrl.AddItem("Third Item") 


#---------------------------------------------------------------------- 

def runTest(frame, nb, log): 
    win = TestPanel(nb, log) 
    return win 

#---------------------------------------------------------------------- 


if __name__ == '__main__': 

    app = wx.App() 

    f = wx.Frame(None) 

    TestPanel(f) 

    f.Show() 

    app.MainLoop() 

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/d5e63a56-339c-46dd-a844-90a2af471b36n%40googlegroups.com.

------=_Part_1197_1512336567.1654252352125
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi all,
<br>
<br>I created some years ago (wxPython 3.0) a combobox with checkable items=
.=20
Behind the scene, it used a mixin class between wx.CheckListBox and=20
wx.combo.ComboPopup. Recently, I had to port this code to Phoenix and I=20
can not make it work. You will find below a snippet reproducing the=20
code. The error I get is:
<br>
<br>test.py:7: wxPyDeprecationWarning: Call to deprecated item. PostCreate=
=20
is no longer necessary.
<br>&nbsp; self.PostCreate(wx.CheckListBox())
<br>wx._core.wxAssertionError: C++ assertion "m_treeview !=3D __null" faile=
d=20
at=20
/tmp/build/80754af9/wxpython_1547931003892/work/ext/wxWidgets/src/gtk/listb=
ox.cpp(478)=20
in DoClear(): invalid listbox
<br>
<br>The above exception was the direct cause of the following exception:
<br>
<br>Traceback (most recent call last):
<br>&nbsp; File "test.py", line 92, in &lt;module&gt;
<br>&nbsp;&nbsp;&nbsp; TestPanel(f)
<br>&nbsp; File "test.py", line 66, in __init__
<br>&nbsp;&nbsp;&nbsp; popupCtrl =3D ComboCheckbox(['dfsfs','fsdfsf','sdfsf=
s'])
<br>&nbsp; File "test.py", line 9, in __init__
<br>&nbsp;&nbsp;&nbsp; wx.ComboPopup.__init__(self)
<br>SystemError: &lt;class 'property'&gt; returned a result with an error s=
et
<br>
<br>Would you have any idea about how to make this code work on phoenix ?
<br>
<br>Thanks for your help
<br>
<br>Eric
<br>
<br>#####################################################
<br>
<br>import wx
<br>
<br>class ComboCheckbox(wx.CheckListBox,wx.ComboPopup):
<br>
<br>&nbsp;&nbsp;&nbsp; def __init__(self, items, maxNumberOfItems=3DNone):
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.PostCreate(wx.CheckList=
Box())
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wx.ComboPopup.__init__(self)
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._items =3D items
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._maxNumberOfItems =3D m=
axNumberOfItems
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._currentItem =3D -1
<br>
<br>&nbsp;&nbsp;&nbsp; def OnMotion(self, event):
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item&nbsp; =3D self.HitTest(=
event.GetPosition())
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if item &gt;=3D 0:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self=
.Select(item)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self=
._currentItem =3D item
<br>
<br>&nbsp;&nbsp;&nbsp; def Create(self, parent):
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wx.CheckListBox.Create(self,=
parent, -1, choices=3Dself._items)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Bind(wx.EVT_MOTION, sel=
f.OnMotion)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Bind(wx.EVT_LEFT_DOWN, =
self.on_check_item)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not self.IsEmpty():
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self=
.Check(0)
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return True
<br>
<br>&nbsp;&nbsp;&nbsp; def GetControl(self):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self
<br>
<br>&nbsp;&nbsp;&nbsp; def GetAdjustedSize(self, minWidth, prefHeight, maxH=
eight):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size =3D self.GetContr=
ol().GetSize()
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return wx.Size(minWidt=
h, size[1])
<br>
<br>&nbsp;&nbsp;&nbsp; def GetStringValue(self):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.GetCheckedString=
s()
<br>
<br>&nbsp;&nbsp;&nbsp; def on_check_item(self, event):
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Control only if ele;ent is=
 checked
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not self.IsChecked(self._=
currentItem):
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Co=
ntrol max number of items
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if s=
elf._maxNumberOfItems is None:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; # Accept the event
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; self.Check(self._currentItem, True)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else=
:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; # Control the number of checked items
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; nCheckedItems =3D len(self.GetChecked())
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; if nCheckedItems &lt; self._maxNumberOfItems:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Chech the item
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Check(self._currentItem, T=
rue)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self=
.Check(self._currentItem, False)
<br>
<br>class TestPanel(wx.Panel):
<br>&nbsp;&nbsp;&nbsp; def __init__(self, parent):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wx.Panel.__init__(self, pare=
nt, -1)
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comboCtrl =3D wx.ComboCtrl(s=
elf, wx.ID_ANY, "", (20,20))
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; popupCtrl =3D ComboCheckbox(=
['dfsfs','fsdfsf','sdfsfs'])
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # It is important to call Se=
tPopupControl() as soon as possible
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comboCtrl.SetPopupControl(po=
pupCtrl)
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Populate using wx.ListView=
 methods
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; popupCtrl.AddItem("First Ite=
m")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; popupCtrl.AddItem("Second It=
em")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; popupCtrl.AddItem("Third Ite=
m")
<br>
<br>
<br>#----------------------------------------------------------------------
<br>
<br>def runTest(frame, nb, log):
<br>&nbsp;&nbsp;&nbsp; win =3D TestPanel(nb, log)
<br>&nbsp;&nbsp;&nbsp; return win
<br>
<br>#----------------------------------------------------------------------
<br>
<br>
<br>if __name__ =3D=3D '__main__':
<br>
<br>&nbsp;&nbsp;&nbsp; app =3D wx.App()
<br>
<br>&nbsp;&nbsp;&nbsp; f =3D wx.Frame(None)
<br>
<br>&nbsp;&nbsp;&nbsp; TestPanel(f)
<br>
<br>&nbsp;&nbsp;&nbsp; f.Show()
<br>
<br>&nbsp;&nbsp;&nbsp; app.MainLoop()

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxpy=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/d5e63a56-339c-46dd-a844-90a2af471b36n%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d=
/msgid/wxpython-users/d5e63a56-339c-46dd-a844-90a2af471b36n%40googlegroups.=
com</a>.<br />

------=_Part_1197_1512336567.1654252352125--

------=_Part_1196_960255748.1654252352125--