Problems using SetDropTarget

24 views
Skip to first unread message

Claudia Frank

unread,
Nov 25, 2016, 5:48:50 PM11/25/16
to wxPython-users
Hello,

If I run this code I do get a segmentation fault on exit.
I figured out, that this happens only when using SetDropTarget more than once.
Did I miss something?

Cheers
Claudia


Running on
Distributor ID : Ubuntu
Description    : Linux Lite 2.8
Release        : 14.04
Codename       : trusty

3.0.2.0 gtk2 (classic)
2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2]

Segmentation fault
#!/usr/bin/python
# -*- coding: utf-8 -*-

import wx
import wx.lib.agw.fourwaysplitter as fws

class DROP_TARGET(wx.DropTarget):
   
def __init__(self):
       
super(DROP_TARGET, self).__init__()
       
self.data = wx.BitmapDataObject()
       
self.SetDataObject(self.data)

   
def OnEnter(self, x, y, d):
       
return d

   
def OnLeave(self):
       
pass

   
def OnDrop(self, x, y):
       
return True

   
def OnDragOver(self, x, y, d):
       
return d

   
def OnData(self, x, y, d):
       
self.GetData()
       
return d

class DemoFrame(wx.Frame):

   
def __init__(self, *args, **kwargs):
       
super(DemoFrame, self).__init__(*args, **kwargs)

       
self.drop_target = DROP_TARGET()
        splitter
= fws.FourWaySplitter(self, -1, agwStyle=wx.SP_LIVE_UPDATE)
       
for colour in [wx.RED, wx.WHITE, wx.BLUE, wx.GREEN]:
            panel
= wx.Panel(splitter)
            panel
.SetBackgroundColour(colour)
           
# if colour is wx.RED:
            panel
.SetDropTarget(self.drop_target)
            splitter
.AppendWindow(panel)

           
def main():
    app
= wx.App(redirect=False)
    _frame
= DemoFrame(None, title='TEMPLATE', size=(800,600))
    app
.SetTopWindow(_frame)
    _frame
.Show(True)
    app
.MainLoop()
    app
= None
   
main
()

Claudia Frank

unread,
Nov 26, 2016, 10:51:51 AM11/26/16
to wxPython-users
Hello,

looks like I found the reason, the drop target instance cannot be reused,
instead it is needed to recreate it every time you need to assign it
to a different control. Not sure if this works as expected but if so,
maybe a hint in the documentation might be useful.

Thanks
Claudia
Reply all
Reply to author
Forward
0 new messages