Simple popup dialog opens too long with Chaco

179 Views Asked by At

I need the small popup dialog to appear at cursor position when user clicks my Chaco plot. But when there are many points in the plot (~100.000) the popup window loads too slow (1-2 seconds) and not responsive in the beginning. So the application becomes not very interactive.. I have no idea how I can speed it up. Can you suggest any solution, workaround or advice something?

Code example:

from chaco.api import ArrayPlotData, Plot, BaseTool
from enable.component_editor import ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
import numpy as np
from PyQt4 import QtGui, QtCore


# simple popup with button and lineedit
class Dialog(QtGui.QDialog):
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.Popup)
        self.resize(100, 50)
        self.layout = QtGui.QVBoxLayout(self)
        self.lineedit = QtGui.QLineEdit()
        self.button = QtGui.QPushButton('button')  
        self.layout.addWidget(self.button)
        self.layout.addWidget(self.lineedit)


# new Tool to process right click over plot
class RightClickTool(BaseTool):
    def __init__(self, *args, **kw):
        self.dlg = Dialog()
        super(RightClickTool, self).__init__(*args, **kw)

    def normal_right_down(self, event):
        self.dlg.show()  # show the dialog on right click
        event.handled = True


class MyPlot(HasTraits):

    plot = Instance(Plot)
    traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False))

    def __init__(self):
        super(MyPlot, self).__init__()

        # data to plot
        x = np.linspace(0, 1, 10**6)
        y = np.random.rand(10**6)
        plotdata = ArrayPlotData(x=x, y=y)

        plot = Plot(plotdata)
        plot.tools.append(RightClickTool(plot))
        plot.plot(('x', 'y'))
        self.plot = plot


lineplot = MyPlot()
lineplot.configure_traits()
0

There are 0 best solutions below