Kivy触摸和键盘事件传递到桌面 [英] Kivy touch and keyboard events passing through to desktop

查看:114
本文介绍了Kivy触摸和键盘事件传递到桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Kivy 框架在Python 3中开发UI应用程序.Kivy应用程序是全屏的.每当我使用物理键盘执行触摸事件或键入时,底层的桌面环境将接收触摸和键盘事件以及我的Kivy应用程序.

I am using the Kivy framework to develop a UI application in Python 3. The Kivy application is fullscreen. Whenever I perform a touch event or type with my physical keyboard, the underlying desktop environment will receive the touch and keyboard events as well as my Kivy application.

例如,如果我在桌面上打开一个文本文件然后运行我的Kivy应用程序,则可以在Kivy应用程序处于前台(全屏)时盲目地在文本文件中键入文本. Kivy应用程序会忽略物理键盘输入,因为我在配置文件中将keyboard_mode选项设置为dock.

For example, if I open a text file on my desktop and then run my Kivy application, I am able to blindly type text into the text file while the Kivy application is in the foreground (fullscreen). The Kivy application ignores the physical keybaord input as it should since I have the keyboard_mode option set to dock in my configuration file.

触摸事件可以在我的Kivy应用程序中正常工作,我能够选择执行其指定操作的按钮;但是,触摸事件也将传递到桌面.我盲目地双击我的Kivy应用程序,然后返回桌面以找到一系列打开的应用程序(通过我的桌面上的快捷方式),从而意识到了这一点. Raspberry Pi社区的成员对此问题也无济于事: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=132054 .

Touch events work in my Kivy application as they should, I am able to select buttons which perform their designated operations; however, the touch event will also be passed through to the desktop. I am aware of this by blindly double clicking in my Kivy application and then returning to the desktop to find a slew of applications opened (through shortcuts on my desktop). A member of the Raspberry Pi community has also had this issue to no avail: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=132054.

这是我简单的 main.kv 文件供参考:

Here is my simple main.kv file for reference:

<Controller>:
    ActionBar:
        pos_hint: {'top':1}
        ActionView:
            use_separator: True
            ActionPrevious:
                title: 'Action Bar'
                with_previous: False
                on_release: root.action_close()

    BoxLayout:
        Label:
            text: "Test"

和我的 main.python 文件:

import kivy
from kivy.uix.floatlayout import FloatLayout
from kivy.app import App

class Controller(FloatLayout):

    def action_close(self):
        App.get_running_app().stop()

class ControllerApp(App):

    def build(self):
        self.load_kv('main.kv')
        return Controller()

ControllerApp().run()

以及我的 config.ini 文件中有关Kivy的相关代码段:

As well as the relevant snippets from my config.ini file for Kivy:

[kivy]
keyboard_repeat_delay = 300
keyboard_repeat_rate = 30
log_dir = logs
log_enable = 1
log_level = info
log_name = kivy_%y-%m-%d_%_.txt
window_icon = 
keyboard_mode = dock
keyboard_layout = qwerty
desktop = 1
exit_on_escape = 1
pause_on_minimize = 0
config_version = 14

[graphics]
display = -1
fullscreen = auto
height = 600
left = 0
maxfps = 60
multisamples = 2
position = auto
rotation = 0
show_cursor = 1
top = 0
width = 800
resizable = 1
borderless = 0
window_state = visible
minimum_width = 0
minimum_height = 0

[input]
mouse = mouse
mtdev_%(name)s = probesysfs,provider=mtdev
hid_%(name)s = probesysfs,provider=hidinput

...

我尝试使用配置文件中的值,最值得注意的是window_statefullscreenkeyboard_mode选项,但均未成功.您可以在此处找到Kivy配置信息.在Google上进行了各种搜索,但都没有结果,任何帮助将不胜感激.

I have tried playing with the values in the configuration file, most notably the window_state, fullscreen, and keyboard_mode options with no success. Kivy configuration information can be found here. Various searches on Google and here turned up nothing, any help would be greatly appreciated.

推荐答案

我认为这是由于使用Kivy的rpi特定的窗口提供程序所引起的,该窗口提供程序与硬件使用低级接口以提高执行效率,但反过来不能以正常方式与桌面交互-具体来说,输入和绘图会绕过常规机制.

I think this is caused by using Kivy's rpi-specific window provider, which uses a low level interface with the hardware in order to perform more efficiently, but in turn doesn't interact with the desktop in a normal way - specifically, input and drawing bypass the normal mechanisms.

如果您想在台式机上使用该应用程序,我认为您可以通过针对它们重新编译Kivy来使用普通的窗口后端(理想情况下为SDL2),尽管这样做可能会更慢.但是,如果您实际上不需要桌面(例如,如果只有Kivy需要运行),则此窗口提供程序的另一个优点是它实际上不需要X11等,在这种情况下,您根本不需要启动它们以避免出现问题.

If you want to use the app in a desktop, I think you can use the normal window backends (ideally SDL2) by recompiling Kivy against them, although this may run slower. However, if you don't actually need the desktop (e.g. if Kivy will be the only thing that needs to run), another advantage of this window provider is that it doesn't actually need X11 etc, in which case you could just not start them to avoid the problem.

另请参见该主题的 github问题.

这篇关于Kivy触摸和键盘事件传递到桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