wx.checkbox and wx.combo.comboctrl

346 views
Skip to first unread message

zhengqing

unread,
Aug 30, 2012, 2:08:11 AM8/30/12
to wxpytho...@googlegroups.com
Hi, 
   I would like to combine with wx.combo.comboctrl and wx.checkbox to realize a function like wx.combobox with multi-selection.
   I am not sure how to do that, need help!
   or will wx.popwindow + wx.checkbox combination be a better choice?

Regards!

zhengqing(Forrest)

Robin Dunn

unread,
Aug 30, 2012, 1:34:16 PM8/30/12
to wxpytho...@googlegroups.com
On 8/29/12 11:08 PM, zhengqing wrote:
> Hi,
> I would like to combine with wx.combo.comboctrl and wx.checkbox to
> realize a function like wx.combobox with multi-selection.
> I am not sure how to do that, need help!
> or will wx.popwindow + wx.checkbox combination be a better choice?
>

Perhaps ComboCtrl with a CheckListBox popup, or with a wx.ListCtrl plus
CheckListCtrlMixin if you need more than one column.


--
Robin Dunn
Software Craftsman
http://wxPython.org

zhengqing

unread,
Aug 30, 2012, 9:03:26 PM8/30/12
to wxpytho...@googlegroups.com
Hi Robin,
    Thanks!
    That works very well, but somehow the checklistbox size is lot control.
    please help!
 
Thank you very much!
 
zhengqing(Forrest)
ChecklistboxComboCtrl.py

Robin Dunn

unread,
Sep 1, 2012, 6:11:11 PM9/1/12
to wxpytho...@googlegroups.com
On 8/30/12 6:03 PM, zhengqing wrote:
> Hi Robin,
> Thanks!
> That works very well, but somehow the checklistbox size is lot control.
> please help!

Sorry, I don't understand your question.

zhengqing

unread,
Sep 2, 2012, 12:56:28 AM9/2/12
to wxpytho...@googlegroups.com
Sorry!
I mean I can't control the size of the checklistbox in combo control, no matter how I set the size.
And in the function bellow:
     def Create(self, parent):
        self.checklistbox 

what is self and parent?

cc = wx.combo.ComboCtrl(self, size = (250, -1))
tcp = CheckboxComboPopup()
cc.SetPopupControl(tcp)

It looks like checklistbox is not attribute of cc and tcp, how can I add items, I tried create a method for adding new items, but it doesn't work?

def Additems(self, list):
     # list = ['zeor', 'one']
     for item in list:
          self.checklistbox.append(item)

tcp.Additems(list)

And this doesn't work!

Please help!

Regards!

zhengqing(Forrest)

Robin Dunn

unread,
Sep 3, 2012, 3:16:14 PM9/3/12
to wxpytho...@googlegroups.com
On 9/1/12 9:56 PM, zhengqing wrote:
> Sorry!
> I mean I can't control the size of the checklistbox in combo control, no
> matter how I set the size.
>
> And in the function bellow:
>
> def Create(self, parent):
> self.checklistbox
>
>
> what is self and parent?

Like usual self is an instance of the class that the method is a member
of, in this case the ComboPopup. Parent is the widget that should be
used as the parent of the widget that is created.



> cc = wx.combo.ComboCtrl(self, size = (250, -1))
> tcp = CheckboxComboPopup()
> cc.SetPopupControl(tcp)
>
>
> It looks like checklistbox is not attribute of cc and tcp,

The Create method is not called until after the SetPopupControl method
above, so checklistbox does not exist until then. But after that point
in the code you should be able to use checklistbox (or call a method
that uses it) without problems.

zhengqing

unread,
Sep 3, 2012, 9:56:45 PM9/3/12
to wxpytho...@googlegroups.com
Thank you very much! problem solved!
Then another problem is that I can't set the size as shown in the figure.
how to make the size to fit the number of checkbox?
 
Thanks!
 

Robin Dunn

unread,
Sep 4, 2012, 4:29:50 PM9/4/12
to wxpytho...@googlegroups.com
On 9/3/12 6:56 PM, zhengqing wrote:
> Thank you very much! problem solved!
> Then another problem is that I can't set the size as shown in the figure.
> how to make the size to fit the number of checkbox?

Do you override the GetAdjustedSize method in your ComboPopup class?
Message has been deleted

Robin Dunn

unread,
Sep 5, 2012, 2:36:54 AM9/5/12
to wxpytho...@googlegroups.com
On 9/4/12 9:30 PM, zhengqing wrote:
> Hi Robin,
> no, I didn't. From the Demo, I can't tell when this method was
> called, and what is the function of this method.
> Now I add this method into the class, but still don't know how it
> works, and where those parameter comes from, how to set those
> parameters, and when this method was called.
>
> def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
> return wx.Size(minWidth, min(150, maxHeight))
>
> Please help if I would like to learn more about wxpython.
>

http://docs.wxwidgets.org/trunk/classwx_combo_popup.html#ae8ff1d6570b177c2c6b7a101035cf2ff
Reply all
Reply to author
Forward
0 new messages