【问题标题】:Critical Clock warning too much iteration with Kivy RST editor关键时钟警告 Kivy RST 编辑器迭代过多
【发布时间】:2017-10-19 05:45:56
【问题描述】:

在一个更大的应用程序中,我在一个单独的屏幕中拥有一种第一编辑器。只要我在输入小部件中键入一个字符,我就会得到一个持续的关键时钟警告列表: [CRITICAL] [Clock ] 警告,在下一帧之前完成了太多迭代。检查你的代码,或者增加 Clock.max_iteration 属性

我增加了 max-iteration 属性,但这并不能解决问题。同样在下面的代码中,我设置大小没有任何区别。

我该如何解决这个问题?

编辑画面文件:

from kivy.uix.screenmanager import Screen
from kivy.lang import Builder
from kivy.clock import Clock
from functools import partial

Builder.load_file('editscreen.kv')

class EditScreen(Screen):
    '''Screen class.'''

    def __init__(self, **kwargs):
        super(EditScreen, self).__init__(**kwargs)

    def updaterst(self):
        inptext = self.txt_inpt.text
        Clock.schedule_once(partial(self.do_update, inptext), 0.1)

    def do_update(self, text, *args):
        self.rsttxt.text = text

还有kv文件:

# File: editscreen.kv
#: import editscreen editscreen

<EditScreen>:
    name: 'EditScreen'

    txt_inpt:txt_inpt
    rsttxt:rsttxt

    BoxLayout:
        orientation: 'vertical'
        #size_hint: (.99, .99)
        TextInput:
            id: txt_inpt
            #size_hint: None, None
            #size: 400, 400
            on_text: root.updaterst()
        RstDocument:
            id: rsttxt
            #size_hint: None, None
            #size: 400, 400
            show_errors: True

【问题讨论】:

  • 至于“[CRITICAL] [Clock] 警告,在下一帧之前完成了太多迭代。检查你的代码,或者增加Clock.max_iteration 属性”,请参考另一篇帖子stackoverflow.com/questions/38448755/…
  • 我关注了这篇文章,正如您在我的代码示例中看到的那样。另请参阅下面项目中的我的 cmets。

标签: kivy restructuredtext kivy-language


【解决方案1】:

size_hint:(无,无)

要更改大小,您必须将以下内容添加到您的 kv 文件中。详情请参考以下应用。

格式

widget.size_hint = (width_percent, height_percent)

示例

size_hint: (None, None)
size_hint: (1, None)

应用示例

editor.py

​​>
from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.properties import ObjectProperty
from kivy.clock import Clock
from functools import partial


class MyScreenManager(ScreenManager):
    pass


class EditScreen(Screen):
    '''Screen class.'''
    txt_inpt = ObjectProperty(None)
    rsttxt = ObjectProperty(None)

    def __init__(self, **kwargs):
        super(EditScreen, self).__init__(**kwargs)

    def updaterst(self):
        inptext = self.txt_inpt.text
        Clock.schedule_once(partial(self.do_update, inptext), 0.1)

    def do_update(self, text, *args):
        self.rsttxt.text = text


class EditorApp(App):
    title = "Kivy RichText Editor"

    def build(self):
        return MyScreenManager()


if __name__ == "__main__":
    EditorApp().run()

editor.kv

#:kivy 1.10.0

<MyScreenManager>:
    EditScreen:

<EditScreen>:
    name: 'EditScreen'

    txt_inpt:txt_inpt
    rsttxt:rsttxt

    BoxLayout:
        orientation: 'vertical'
        # size_hint: (.99, .99)
        TextInput:
            id: txt_inpt
            size_hint: 1, None
            height: root.height / 2
            on_text: root.updaterst()
        RstDocument:
            id: rsttxt
            size_hint: 1, None
            height: root.height / 2
            show_errors: True

输出

【讨论】:

  • 尊敬的 Ikolim,感谢您的详细回复。不幸的是,这并不能解决我的问题。关键时钟警告仍然存在。我的猜测是,它与使用 Tabbedpanel 进行主导航和选项卡上下文中的屏幕管理器的组合有关。所以我会深入研究这个问题。
【解决方案2】:

我刚刚编辑了一点你的代码,它运行良好,没有严重警告:

-py:

from kivy.uix.screenmanager import Screen
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.app import App


class EditScreen(Screen):
   '''Screen class.'''
   txt_inpt = ObjectProperty()

   def __init__(self, **kwargs):
      super(EditScreen, self).__init__(**kwargs)
      Clock.schedule_interval(self.do_update, 0.1)

   def do_update(self, *args):
      self.rsttxt.text = self.txt_inpt.text

class EditorApp(App):

   def build(self):
      return EditScreen()


if __name__ == "__main__":
   EditorApp().run()

-kv:

<EditScreen>:
   name: 'EditScreen'

   txt_inpt:txt_inpt
   rsttxt:rsttxt

   BoxLayout:
      orientation: 'vertical'
      #size_hint: (.99, .99)
      TextInput:
         id: txt_inpt
         #size_hint: None, None
         #size: 400, 400
      RstDocument:
         id: rsttxt
         #size_hint: None, None
         #size: 400, 400
         show_errors: True

输出:

请尝试我的代码并告诉我们

【讨论】:

  • 您的代码示例在我的环境以及单个应用程序中运行良好。但集成在我的总包中,它会不断生成这些关键时钟警告。
  • 我理解这个问题。 pb 是 on_text 事件处理程序,因此将其删除并安排间隔循环而不是一次。我更新了我的代码,用你的大代码试试。我希望我能帮上忙!
  • 您好,感谢您的帮助。不幸的是,这个解决方案也不能解决问题。我很确定它与使用 Tabbedpanels 与 screenmanager 结合进行主导航有关(阅读:错误)。我开始重新设计导航结构,并将仅使用屏幕管理器和延迟加载架构。完成后,我将在此处发布结果。
  • 好的,但是由于没有什么能正确地帮助你,我们需要更多的代码。
【解决方案3】:

这都是关于按钮的。如果连续有很多按钮超出屏幕,如果缩小,则会出现错误。我把 size_hint: None, None 和它的工作。使用 FloatLayout 来定位按钮和其他元素。在 dp, sp 中设置大小,这样它们就不会相互重叠。为大屏幕制作应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 2021-01-19
    • 2019-06-11
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多