我试图在我的代码中实现 touchtracer 演示示例。 Here is the original page
我意识到,由于必要的 touch.grab(self) 事件,跟踪仅在延迟(在您按住按钮之后)的情况下起作用。但是,我想立即在第一步之后立即看到踪迹。有没有办法在不干扰跟踪制作的情况下做到这一点?
编辑:“延迟”是指激活跟踪的保持 Action 。目前需要按下 + 按住才能启动追踪器。我希望能够随时随地进行追踪,而无需“保持”。
EDIT2:我觉得有必要解释一下我的 touchtracer 版本与其他人的有何不同,因为除了我之外似乎没有人会遇到这个问题。我在我的代码中嵌入了 touchtracer 代码并删除了垂直/水平线和标签。所以我的版本只有痕迹。这是我的 on_touch_down、on_touch_move 和 on_touch_up 的样子。
def on_touch_down(self, touch):
win = self.get_parent_window()
ud = touch.ud
ud['group'] = g = str(touch.uid)
pointsize = 5
ud['color'] = random()
with self.canvas:
Color(ud['color'], 1, 1, mode='hsv', group=g)
ud['lines'] = [
Point(points=(touch.x, touch.y), source='particle.png',
pointsize=pointsize, group=g)]
touch.grab(self)
return True
def on_touch_move(self, touch):
if touch.grab_current is not self:
return
ud = touch.ud
index = -1
while True:
try:
points = ud['lines'][index].points
oldx, oldy = points[-2], points[-1]
break
except:
index -= 1
if (oldx, oldy) == (touch.x, touch.y):
return
points = calculate_points(oldx, oldy, touch.x, touch.y)
if points:
try:
lp = ud['lines'][-1].add_point
for idx in range(0, len(points), 2):
lp(points[idx], points[idx + 1])
except GraphicException:
pass
def on_touch_up(self, touch):
if touch.grab_current is not self:
return
touch.ungrab(self)
ud = touch.ud
self.canvas.remove_group(ud['group'])
最佳答案
好吧,这看起来像是其中一个库的版本问题。我在运行在虚拟机上的 Ubuntu 14.0 上构建的 python2.7 中使用了它。我更新了与 python 相关的所有内容并使用库重新安装了 kivy,问题已解决。我仍然不确定是什么原因造成的,因为我没有在日志中收到任何错误消息,但看起来这是由于错误或未正确安装的 kivy 造成的。
关于python - Kivy 毫不拖延地捕获触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37933920/