The id identifiers are create in the kv file, and when the kv file is processed and ids dict is created. This dict can be accessed from kv or python.
See: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#ids
https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=ids#kivy.uix.widget.Widget.ids
if your kv rule has defined id’s and your ids dict is empty – the problem could be that you are trying to access the ids in __init__. The ids are not yet set at the time the object is created, instead use on_kv_post. This is called after the widgets kv code has been processed.
From the widget docs: https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=widget#kivy.uix.widget.Widget
on_kv_post: (base_widget, )
Fired after all the kv rules associated with the widget and all other widgets that are in any of those rules have had all their kv rules applied. base_widget is the base-most widget whose instantiation triggered the kv rules (i.e. the widget instantiated from Python, e.g. MyWidget()).
Hope that helps!
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAFYkXjnkMVbNvB6LNNtj30nYAnDB3TXmXcjqD5vUWGNqLQvQvA%40mail.gmail.com.
By the way do you know is there any way to access app from withing a
component method without passing app as parameter?
https://kivy.org/doc/stable/api-kivy.app.html?highlight=get_running#kivy.app.App.get_running_app
In the method I typically would write:
app = App.get_running_app()
so the “kv string” looks the same in python or kv.
On to ids… in your example
MyComponent:
id: button
on_press: self.do_something(app=app)
This id will now be added to the ids dict. It is redundant. This is the self object to root of the ids dict.
You would use the id to address the nested components. This works for the root widget or rule. Each kv rule has its own ids dict.
BoxLayout: # root widget has an ids dict
Button:
id:button_1
Button:
id: button_2
MyBoxLayout:
id: my_boxlayout
<MyBoxLayout>: # kv rule has an ids dict
Button:
id:button_1
Button:
id: button_2
I did not quite understand your question about asyncio and kivy. I have been using Trio (an asycio framework) with httpx – but have not yet had an opportunity to integrate async with kivy.
For light networking in kivy I use urlrequest: https://kivy.org/doc/stable/api-kivy.network.urlrequest.html?highlight=urlrequest#module-kivy.network.urlrequest
It integrates easily into the kivy callback model.
If you have an example where you are having trouble with ids, feel free to share some code.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAFYkXjmvxRCwA222n43S4oqWMreUV5A_v4TwqnPXzfi4B3_yvQ%40mail.gmail.com.
I’m not sure what the problem is. Could you have possibly created 2 App instances?
From: Tomek CEDRO
Sent: Friday, December 2, 2022 6:13 PM
To: kivy-...@googlegroups.com
Subject: Re: [kivy-users] incoherence: ids in kv and python code
Thank you Elliot :-)
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAFYkXj%3Dy0Fmbqy_1Pc9UBZ7DGNAhs5y-Zj4JXoScVtX%2BfA9OBQ%40mail.gmail.com.
Another possibility – are you sure you are only loading the kv files once? Kivy will try to load a kv file with the name of your app by default. If you have a kv file with the name of your app – it is possible that it is being loaded twice.
Example:
class MyExcellentApp(MDApp):
…
Will load myexcellent.kv automagically. If you are also loading this file with a Builder.load_file() this could cause a problem.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/638aa840.170a0220.e40e.aaceSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
I thought this might be helpful…
Looking at the code in the github issue:
The root widget is a ScreenManager declared in the build method, and 2 screens are added. There for:
self.root is the screen manager. self.root.ids should be empty, the ids are in the screens. To get the ids from the screen named ‘menu’, would require:
self – In this context self is MDApp
self.root – The screenmanager
self.root.get_screen(‘menu’) – The menu screen
self.root.get_screen(‘menu’).ids
Let me know if this helps…
From: Elliot Garbus
Sent: Friday, December 2, 2022 9:02 PM
To: kivy-...@googlegroups.com
Subject: Re: [kivy-users] incoherence: ids in kv and python code
The reported GitHub issue does not look like a bug, it looks like a user issue.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/543AFC83-4DE6-4002-9CBE-30E1939AE7A2%40cox.net.
On Dec 2, 2022, at 9:23 PM, Tomek CEDRO <to...@cedro.info> wrote:
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAFYkXjmhNJONkrp2WzZwbQNTdHZ%2BLc5nL8Q-MyhttQBGtVNAog%40mail.gmail.com.