How to show a checkbox in ObjectListView

849 views
Skip to first unread message

Mike Driscoll

unread,
Feb 26, 2013, 12:28:20 PM2/26/13
to wxpytho...@googlegroups.com
Hi,

I'm trying to figure out how to insert a checkbox in the ObjectListView widget. According to http://objectlistview.sourceforge.net/python/recipes.html?highlight=checkbox#recipe-checkbox I am supposed to be able to use the CreateCheckStateColumn() method, but that doesn't appear to work for me. I have attached a small runnable example. Can anyone see what I'm doing wrong?

I am using Python 2.6.6 on Windows 7 with wxPython 2.8.12.1

Thanks,
Mike
test_check.py

Mike Driscoll

unread,
Feb 26, 2013, 1:34:48 PM2/26/13
to wxpytho...@googlegroups.com
Hi Yoriz,

I put the call in my setResults() method directly after the SetColumns() call and you're right, it worked! Thanks!

- Mike


On Tue, Feb 26, 2013 at 12:05 PM, Yoriz <oldkn...@googlemail.com> wrote:
Hiya,
Move the CreateCheckStateColumn to after the SetColumns method.
--
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 wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
-----------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org

Raphael Mayoraz

unread,
Feb 26, 2013, 4:15:53 PM2/26/13
to wxpytho...@googlegroups.com
> --
> 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 wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Hi,

I do use checkboxes in ObjectListView, but I never tried
CreateCheckStateColumn(). I do insert the checkbox when creating the
column object. Example:

myColumn = ColumnDefn(myColTitle, "center",
valueGetter="attributeValue",
valueSetter=self.myValueMethod,
checkStateGetter="attributeBool",
checkStateSetter=self.myCheckBoxMethod)

where 'attributeValue' is the value to be passed to the row (so, for
example, an attribute of the list of object you want to display),
'self.myValueMethod' is the method that is run when entering a new
value, 'attributeBool', the bool value for the check box (also an
attribute of the object for example), 'self.myCheckBoxMethod' the method
that is run when clicking on the check box.

In your code, this would go in self.resultsOlv.SetColumns(). It is not
required to have 'valueSetter' and 'valueGetter'. Just make the column
narrow enough so that only the check box is displayed, if nothing is to
be seen nearby the check box.

It works well, but I'm not sure this is the answer you are hoping for ...

Raphael

Daniel Hyams

unread,
Feb 26, 2013, 4:32:47 PM2/26/13
to wxpytho...@googlegroups.com

Daniel Hyams

On Feb 26, 2013 4:15 PM, "Raphael Mayoraz" <may...@netplus.ch> wrote:
On 2/26/2013 6:28 PM, Mike Driscoll wrote:
Hi,

I'm trying to figure out how to insert a checkbox in the ObjectListView widget. According to http://objectlistview.sourceforge.net/python/recipes.html?highlight=checkbox#recipe-checkbox I am supposed to be able to use the CreateCheckStateColumn() method, but that doesn't appear to work for me. I have attached a small runnable example. Can anyone see what I'm doing wrong?

I am using Python 2.6.6 on Windows 7 with wxPython 2.8.12.1

Thanks,
Mike
--
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 wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


Hi,

I do use checkboxes in ObjectListView, but I never tried CreateCheckStateColumn(). I do insert the checkbox when creating the column object. Example:

myColumn = ColumnDefn(myColTitle, "center",
                      valueGetter="attributeValue",
                      valueSetter=self.myValueMethod,
checkStateGetter="attributeBool",
checkStateSetter=self.myCheckBoxMethod)

where 'attributeValue' is the value to be passed to the row (so, for example, an attribute of the list of object you want to display), 'self.myValueMethod' is the method that is run when entering a new value, 'attributeBool', the bool value for the check box (also an attribute of the object for example), 'self.myCheckBoxMethod' the method that is run when clicking on the check box.

In your code, this would go in self.resultsOlv.SetColumns(). It is not required to have 'valueSetter' and 'valueGetter'. Just make the column narrow enough so that only the check box is displayed, if nothing is to be seen nearby the check box.

It works well, but I'm not sure this is the answer you are hoping for ...

Raphael

--
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 wxpython-users+unsubscribe@googlegroups.com.

Werner

unread,
Feb 26, 2013, 4:56:30 PM2/26/13
to wxpytho...@googlegroups.com
Hi Mike,

On 26/02/2013 18:28, Mike Driscoll wrote:
> Hi,
>
> I'm trying to figure out how to insert a checkbox in the
> ObjectListView widget. According to
> http://objectlistview.sourceforge.net/python/recipes.html?highlight=checkbox#recipe-checkbox
> I am supposed to be able to use the CreateCheckStateColumn() method,
> but that doesn't appear to work for me. I have attached a small
> runnable example. Can anyone see what I'm doing wrong?
>
I have all my olv based lists defined in a table, which is based on the
the code in medialocker.

Assuming that there would be a column 'published' in the book table the
last entry would do the trick.

