如何从BoxLayout重新定位窗口小部件

时间:2017-12-17 16:37:59

标签: kivy kivy-language

我使用的是最新版本的kivy:v1.10.1.dev0, git-Unknown, 20171208,python v3.6.2,mac os。

我想要实现以下内容:当我使用更改的设置更新设置重新定位/重绘BoxLayout中的值时,在我的情况下,我更新size_hint值。这是我到目前为止的工作:

my.py

from kivy.app import App


class MyApp(App):
    def build_config(self, config):
        config.read('./my.ini')

    def build_settings(self, settings):
        settings.add_json_panel('Test', self.config, filename='my.json')

    def on_config_change(self, config, section, key, value):
        if section in ('layout',) and key in ('size_hint',):
            # NOT WORKING!!
            # print(self.root.canvas.clear())
            # self.root.canvas.ask_update()
            # self.root.canvas.draw()

            # NOT WORKING!!
            print(self.root)
            print(self.root.do_layout())

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

my.kv

#:import SettingsWithSidebar kivy.uix.settings.SettingsWithSidebar
BoxLayout:
    RecycleView:
        size_hint: float(app.config.get('layout', 'size_hint')), 1
        Button:
            text: 'Open Settings'
            on_touch_down: app.settings_cls = SettingsWithSidebar; app.open_settings()
    RecycleView:
        size_hint: 1-float(app.config.get('layout', 'size_hint')), 1
        Button:
            text: 'Just a test'

的my.ini

[layout]
size_hint = 0.6

my.json

[
  {
        "type": "string",
        "title": "Size Hint",
        "desc": "Size Hint",
        "section": "layout",
        "key": "size_hint"
    }
]

那么,当我关闭设置窗口时,如何看到使用新值size_hint更新新布局?

THX!

1 个答案:

答案 0 :(得分:0)

OK, after some help from IRC #Kivy the solution is to not use directly mUserFriendsReference =mFirebaseDatabase.getReference("friend_request/receiver/" +FirebaseAuth.getInstance().getCurrentUser().getUid()); in app.config.get('layout', 'size_hint') file but used .kv instead.

my.kv

Properties

my.py

BoxLayout:
    RecycleView:
        size_hint: app.size_hint, 1
        Button:
            text: 'Open Settings'
            on_touch_down: app.open_settings()
    RecycleView:
        size_hint: 1-app.size_hint, 1
        Button:
            text: 'Just a test'