【发布时间】:2015-01-29 01:52:48
【问题描述】:
我有两个功能。
第一个函数响应一个键事件,该事件将我屏幕上已经绘制的所有内容向左移动(向右平移)。
第二个函数是我的 onMove 处理程序,当我的鼠标移动时,它会在当前光标位置重新绘制一条线。 (想想在 cad 程序中画一条线)
我的问题是,当我的屏幕慢慢向右平移时,我的鼠标动作没有被捕捉到。在捕捉鼠标移动的同时允许绘制对象的运动最有效的是什么?
我怀疑多线程是答案。但是,我按照“wxPython in Action”和 wx.CallAfter() 进行了尝试,但没有成功。我可以使程序在该配置下成功运行,但鼠标移动问题仍然存在。
这处理通过按“f”键启动的“向右平移”命令:
elif key == 70:
timeincrement = .01
t = .5 # number of seconds we want to move
a = -500 # pixels per second squared
v = 1000 # initial pixel velocity pixels per second
x = 0 # starting time
start = copy(parent.xloc)
while x <= t:
x = x + timeincrement
# Below is the current location of the center of the screen
# based on the acceleration values listed above
dist = ((v * x) + (.5 * a * x ** 2)) / (72 * parent.zoom)
sleep(timeincrement)
parent.xloc = start + dist
parent.drawingpanel.updateDrawing()
这会处理 EVT_MOTION
def onMove(self, evt):
position = evt.GetPosition()
self.parent.mousepos = (position.x, position.y)
self.updateDrawing()
任何帮助将不胜感激。
【问题讨论】:
标签: python multithreading wxpython