ユーザーが Chaco プロットをクリックしたときに、小さなポップアップ ダイアログがカーソル位置に表示されるようにする必要があります。しかし、プロットに多くのポイント (~100.000) がある場合、ポップアップ ウィンドウの読み込みが遅すぎ (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()