Quiv of Kivy FloatLayout缩放? - 或者我错过了一些基本的东西

时间:2017-04-13 22:18:33

标签: python kivy kivy-language

我在使用FloatLayout时遇到了一些问题,并且在处理许多小部件时进行缩放, 特别是图像。虽然我已经阅读了文档和大部分源代码, 我怀疑我缺少一些基本的东西。为了演示,我写了一篇小文章 示例程序:

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

kv_text = """
#:kivy 1.9.2-dev

GameScreen:

<GameScreen>
    Image:
        source: 'just_blue.png'
        size_hint: (1.0, 1.0)
        pos_hint: {'x': 0.0, 'y': 0.0}
    Image:
        source: 'gimp_pine.png'
        size_hint: (0.5, 0.5)
        pos_hint: {'x': 0.0, 'y': 0.0}
    Button:
        text: "0.5, 0.5"
        size_hint: (0.2, 0.2)
        pos_hint: {'x': 0.0, 'y': 0.0}
"""

# notes:
# both PNG files are 400 x 400 pixels
# the resulting window created on my PC is 800 x 600

class GameScreen(FloatLayout):
    pass

class GameApp(App):

    def build(self):
        presentation = Builder.load_string(kv_text)
        return presentation

    def on_start(self):
        pass

if __name__ == '__main__':
    app = GameApp()
    app.run()

这导致了这个:

screenshot

我看到两个问题:

  1. 左下角不在窗口的左下角。

  2. 显然,PNG的大小也是错误的。只有按钮是正确的。

  3. 我正在开发的应用程序无法使用花哨的“背景”解决方法。我真的很喜欢 使用小部件来处理被操纵的数百个项目。

    供参考,这是文本日志:

    [INFO   ] [Logger      ] Record log in /home/johnd/.kivy/logs/kivy_17-04-13_40.txt
    [INFO   ] [Kivy        ] v1.9.2.dev0, git-a97fe07, 20170413
    [INFO   ] [Python      ] v2.7.12 (default, Nov 19 2016, 06:48:10) 
    [GCC 5.4.0 20160609]
    [INFO   ] [Factory     ] 194 symbols loaded
    [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
    [WARNING] Application requested a -dev version of Kivy. (You have 1.9.2.dev0, but the application requires 1.9.2-dev)
    [INFO   ] [OSC         ] using <multiprocessing> for socket
    [INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
    [INFO   ] [GL          ] Using the "OpenGL" graphics system
    [INFO   ] [GL          ] Backend used <gl>
    [INFO   ] [GL          ] OpenGL version <4.5.0 NVIDIA 361.42>
    [INFO   ] [GL          ] OpenGL vendor <NVIDIA Corporation>
    [INFO   ] [GL          ] OpenGL renderer <GeForce GTX 950M/PCIe/SSE2>
    [INFO   ] [GL          ] OpenGL parsed version: 4, 5
    [INFO   ] [GL          ] Shading version <4.50 NVIDIA>
    [INFO   ] [GL          ] Texture max size <16384>
    [INFO   ] [GL          ] Texture max units <32>
    [INFO   ] [Window      ] auto add sdl2 input provider
    [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
    [INFO   ] [Text        ] Provider: sdl2
    [INFO   ] [GL          ] NPOT texture support is available
    [INFO   ] [Base        ] Start application main loop
    [INFO   ] [Base        ] Leaving application in progress...
    (venv) johnd@johnd-GP60-2QF ~/Projects/test_kivy $ python main.py
    [INFO   ] [Logger      ] Record log in /home/johnd/.kivy/logs/kivy_17-04-13_41.txt
    [INFO   ] [Kivy        ] v1.9.2.dev0, git-a97fe07, 20170413
    [INFO   ] [Python      ] v2.7.12 (default, Nov 19 2016, 06:48:10) 
    [GCC 5.4.0 20160609]
    [INFO   ] [Factory     ] 194 symbols loaded
    [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
    [WARNING] Application requested a -dev version of Kivy. (You have 1.9.2.dev0, but the application requires 1.9.2-dev)
    [INFO   ] [OSC         ] using <multiprocessing> for socket
    [INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
    [INFO   ] [GL          ] Using the "OpenGL" graphics system
    [INFO   ] [GL          ] Backend used <gl>
    [INFO   ] [GL          ] OpenGL version <4.5.0 NVIDIA 361.42>
    [INFO   ] [GL          ] OpenGL vendor <NVIDIA Corporation>
    [INFO   ] [GL          ] OpenGL renderer <GeForce GTX 950M/PCIe/SSE2>
    [INFO   ] [GL          ] OpenGL parsed version: 4, 5
    [INFO   ] [GL          ] Shading version <4.50 NVIDIA>
    [INFO   ] [GL          ] Texture max size <16384>
    [INFO   ] [GL          ] Texture max units <32>
    [INFO   ] [Window      ] auto add sdl2 input provider
    [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
    [INFO   ] [Text        ] Provider: sdl2
    [INFO   ] [GL          ] NPOT texture support is available
    [INFO   ] [Base        ] Start application main loop
    [INFO   ] [Base        ] Leaving application in progress...
    

    虽然我使用SDL2运行kivy的1.9.2.dev0,但我在1.9.1和pygame中看到过这种相同的行为。

    (除此之外,在Android环境中,缩放问题变得更糟。但是我会在单独的堆栈溢出时询问它。)

0 个答案:

没有答案
相关问题