Dragging tree items with italic font

I’m having a little trouble tracking down the solution
to this problem. Whenever a tree item with an italic font is in my tree, I get
the following error when I start dragging:

Traceback (most recent call last):

File
“C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”, line
14554, in

lambda event: event.callable(*event.args,

**event.kw) )

File “D:\Documents and
Settings\rickkylw\Desktop\pyswigtest.py”, line 72, in DoDragDrop

dd.setObject(self.drag_data)

File “D:\Documents and
Settings\rickkylw\Desktop\pyswigtest.py”, line 15, in setObject

self.SetData(cPickle.dumps(obj))

File “C:\Python25\lib\copy_reg.py”, line
69, in _reduce_ex

raise TypeError, "can't pickle %s

objects" % base.name

TypeError: can’t pickle PySwigObject objects

See the attached example. To reproduce, try to drag the
child node. This will work fine. Now expand child and try to drag something
else and the error occurs. If Child is collapsed again, dragging works.

I’ve been trying to track this down for quite some
time and I just now discovered the cause of this. I’m using Windows XP
with Python 2.5 and wxpython 2.8.8.0.

Any help would be greatly appreciated.

-Kyle Rickey

tree_drag_test.py (2.22 KB)

Hello,

···

On Mon, Dec 22, 2008 at 2:29 PM, Rickey, Kyle W Kyle.Rickey@bakerhughes.com wrote:

I’m having a little trouble tracking down the solution
to this problem. Whenever a tree item with an italic font is in my tree, I get
the following error when I start dragging:

Traceback (most recent call last):

File
“C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”, line
14554, in

lambda event: event.callable(*event.args,

**event.kw) )

File “D:\Documents and
Settings\rickkylw\Desktop\pyswigtest.py”, line 72, in DoDragDrop

dd.setObject(self.drag_data)

File “D:\Documents and
Settings\rickkylw\Desktop\pyswigtest.py”, line 15, in setObject

self.SetData(cPickle.dumps(obj))

File “C:\Python25\lib\copy_reg.py”, line
69, in _reduce_ex

raise TypeError, "can't pickle %s

objects" % base.name

TypeError: can’t pickle PySwigObject objects

The error is quite clear. What is ‘obj’ in ‘self.SetData(cPickle.dumps(obj))’. You cant pickle most most wx objects directly.

Cody

Cody

Thanks Cody.

obj is an object that has an items property.
items is a list of the tree items that are being dragged.

def setObject(self, obj):

if obj != None:

                    print

obj.items

        self.SetData(cPickle.dumps(obj))

obj.items is
[<wx.lib.customtreectrl.GenericTreeItem instance at 0x01AD7F08>]. So
I guess I’m confused why I can pickle that TreeItem when there’s no
italic tree items.

-Kyle Rickey

···

From:
wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Cody Precord
Sent: Monday, December 22, 2008
2:39 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users]
Dragging tree items with italic font

Hello,

On Mon, Dec 22, 2008 at 2:29 PM, Rickey, Kyle W Kyle.Rickey@bakerhughes.com wrote:

I’m
having a little trouble tracking down the solution to this problem. Whenever a
tree item with an italic font is in my tree, I get the following error when I
start dragging:

Traceback
(most recent call last):

File “C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”,
line 14554, in

lambda event: event.callable(*event.args, **event.kw) )

File “D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py”, line
72, in DoDragDrop

dd.setObject(self.drag_data)

File “D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py”, line
15, in setObject

self.SetData(cPickle.dumps(obj))

File “C:\Python25\lib\copy_reg.py”, line 69, in _reduce_ex

raise TypeError, “can’t pickle %s objects” % base.name

TypeError:
can’t pickle PySwigObject objects

The error is quite clear. What is ‘obj’ in ‘self.SetData(cPickle.dumps(obj))’.
You cant pickle most most wx objects directly.

Cody

Cody

Ahh, I got it figured out now. Instead of
keeping a list of the tree items I’m dragging, I can just keep of list of
the pyData (self.tree.GetPyData) for each item. So my code was a simple change to:

drag_data =
DragObject([self.tree.GetPyData(s) for s in selection])

and then a small change in my code that
handles the drop. Thanks for reminding me about pickling wx objects.

-Kyle Rickey

···

