Note that there are some explanatory texts on larger screens.

plurals
  1. POPython GUI Drag/Drop Problems
    primarykey
    data
    text
    <p>I am having problems with a GUI I'm working on. The idea is to have a tree list of signals and be able to drag them onto the plot. Eventually having a long list of signals and multiple plots etc.. However the code segmentation faults after a seemingly random number of drag &amp; drops (sometimes just one). I've stripped the code to the bare bones so it plots the same curve each time and there is only one 'signal'to choose from; in this case just x^2.</p> <p>Below I've posted the code with the packages it requires.</p> <pre><code>import wx import random import scipy import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.figure import Figure class MainFrame(wx.Frame): ''' Create the mainframe on which all of the other panels are placed. ''' def __init__(self): wx.Frame.__init__(self, parent=None, title="GUI", size=(998,800)) self.SetBackgroundColour('#CCCCCC') self.GUIBox = wx.BoxSizer(wx.HORIZONTAL) self.P = PlotWindow(self) self.DD = DragDrop(self) self.GUIBox.Add(self.DD, 0, wx.LEFT | wx.ALIGN_TOP) self.GUIBox.Add(self.P, 0, wx.LEFT | wx.ALIGN_TOP) self.SetSizer(self.GUIBox) return class PlotWindow(wx.Panel): def __init__(self, parent): wx.Window.__init__(self, parent) self.Figure = Figure() self.Figure.set_size_inches(8.56, 9.115) self.C = FigureCanvasWxAgg(self, -1, self.Figure) self.SP = self.Figure.add_subplot(111) self.a = [0,1,2,3,4,5] self.b = [0,1,4,9,16,25] self.signals = [self.b] def rePlot(self): self.SP.clear() c = scipy.zeros(6) for i in range(0, 6, 1): c[i] = self.b[i]*random.uniform(0, 2) self.SP.plot(self.a,c) self.C.draw() class MyTextDropTarget(wx.TextDropTarget): def __init__(self, objt): wx.TextDropTarget.__init__(self) self.Objt = objt def OnDropText(self, x, y, data): self.Objt.rePlot() class DragDrop(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, style=wx.BORDER_RAISED) self.SetBackgroundColour('#CCCCCC') self.tree = wx.TreeCtrl(self, -1, size=(270,700)) # Add root root = self.tree.AddRoot("Signals") self.tree.AppendItem(root, "Square") dt = MyTextDropTarget(self.GetParent().P) self.GetParent().P.SetDropTarget(dt) self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnDragInit) self.VBox = wx.BoxSizer(wx.VERTICAL) self.VBox.Add(self.tree, 0) self.SetSizer(self.VBox) def OnDragInit(self, event): text = self.tree.GetItemText(event.GetItem()) tdo = wx.TextDataObject(text) tds = wx.DropSource(self.tree) tds.SetData(tdo) tds.DoDragDrop(True) class App(wx.App): def OnInit(self): self.dis = MainFrame() self.dis.Show() return True app = App() app.MainLoop() </code></pre> <p>I've tried to take out as much unnecessary code as possible; any help would be much appreciated!</p> <p>Cheers!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload