Chaco打开的简单弹出对话框太长了

时间:2015-08-09 17:13:31

标签: python performance pyqt enthought chaco

当用户点击我的Chaco图时,我需要小的弹出对话框出现在光标位置。但是当图中有很多点(~100.00)时,弹出窗口加载太慢(1-2秒)并且在开始时没有响应。所以应用程序变得不太互动..我不知道如何加快速度。你能建议任何解决方案,解决方法或建议吗?

代码示例:

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 个答案:

没有答案