From: wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org
[mailto:wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org]
On Behalf Of Rickey, Kyle W
Sent: Monday, December 22, 2008
2:58 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users]
Dragging tree items with italic font

Thanks Cody.

obj is an object that has an items
property. items is a list of the tree items that are being dragged.

def setObject(self, obj):

if obj != None:

        print

obj.items

self.SetData(cPickle.dumps(obj))

obj.items is
[<wx.lib.customtreectrl.GenericTreeItem instance at 0x01AD7F08>].
So I guess I’m confused why I can pickle that TreeItem when there’s
no italic tree items.

-Kyle Rickey


From:
wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Cody Precord
Sent: Monday, December 22, 2008
2:39 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users]
Dragging tree items with italic font

Hello,

On Mon, Dec 22, 2008 at 2:29 PM, Rickey, Kyle W Kyle.Rickey@bakerhughes.com wrote:

I’m
having a little trouble tracking down the solution to this problem. Whenever a
tree item with an italic font is in my tree, I get the following error when I
start dragging:

Traceback
(most recent call last):

File “C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”,
line 14554, in

lambda event: event.callable(*event.args, **event.kw) )

File “D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py”, line
72, in DoDragDrop

dd.setObject(self.drag_data)

File “D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py”, line
15, in setObject

self.SetData(cPickle.dumps(obj))

File “C:\Python25\lib\copy_reg.py”, line 69, in _reduce_ex

raise TypeError, “can’t pickle %s objects” % base.name

TypeError:
can’t pickle PySwigObject objects

The error is quite clear. What is ‘obj’ in ‘self.SetData(cPickle.dumps(obj))’.
You cant pickle most most wx objects directly.

Cody

Cody

Hello,

···

On Mon, Dec 22, 2008 at 2:58 PM, Rickey, Kyle W Kyle.Rickey@bakerhughes.com wrote:

Thanks Cody.

obj is an object that has an items property.
items is a list of the tree items that are being dragged.

def setObject(self, obj):

if obj != None:

                    print

obj.items

        self.SetData(cPickle.dumps(obj))

obj.items is
[<wx.lib.customtreectrl.GenericTreeItem instance at 0x01AD7F08>]. So
I guess I’m confused why I can pickle that TreeItem when there’s no
italic tree items.

You will need to look at how GenericTreeItem is implemented and

http://docs.python.org/library/pickle.html#what-can-be-pickled-and-unpickled

From a very brief look at the GenericTreeItem class I would say its is because some of the items in its dict are not picklable (i.e it keeps reference to its parent window which is a swig object, ect…).

Cody

Hi Kyle,

Would you mind posting your working draggable-tree code ?

I’ll be working on tree items that need to change in response to outside input, and wanted to see how your code works.

Alas, your original code, while displaying a tree on my screen, does not allow me to drag items (even non italics).

Thanks,

Ron.

···

From: Rickey, Kyle W [mailto:Kyle.Rickey@bakerhughes.com]
Sent: Monday, December 22, 2008 23:11
To: wxpython-users@lists.wxwidgets.org
Subject:
RE: [wxpython-users] Dragging tree items with italic font [SOLVED]

Ahh, I got it figured out now. Instead of keeping a list of the tree items I’m dragging, I can just keep of list of the pyData (self.tree.GetPyData) for each item. So my code was a simple change to:

drag_data = DragObject([self.tree.GetPyData(s) for s in selection])

and then a small change in my code that handles the drop. Thanks for reminding me about pickling wx objects.

-Kyle Rickey


From:
wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org [mailto:wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org] On Behalf Of Rickey, Kyle W
Sent: Monday, December 22, 2008 2:58 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] Dragging tree items with italic font

Thanks Cody.

obj is an object that has an items property. items is a list of the tree items that are being dragged.

def setObject(self, obj):

if obj != None:

                      print obj.items
          self.SetData(cPickle.dumps(obj))

obj.items is [<wx.lib.customtreectrl.GenericTreeItem instance at 0x01AD7F08>]. So I guess I’m confused why I can pickle that TreeItem when there’s no italic tree items.

-Kyle Rickey


