1. <i id='HsKLA'><tr id='HsKLA'><dt id='HsKLA'><q id='HsKLA'><span id='HsKLA'><b id='HsKLA'><form id='HsKLA'><ins id='HsKLA'></ins><ul id='HsKLA'></ul><sub id='HsKLA'></sub></form><legend id='HsKLA'></legend><bdo id='HsKLA'><pre id='HsKLA'><center id='HsKLA'></center></pre></bdo></b><th id='HsKLA'></th></span></q></dt></tr></i><div id='HsKLA'><tfoot id='HsKLA'></tfoot><dl id='HsKLA'><fieldset id='HsKLA'></fieldset></dl></div>
      <bdo id='HsKLA'></bdo><ul id='HsKLA'></ul>
  2. <legend id='HsKLA'><style id='HsKLA'><dir id='HsKLA'><q id='HsKLA'></q></dir></style></legend>

    <tfoot id='HsKLA'></tfoot>

      <small id='HsKLA'></small><noframes id='HsKLA'>

    1. 动态更新的Kivy设置条目

      Dynamically updated Kivy settings entry(动态更新的Kivy设置条目)

        <i id='sjXwQ'><tr id='sjXwQ'><dt id='sjXwQ'><q id='sjXwQ'><span id='sjXwQ'><b id='sjXwQ'><form id='sjXwQ'><ins id='sjXwQ'></ins><ul id='sjXwQ'></ul><sub id='sjXwQ'></sub></form><legend id='sjXwQ'></legend><bdo id='sjXwQ'><pre id='sjXwQ'><center id='sjXwQ'></center></pre></bdo></b><th id='sjXwQ'></th></span></q></dt></tr></i><div id='sjXwQ'><tfoot id='sjXwQ'></tfoot><dl id='sjXwQ'><fieldset id='sjXwQ'></fieldset></dl></div>
      • <small id='sjXwQ'></small><noframes id='sjXwQ'>

          <tbody id='sjXwQ'></tbody>

            <bdo id='sjXwQ'></bdo><ul id='sjXwQ'></ul>
            <legend id='sjXwQ'><style id='sjXwQ'><dir id='sjXwQ'><q id='sjXwQ'></q></dir></style></legend><tfoot id='sjXwQ'></tfoot>
              • 本文介绍了动态更新的Kivy设置条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Kivy有这个非常棒的内置功能,可以为您的应用程序创建设置面板。 它为您提供了一组可以使用的条目类型,如字符串、布尔、选项等。 但是所有这些选项都硬编码在json文件中,如果发生动态变化,您会怎么做?

                如何在Kivy中拥有动态更改的设置菜单?

                具体地说,我需要一个用于串行连接的设置面板。我的应用程序的用户需要选择他想要连接的现有串行端口。此列表可以在Python中获取,但它可以随时更改,因此如何使我的设置菜单与当前的COM端口可用性保持最新?

                推荐答案

                可能有几种方法。以下是其中之一:

                创建将函数作为字符串接受的新设置类型,该设置将包含每次用户要查看列表时要调用的函数的完整路径:

                class SettingDynamicOptions(SettingOptions):
                    '''Implementation of an option list that creates the items in the possible
                    options list by calling an external method, that should be defined in
                    the settings class.
                    '''
                
                    function_string = StringProperty()
                    '''The function's name to call each time the list should be updated.
                    It should return a list of strings, to be used for the options.
                    '''
                
                    def _create_popup(self, instance):
                        # Update the options
                        mod_name, func_name = self.function_string.rsplit('.',1)
                        mod = importlib.import_module(mod_name)
                        func = getattr(mod, func_name)
                        self.options = func()
                    
                        # Call the parent __init__
                        super(SettingDynamicOptions, self)._create_popup(instance)
                

                它是SettingOptions的子类,后者允许用户从下拉列表中进行选择。每次用户按下设置以查看可能的选项时,都会调用_create_popup方法。新的重写方法动态导入函数并调用它来更新类的Options属性(反映在下拉列表中)。

                现在可以在json中创建这样的设置项:

                    {
                        "type": "dynamic_options",
                        "title": "options that are always up to date",
                        "desc": "some desc.",
                        "section": "comm",
                        "key": "my_dynamic_options",
                        "function_string": "my_module.my_sub_module.my_function"
                    },
                

                还需要通过将Kivy的设置类子类化来注册新的设置类型:

                class MySettings(SettingsWithSidebar):
                    '''Customized settings panel.
                    '''
                    def __init__(self, *args, **kargs):
                        super(MySettings, self).__init__(*args, **kargs)
                        self.register_type('dynamic_options', SettingDynamicOptions)
                

                并将其用于您的应用程序:

                    def build(self):
                        '''Build the screen.
                        '''
                        self.settings_cls = MySettings
                

                这篇关于动态更新的Kivy设置条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                GUI Freezes while downloading PyQt5 and Pytube(GUI在下载PyQt5和Pytube时冻结)
                How to solve memory issues while multiprocessing using Pool.map()?(如何解决使用Pool.map()进行多处理时的内存问题?)
                Python - How to use FastAPI and uvicorn.run without blocking the thread?(Python-如何使用FastAPI和uvicorn.run而不阻塞线程?)
                How to increment a shared counter from multiple processes?(如何从多个进程递增共享计数器?)
                Using pika, how to connect to rabbitmq running in docker, started with docker-compose with external network?(使用pika,如何连接运行在docker中的rabbitmq,从docker开始-与外部网络连接?)
                How to use .rolling() on each row of a Pandas dataframe?(如何对 pandas 数据帧的每一行使用.roll()?)
              • <i id='nhS7z'><tr id='nhS7z'><dt id='nhS7z'><q id='nhS7z'><span id='nhS7z'><b id='nhS7z'><form id='nhS7z'><ins id='nhS7z'></ins><ul id='nhS7z'></ul><sub id='nhS7z'></sub></form><legend id='nhS7z'></legend><bdo id='nhS7z'><pre id='nhS7z'><center id='nhS7z'></center></pre></bdo></b><th id='nhS7z'></th></span></q></dt></tr></i><div id='nhS7z'><tfoot id='nhS7z'></tfoot><dl id='nhS7z'><fieldset id='nhS7z'></fieldset></dl></div>

                        <small id='nhS7z'></small><noframes id='nhS7z'>

                        <tfoot id='nhS7z'></tfoot>
                      1. <legend id='nhS7z'><style id='nhS7z'><dir id='nhS7z'><q id='nhS7z'></q></dir></style></legend>

                          <tbody id='nhS7z'></tbody>

                        • <bdo id='nhS7z'></bdo><ul id='nhS7z'></ul>