使用Kivy在ScrollView中使用RST文档

使用Kivy在ScrollView中使用RST文档

本文介绍了使用Kivy在ScrollView中使用RST文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am in a bit of a predicament. While working with Kivy's ScrollView Layout and (Current Experimental) reStructuredText renderer module, I ran into a slight problem. Whenever I run my code, my terminal spams me with:

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

现在,该应用程序似乎运行良好,直到您将ScrollView Layout中的rST文档带到该页面为止.该页面执行各种奇怪的事情. 主滚动"视图将永远缓慢地向下滚动,从页面尾部逐渐变成白色,并且rST文档被奇怪地放置,向左稍微移位.

Now, the application seems to run perfectly fine, until you get to the page with the rST Document inside a ScrollView Layout. That page does all kinds of odd things. The Main scroll view will slowly scroll down, forever, trailing off the page into whiteness, and the rST document is placed oddly, shifted slightly to the left.

但是,当我删除文档时,屏幕和应用程序运行正常,运行正常.是否有人对我如何解决此问题有任何想法,以使页面正常工作? (我是否提到过rST文档最初是放在传送带中的,但是我取出传送带来查看是否是问题所在.)这是Kivy语言代码:

When I remove the document though, the screen and application behave perfectly normal, running smoothly. Does anyone have any idea as to how I could fix this, to make the page work correctly? (Did I mention the rST Document was originally in a Carousel, but I took out the carousel to see if that was the problem.)Here is the Kivy Language Code:

<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布局吗?

Could the problem be that rST Documents are based off of the ScrollView Layout by any chance?

推荐答案

有时候height: self.minimum_height和类似的东西就像把自己开枪打死.绝对要首先注释掉这些内容,因为如果您不做任何花哨的事情,那么大小就成为问题.

Sometimes height: self.minimum_height and similar stuff are like shooting yourself in a foot. Definitely try to comment out these things first, because if you don't do something fancy, the sizing is the issue.

现在,为什么会出现问题? StackLayout 具有其minimum_heightminimum_size设置,我认为该设置在 ,其初始值为零.

Now, why is it an issue? StackLayout has its minimum_height set from minimum_size, which is set I think somewhere here and has some initial value that is not zero.

不过不要混淆,minimum_height确实在开始时默认为零,但是大概在每个添加的小部件上都会对其进行重新计算.如果在height: self.minimum_height之后添加on_height: print(self.height),您会明白我的意思.

Don't be confused though, minimum_height really defaults to zero at the beginning, but then it's recalculated probably on each added widget or so. If you add on_height: print(self.height) after your height: self.minimum_height, you'll see what I mean.

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

Why does it do it like that? Simple! You didn't set absolute size for those children (each child has size_hint == [1, 1]).

此外,如果我没记错的话,ScrollView期望尺寸大于ScrollView(以便滚动).

Also, ScrollView expects size bigger that the ScrollView if I remember correctly (so that it would scroll).

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.

Remove size_hint and size from children and you have your too much iteration there.

这篇关于使用Kivy在ScrollView中使用RST文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 15:42