olvEntries[u'Book'] = [
[u'publisher', 0, 150, u'publisher', u'name',
None, None, True, u'', u'left', u'', u''],
[u'title', 1, 150, None, u'title',
None, None, False, u'', u'left', u'', u''],
[u'author', 2, 150, u'person', u'full_name',
None, None, False, u'', u'left', u'', u''],
[u'isbn', 3, 150, None, u'isbn',
None, None, False, u'', u'left', u'', u''],
[u'published', 4, 30, None, u'published', None,
u'published', True, u'', u'centre', u'', u'', False],
]

You would also need to update 'mlsrc.libui.olvdefs.py' to support that
column.

The code in 'mlsrc.base_app.doCreateOLVEntry' would then create the
entries in the 'olvlist' table.

Werner

Werner

unread,
Feb 27, 2013, 2:09:54 AM2/27/13
to wxpytho...@googlegroups.com
Forgot to mention that the olv stuff done in medialocker allows the user
to configure the layout of the list, i.e. he/she can drag column headers
to where they want them, size the columns and then save this
configuration to the database through the list context menu (within the
list, not on the header).

Werner

Mike Driscoll

unread,
Feb 27, 2013, 12:21:15 PM2/27/13
to wxpytho...@googlegroups.com
Hi Raphael,


On Tuesday, February 26, 2013 3:15:53 PM UTC-6, rapmay wrote:
On 2/26/2013 6:28 PM, Mike Driscoll wrote:
> Hi,
>
> I'm trying to figure out how to insert a checkbox in the
> ObjectListView widget. According to
> http://objectlistview.sourceforge.net/python/recipes.html?highlight=checkbox#recipe-checkbox
> I am supposed to be able to use the CreateCheckStateColumn() method,
> but that doesn't appear to work for me. I have attached a small
> runnable example. Can anyone see what I'm doing wrong?
>
> I am using Python 2.6.6 on Windows 7 with wxPython 2.8.12.1
>
> Thanks,
> Mike
> --
> 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 wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Hi,

I do use checkboxes in ObjectListView, but I never tried
CreateCheckStateColumn(). I do insert the checkbox when creating the
column object.

Well, CreateCheckStateColumn made adding the check boxes really easy. And it's really simple to find out which ones are checked via the GetCheckedObjects() method.

 
Example:

myColumn = ColumnDefn(myColTitle, "center",
                       valueGetter="attributeValue",
                       valueSetter=self.myValueMethod,
checkStateGetter="attributeBool",
checkStateSetter=self.myCheckBoxMethod)

where 'attributeValue' is the value to be passed to the row (so, for
example, an attribute of the list of object you want to display),
'self.myValueMethod' is the method that is run when entering a new
value, 'attributeBool', the bool value for the check box (also an
attribute of the object for example), 'self.myCheckBoxMethod' the method
that is run when clicking on the check box.

In your code, this would go in self.resultsOlv.SetColumns(). It is not
required to have 'valueSetter' and 'valueGetter'. Just make the column
narrow enough so that only the check box is displayed, if nothing is to
be seen nearby the check box.

It works well, but I'm not sure this is the answer you are hoping for ...

Raphael

I'm glad to know of another way of doing this, although I don't really understand how it works. Thanks for the info though.

- Mike
 

Werner

unread,
Feb 28, 2013, 4:20:21 AM2/28/13
to wxpytho...@googlegroups.com
Hi Mike,

Hope didn't confuse you with my last answer, as I was not answering your
question:-[ .

I thought you wanted to show a checkbox for a boolean value and not
activate the option to select multiple objects in the list.

I needed to get my mind of a problem I can't find in my code, so had a
look at medialocker and made a few updates.

1. to activate a checkstatecolum you can now just do:

e.g. in mlsrc.controllers.base_list.setUpOlv:

self.theOlv.initOLV(self.modelName, checkstatecol=1)

2. I added a demo column for boolean value to be represented as a
checkbox in the list.

Note that the current code of MediaLocker has problems with 2.9.x, so I
force it to use 2.8. The problems are probably to do with some sizing
issue for the search controls, had the same in my own stuff, so when I
have a moment I will look at this and will push a fix.

Werner

Mike Driscoll

unread,
Feb 28, 2013, 9:40:08 AM2/28/13
to wxpytho...@googlegroups.com
Hi Werner,


On Thursday, February 28, 2013 3:20:21 AM UTC-6, werner wrote:
Hi Mike,

Hope didn't confuse you with my last answer, as I was not answering your
question:-[ .

Don't worry about it. I figured it out from what someone else said.

 

I thought you wanted to show a checkbox for a boolean value and not
activate the option to select multiple objects in the list.

I needed to get my mind of a problem I can't find in my code, so had a
look at medialocker and made a few updates.

1. to activate a checkstatecolum you can now just do:

e.g. in mlsrc.controllers.base_list.setUpOlv:

self.theOlv.initOLV(self.modelName, checkstatecol=1)

2. I added a demo column for boolean value to be represented as a
checkbox in the list.

Note that the current code of MediaLocker has problems with 2.9.x, so I
force it to use 2.8.  The problems are probably to do with some sizing
issue for the search controls, had the same in my own stuff, so when I
have a moment I will look at this and will push a fix.

Werner


Thanks for updating the project. I think we still get a little activity / interest in it from time to time.

- Mike
 
Reply all
Reply to author
Forward
0 new messages