python - Kivy 毫不拖延地捕获触摸

标签 python kivy

我试图在我的代码中实现 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/

相关文章:

python - Pydantic 枚举字段未转换为字符串

python - 暂停 python 脚本,直到事件发生而不挂起/阻塞 GUI

python - 如何使用 keras.backend.gradients() 获取梯度值

python - 直接修改二进制可执行文件而不损坏它的可能性

android - 使用 Python/Kivy 的简单条形码扫描器,适用于 Android 设备

python - 如何更改进度条kivy的颜色

python - Kivy VideoPlayer 全屏、循环和隐藏控件

Android:从 Kivy 后台服务播放声音

python - 古腾堡项目 Python 问题?

python - 超越关键字依赖的文本分类并推断实际含义