From:
wxpython-users-bounces@lists.wxwidgets.org [mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Cody Precord
Sent: Monday, December 22, 2008 2:39 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Dragging tree items with italic font

Hello,

On Mon, Dec 22, 2008 at 2:29 PM, Rickey, Kyle W <Kyle.Rickey@bakerhughes.com > wrote:

I’m having a little trouble tracking down the solution to this problem. Whenever a tree item with an italic font is in my tree, I get the following error when I start dragging:

Traceback (most recent call last):

File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14554, in <lambda>
  lambda event: event.callable(*event.args, **[event.kw](http://event.kw)) )
File "D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py", line 72, in DoDragDrop
  dd.setObject(self.drag_data)
File "D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py", line 15, in setObject
  self.SetData(cPickle.dumps(obj))
File "C:\Python25\lib\copy_reg.py", line 69, in _reduce_ex
  raise TypeError, "can't pickle %s objects" % base.__name__

TypeError: can’t pickle PySwigObject objects

The error is quite clear. What is ‘obj’ in ’ self.SetData(cPickle.dumps(obj))'. You cant pickle most most wx objects directly.

Cody

Cody

Ron,

Attached is my code that I cleaned up a
bit. Note in this example you just drag and drop from the tree back onto the
tree. Ideally, you would have some other control that you dragged onto, but it
should work the same. For my needs all I needed was the PyData for each tree
item so it was fairly easy to pass that info onto my drop target. HTH.

-Kyle Rickey

tree_drag_test.py (3.04 KB)

···

From:
wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Barak, Ron
Sent: Tuesday, December 23, 2008
2:04 AM
To:
+KyleRickey+comverse+f94ad60820.Kyle.Rickey#bakerhughes.com@spamgourmet.com
Cc:
wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users]
Dragging tree items with italic font [SOLVED]

Hi Kyle,

Would you mind posting your working
draggable-tree code ?

I’ll be working on tree items that need to change in
response to outside input, and wanted to see how your code works.

Alas, your original code, while displaying a tree on my
screen, does not allow me to drag items (even non italics).

Thanks,

Ron.


From: Rickey,
Kyle W [mailto:Kyle.Rickey@bakerhughes.com]
Sent: Monday, December 22, 2008
23:11
To: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users]
Dragging tree items with italic font [SOLVED]

Ahh, I got it figured out now. Instead of
keeping a list of the tree items I’m dragging, I can just keep of list of
the pyData (self.tree.GetPyData) for each item. So my code was a simple change
to:

drag_data =
DragObject([self.tree.GetPyData(s) for s in selection])

and then a small change in my code that
handles the drop. Thanks for reminding me about pickling wx objects.

-Kyle Rickey


From: wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org
[mailto:wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org]
On Behalf Of Rickey, Kyle W
Sent: Monday, December 22, 2008
2:58 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users]
Dragging tree items with italic font

Thanks Cody.

obj is an object that has an items
property. items is a list of the tree items that are being dragged.

def setObject(self, obj):

if obj != None:

        print

obj.items

self.SetData(cPickle.dumps(obj))

obj.items is
[<wx.lib.customtreectrl.GenericTreeItem instance at 0x01AD7F08>].
So I guess I’m confused why I can pickle that TreeItem when there’s
no italic tree items.

-Kyle Rickey


From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Cody Precord
Sent: Monday, December 22, 2008
2:39 PM
To:
wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users]
Dragging tree items with italic font

Hello,

On Mon, Dec 22, 2008 at 2:29 PM, Rickey, Kyle W Kyle.Rickey@bakerhughes.com > wrote:

I’m
having a little trouble tracking down the solution to this problem. Whenever a
tree item with an italic font is in my tree, I get the following error when I
start dragging:

Traceback
(most recent call last):

File “C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”,
line 14554, in

lambda event: event.callable(*event.args, **event.kw) )

File “D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py”, line
72, in DoDragDrop

dd.setObject(self.drag_data)

File “D:\Documents and Settings\rickkylw\Desktop\pyswigtest.py”, line
15, in setObject

self.SetData(cPickle.dumps(obj))

File “C:\Python25\lib\copy_reg.py”, line 69, in _reduce_ex

raise TypeError, “can’t pickle %s objects” % base.name

TypeError:
can’t pickle PySwigObject objects

The error is quite clear. What is ‘obj’ in ‘self.SetData(cPickle.dumps(obj))’.
You cant pickle most most wx objects directly.

Cody

Cody