| 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> 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> File "test.py", line 92, in <module>
<br> TestPanel(f)
<br> File "test.py", line 66, in __init__
<br> popupCtrl =3D ComboCheckbox(['dfsfs','fsdfsf','sdfsf=
s'])
<br> File "test.py", line 9, in __init__
<br> wx.ComboPopup.__init__(self)
<br>SystemError: <class 'property'> 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> def __init__(self, items, maxNumberOfItems=3DNone):
<br>
<br> self.PostCreate(wx.CheckList=
Box())
<br>
<br> wx.ComboPopup.__init__(self)
<br>
<br> self._items =3D items
<br> self._maxNumberOfItems =3D m=
axNumberOfItems
<br> self._currentItem =3D -1
<br>
<br> def OnMotion(self, event):
<br>
<br> item =3D self.HitTest(=
event.GetPosition())
<br> if item >=3D 0:
<br> self=
.Select(item)
<br> self=
._currentItem =3D item
<br>
<br> def Create(self, parent):
<br>
<br> wx.CheckListBox.Create(self,=
parent, -1, choices=3Dself._items)
<br> self.Bind(wx.EVT_MOTION, sel=
f.OnMotion)
<br> self.Bind(wx.EVT_LEFT_DOWN, =
self.on_check_item)
<br> if not self.IsEmpty():
<br> self=
.Check(0)
<br>
<br> return True
<br>
<br> def GetControl(self):
<br> return self
<br>
<br> def GetAdjustedSize(self, minWidth, prefHeight, maxH=
eight):
<br> size =3D self.GetContr=
ol().GetSize()
<br> return wx.Size(minWidt=
h, size[1])
<br>
<br> def GetStringValue(self):
<br> return self.GetCheckedString=
s()
<br>
<br> def on_check_item(self, event):
<br>
<br> # Control only if ele;ent is=
checked
<br> if not self.IsChecked(self._=
currentItem):
<br>
<br> # Co=
ntrol max number of items
<br> if s=
elf._maxNumberOfItems is None:
<br>  =
; # Accept the event
<br>  =
; self.Check(self._currentItem, True)
<br> else=
:
<br>  =
; # Control the number of checked items
<br>  =
; nCheckedItems =3D len(self.GetChecked())
<br>  =
; if nCheckedItems < self._maxNumberOfItems:
<br>  =
; # Chech the item
<br>  =
; self.Check(self._currentItem, T=
rue)
<br> else:
<br> self=
.Check(self._currentItem, False)
<br>
<br>class TestPanel(wx.Panel):
<br> def __init__(self, parent):
<br> wx.Panel.__init__(self, pare=
nt, -1)
<br>
<br> comboCtrl =3D wx.ComboCtrl(s=
elf, wx.ID_ANY, "", (20,20))
<br>
<br> popupCtrl =3D ComboCheckbox(=
['dfsfs','fsdfsf','sdfsfs'])
<br>
<br> # It is important to call Se=
tPopupControl() as soon as possible
<br> comboCtrl.SetPopupControl(po=
pupCtrl)
<br>
<br> # Populate using wx.ListView=
methods
<br> popupCtrl.AddItem("First Ite=
m")
<br> popupCtrl.AddItem("Second It=
em")
<br> popupCtrl.AddItem("Third Ite=
m")
<br>
<br>
<br>#----------------------------------------------------------------------
<br>
<br>def runTest(frame, nb, log):
<br> win =3D TestPanel(nb, log)
<br> return win
<br>
<br>#----------------------------------------------------------------------
<br>
<br>
<br>if __name__ =3D=3D '__main__':
<br>
<br> app =3D wx.App()
<br>
<br> f =3D wx.Frame(None)
<br>
<br> TestPanel(f)
<br>
<br> f.Show()
<br>
<br> app.MainLoop()
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users" 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--