dataviectrl expand problem

Hi,

I have a program (it uses wxpython 3.0.0.0), which I have
been developing for some time. It uses the dataviewctrl controller, and works
like a directory tree, e.g. it can have files, which does not have
sub-directories, and directories, which can have sub-directories. I bind an
event controller to the EVT_DATAVIEW_ITEM_CONTEXT_MENU so it expands, when I
right click an element, but when I right click an element than the last of the
displayed items gets expanded, not the one wich I have right-clicked.
I tried using the e.GetItem() and the ctrl.GetSelection() functions to determine the selected item, without success.

The attached file contains a sample program, which shows my problem. I need to expand the elements from the code, because I want to save the current status of the expanded elements, and load it later.

So, is this a
bug in wxpython, or do I miss something?

Thanks in advance:

Zsolt Endreffy

wxtest.py (6.33 KB)

in on_expand(self, e) try:
item = e.GetEventObject().HitTest(e.GetPosition())

http://wxpython.org/Phoenix/docs/html/dataview.DataViewCtrl.html#dataview.DataViewCtrl.HitTest

···

On Wednesday, September 10, 2014 12:19:52 AM UTC-7, Zsolt Endreffy wrote:

Hi,

I have a program (it uses wxpython 3.0.0.0), which I have
been developing for some time. It uses the dataviewctrl controller, and works
like a directory tree, e.g. it can have files, which does not have
sub-directories, and directories, which can have sub-directories. I bind an
event controller to the EVT_DATAVIEW_ITEM_CONTEXT_MENU so it expands, when I
right click an element, but when I right click an element than the last of the
displayed items gets expanded, not the one wich I have right-clicked.
I tried using the e.GetItem() and the ctrl.GetSelection() functions to determine the selected item, without success.

The attached file contains a sample program, which shows my problem. I need to expand the elements from the code, because I want to save the current status of the expanded elements, and load it later.

So, is this a
bug in wxpython, or do I miss something?

Thanks in advance:

Zsolt Endreffy

Unfortunately it doesn’t work either. Anyone else with a suggestion?

  1. szeptember 10., szerda 18:51:48 UTC+2 időpontban Nathan McCorkle a következőt írta:
···

in on_expand(self, e) try:
item = e.GetEventObject().HitTest(e.GetPosition())

http://wxpython.org/Phoenix/docs/html/dataview.DataViewCtrl.html#dataview.DataViewCtrl.HitTest

On Wednesday, September 10, 2014 12:19:52 AM UTC-7, Zsolt Endreffy wrote:

Hi,

I have a program (it uses wxpython 3.0.0.0), which I have
been developing for some time. It uses the dataviewctrl controller, and works
like a directory tree, e.g. it can have files, which does not have
sub-directories, and directories, which can have sub-directories. I bind an
event controller to the EVT_DATAVIEW_ITEM_CONTEXT_MENU so it expands, when I
right click an element, but when I right click an element than the last of the
displayed items gets expanded, not the one wich I have right-clicked.
I tried using the e.GetItem() and the ctrl.GetSelection() functions to determine the selected item, without success.

The attached file contains a sample program, which shows my problem. I need to expand the elements from the code, because I want to save the current status of the expanded elements, and load it later.

So, is this a
bug in wxpython, or do I miss something?

Thanks in advance:

Zsolt Endreffy

Hello, you have an issue in your class CustomDataViewModel(dv.PyDataViewModel):
In

def GetParent(self, item):


node = self.ItemToObject(item)
if node.parent_node is None:
return dv.NullDataViewItem

return node.parent_node # replace this

    return self.ObjectToItem(node.parent_node) # by this

You have to return the parent DataViewItem, not the object the item is based on.

@Nathan:
You found out yourself in this thread (last post)
https://groups.google.com/forum/#!topicsearchin/wxpython-users/HitTest/wxpython-users/5UKy7us2o9M
that HitTest on a DataViewItem does not work (see the full thread for an explanation). Why are you proposing it again?
If it has changed in 3.0.1 Phoneix/Classic, ignore my rant.

···

On Thursday, September 11, 2014 11:00:02 AM UTC+2, Zsolt Endreffy wrote:

Unfortunately it doesn’t work either. Anyone else with a suggestion?

WOW!

I would have never found this bug on my own! Thank you so much, now everything works as it should. You are awesome!

Good point! I don’t use this widget so I didn’t remember the bug. I just tried in 3.0.1-classic(preview)-MSW and it still complains:

wx-3.0.1-msw-classic\wx\dataview.py", line 1817, in HitTest

return _dataview.DataViewCtrl_HitTest(*args, **kwargs)

TypeError: in method ‘DataViewCtrl_HitTest’, expected argument 4 of type ‘wxDataViewColumn *&’

···

On Thursday, September 11, 2014 4:17:34 AM UTC-7, nepix32 wrote:

@Nathan:
You found out yourself in this thread (last post)
https://groups.google.com/forum/#!topicsearchin/wxpython-users/HitTest/wxpython-users/5UKy7us2o9M
that HitTest on a DataViewItem does not work (see the full thread for an explanation). Why are you proposing it again?
If it has changed in 3.0.1 Phoneix/Classic, ignore my rant.