DataViewCtrl and ComboBox

Hi All,

I need to build a GUI in python, using wx.

Is there a reasonable -I mean, reasonably straightforward- way to have an editable list-like widget where the editing control would be a combo box? A ChoiceCtrl could also work for me.

The CustomRenderer.py sample from the source distribution (version wxPython_Phoenix-2.9.5.81-r73904) does not seem to be working: I get a “TypeError: invalid result type from MyCustomRenderer.GetValueFromEditorCtrl() … Unexpected type (“null”) in wxVariant.” when running it.

Does it mean that ‘wx.dataview’ is not currently working, or is there a simple work-around? Can anyone point me to a possible direction?

Thanks in advance for your help

nolfac_dev wrote:

Hi All,

I need to build a GUI in python, using wx.
Is there a reasonable -I mean, reasonably straightforward- way to have
an editable list-like widget where the editing control would be a combo
box? A ChoiceCtrl could also work for me.

Not out of the box, but EditableListBox is generic code so it probably would not be too hard to port it to Python and then make it possible to use different types of widgets for the edit control.

The CustomRenderer.py sample from the source distribution (version
wxPython_Phoenix-2.9.5.81-r73904) does not seem to be working: I get a
"TypeError: invalid result type from
MyCustomRenderer.GetValueFromEditorCtrl() ... Unexpected type ("null")
in wxVariant." when running it.

Which platform? Do you have to do anything to trigger the exception?

···

--
Robin Dunn
Software Craftsman

Hi Robin,

thanks for your answer.

1) Regarding CustomRenderer.py:

I’m on linux (ubuntu 12.10) and Python 2.7. After launching the sample program, if you edit and change one of the cells, the exception is triggered when you end the edition. I groped for a solution, and found out that the return value from GetValueFromEditorCtrl could be changed as follows to remove the exception:

class MyCustomRenderer(dv.DataViewCustomRenderer):

def GetValueFromEditorControl(self, editor):

    ...

    **return True, value**

(instead of return value). In the C++ code, this function returns a bool (probably a validate/cancel flag?), and the value of the editor control is returned through a parameter passed by reference. Does the solution above make sense?

Also, I get an exception at the beginning of the execution when launching CustomRenderer.py;

NotImplementedError: DataViewIndexListModel.GetColumnType() is abstract and must be overriden

I added to IndexListModel.py the following:

class TestModel(dv.DataViewIndexListModel):

def GetColumnType(self, col):

** return “string”**

which removed the exception.

2) Regarding the ComboBox as edit control in dataview:

I’ll have a closer look at EditableListBox, but for the time being, the dataview solution, together with a custom renderer seems to better fit my needs (I need multiple columns, and if I can make it work, I will re-use it elsewhere in my app in order to simplify the GUI).

Based on the sample code in CustomRenderer.py (with the corrections above), I tried to use a ComboBox in place of the TextCtrl, but this does not work for now. The control is not properly drawn, the drop down is not displayed correctly, and the focus is not handled correctly (it seems), when you click outside of the drop down control. I’ll do some more experiments to see if I can make it work (though the display does not work properly, keyboard events are handled correctly, and I can change values with up/down arrows and validate with enter).

Can you point me to some direction? Maybe use a ComboCtrl, in order to get more control on the drawing/focus? or maybe look at the similar functionality for grid?

I also noticed that there is a wxDataViewChoiceRenderer in wxWidgets. Is it not present in Phoenix for a good reason, or is it on some Todo List? (I do not know sip at all, but I can try to explore this route, though it probably is a bit difficult for me…)

Thanks for your help.

Vincent

···

On Wednesday, May 15, 2013 7:53:54 PM UTC+2, Robin Dunn wrote:

nolfac_dev wrote:

Hi All,

I need to build a GUI in python, using wx.

Is there a reasonable -I mean, reasonably straightforward- way to have

an editable list-like widget where the editing control would be a combo

box? A ChoiceCtrl could also work for me.

Not out of the box, but EditableListBox is generic code so it probably
would not be too hard to port it to Python and then make it possible to
use different types of widgets for the edit control.

The CustomRenderer.py sample from the source distribution (version

wxPython_Phoenix-2.9.5.81-r73904) does not seem to be working: I get a

"TypeError: invalid result type from

MyCustomRenderer.GetValueFromEditorCtrl() … Unexpected type (“null”)

in wxVariant." when running it.

Which platform? Do you have to do anything to trigger the exception?


Robin Dunn

Software Craftsman

http://wxPython.org

nolfac_dev wrote:

Hi Robin,

thanks for your answer.

*_1) Regarding CustomRenderer.py:_*
I'm on linux (ubuntu 12.10) and Python 2.7. After launching the sample
program, if you edit and change one of the cells, the exception is
triggered when you end the edition. I groped for a solution, and found
out that the return value from GetValueFromEditorCtrl could be changed
as follows to remove the exception:

class MyCustomRenderer(dv.DataViewCustomRenderer):
...
def GetValueFromEditorControl(self, editor):
...
*return True, value*

(instead of return value). In the C++ code, this function returns a bool
(probably a validate/cancel flag?), and the value of the editor control
is returned through a parameter passed by reference. Does the solution
above make sense?

Yes, thanks.

Also, I get an exception at the beginning of the execution when
launching CustomRenderer.py;
NotImplementedError: DataViewIndexListModel.GetColumnType() is abstract
and must be overriden

I added to IndexListModel.py the following:

class TestModel(dv.DataViewIndexListModel):
...
*def GetColumnType(self, col):*
*return "string"
*
...

which removed the exception.

Thanks.

*_2) Regarding the ComboBox as edit control in dataview:_*
I'll have a closer look at EditableListBox, but for the time being, the
dataview solution, together with a custom renderer seems to better fit
my needs (I need multiple columns, and if I can make it work, I will
re-use it elsewhere in my app in order to simplify the GUI).
Based on the sample code in CustomRenderer.py (with the corrections
above), I tried to use a ComboBox in place of the TextCtrl, but this
does not work for now. The control is not properly drawn, the drop down
is not displayed correctly, and the focus is not handled correctly (it
seems), when you click outside of the drop down control. I'll do some
more experiments to see if I can make it work (though the display does
not work properly, keyboard events are handled correctly, and I can
change values with up/down arrows and validate with enter).
Can you point me to some direction? Maybe use a ComboCtrl, in order to
get more control on the drawing/focus? or maybe look at the similar
functionality for grid?
I also noticed that there is a wxDataViewChoiceRenderer in wxWidgets. Is
it not present in Phoenix for a good reason, or is it on some Todo List?
(I do not know sip at all, but I can try to explore this route, though
it probably is a bit difficult for me...)

I have a note in the Phoenix code that it is only available in the generic version of the dataview code (IOW, currently only on Windows and not OSX or GTK) so I have it commented out. I don't know if there are plans to change that.

···

--
Robin Dunn
Software Craftsman