【问题标题】:Using a RST Document in a ScrollView using Kivy使用 Kivy 在 ScrollView 中使用 RST 文档
【发布时间】:2017-01-17 21:39:23
【问题描述】:

我有点进退两难。在使用 Kivy 的 ScrollView 布局和(当前实验性)reStructuredText 渲染器模块时,我遇到了一个小问题。每当我运行我的代码时,我的终端都会向我发送垃圾邮件:

[CRITICAL] [Clock] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute

现在,应用程序似乎运行得非常好,直到您进入 ScrollView 布局中包含 rST 文档的页面。该页面做了各种奇怪的事情。主滚动视图将永远缓慢地向下滚动,从页面拖出变成白色,并且 rST 文档放置得很奇怪,稍微向左移动。

但当我删除文档时,屏幕和应用程序的行为完全正常,运行顺畅。有谁知道我该如何解决这个问题,以使页面正常工作? (我有没有提到 rST 文档最初是在轮播中,但我拿出了轮播,看看这是否是问题所在。) 这是 Kivy 语言代码:

<Page>:
    orientation: 'vertical'
    ScrollView:
        size_hint: (.99, .99)
        StackLayout:
            size_hint_y: None
            id: content_layout
            height: self.minimum_height
            WrappedLabel:
                text: "Test"
                font_size: min(root.height, root.width)
            RstDocument:
                underline_color: 'blue'
                text:("Some Text")

问题是否可能是 rST 文档基于 ScrollView 布局?

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    有时height: self.minimum_height 和类似的东西就像是在踢自己的脚。一定要先把这些东西注释掉,因为如果你不做一些花哨的事情,尺寸就是问题。

    现在,为什么会出现问题? StackLayoutminimum_height 是从 minimum_size 设置的,我认为它是在某处设置的 here 并且有一些初始值为零。

    不过不要混淆,minimum_height 在开始时确实默认为零,但随后可能会在每个添加的小部件上重新计算它。如果你在height: self.minimum_height 后面加上on_height: print(self.height),你就会明白我的意思了。

    为什么会这样?简单的!您没有为这些孩子设置绝对大小(每个孩子都有size_hint == [1, 1])。

    另外,ScrollView 如果我没记错的话,期望尺寸比 ScrollView 大(这样它会滚动)。

    from kivy.lang import Builder
    from kivy.base import runTouchApp
    from kivy.uix.boxlayout import BoxLayout
    Builder.load_string('''
    <Test>:
        orientation: 'vertical'
        ScrollView:
            size_hint: (.99, .99)
            StackLayout:
                size_hint_y: None
                id: content_layout
                height: self.minimum_height
                on_height: print(self.height)
                Label:
                    size_hint: None, None
                    size: 100, 30
                    text: "Test"
                    font_size: min(root.height, root.width)
                RstDocument:
                    size_hint: None, None
                    size: 100, 1000
                    underline_color: 'blue'
                    text:("Some Text")
    ''')
    class Test(BoxLayout): pass
    runTouchApp(Test())
    

    从孩子身上删除size_hintsize,你的too much iteration 就在那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2021-09-07
      • 2013-06-29
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多