Search code examples
pythonkivykivy-languagekivymd

getting an error of loading multiple files?


Error

[INFO   ] [Base        ] Leaving application in progress...
[WARNING] [Lang        ] The file e:\school_proj\final_with_settings\layout.kv is loaded multiples times, you might have unwanted behaviors.
[INFO   ] [Base        ] Start application main loop
False
True
UPDATED
[INFO   ] [Base        ] Leaving application in progress...

So, I take some user input then to make changes I have to restart the app.

For the same I found this code on the internet:

    def restart(self):
        self.root.clear_widgets()
        self.stop()
        return StonkkApp().run()

This resides in the MDApp class

.py code

class StonkkApp(MDApp):
    
    def build(self):
        self.icon = f'{cur_file_path}/stonkss.png'
        screen = Builder.load_file('layout.kv')
        self.theme_cls.theme_style = theme
        self.theme_cls.primary_palette = 'Gray'
        return screen
    
    def restart(self):
        self.root.clear_widgets()
        self.stop()
        return StonkkApp().run()

Then it is giving the error.

Full Traceback:
[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.3.2
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Kivy        ] v2.1.0.dev0, git-143ba31, 20210630
[INFO   ] [Python      ] v3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.5.13399 Compatibility Profile Context 
15.201.1151.1008'>
[INFO   ] [GL          ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 5
[INFO   ] [GL          ] Shading version <b'4.40'>
[INFO   ] [GL          ] Texture max size <16384>[INFO   ] [GL          ] Texture max units <18>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked     
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Base        ] Start application main loop
False
True
UPDATED
Saving changes.
current color and type of plot is , . app mode is Light
[INFO   ] [Base        ] Leaving application in progress...
[WARNING] [Lang        ] The file e:\school_proj\final_with_settings\layout.kv is loaded multiples times, you might have unwanted behaviors.
[INFO   ] [Base        ] Start application main loop
False
True
UPDATED
[INFO   ] [Base        ] Leaving application in progress...

This error is coming after I have started running the restart code.

SOLUTION:

Builder.unload_file('Layout.kv')

Just had to add to the start of the restart() function.


Solution

  • When you restart you App, the build() method is reloading the kv file in the line:

    screen = Builder.load_file('layout.kv')
    

    See this question for an idea of how to prevent loading the kv file twice.