community icon indicating copy to clipboard operation
community copied to clipboard

Injectable widgets in kv lang?

Open tomplast opened this issue 3 years ago • 2 comments

Is it possible somehow to inject content into inherited widgets? Here comes an example in pseudo code of what I would like to do:

#: abstract BaseScreen@Screen:` Label: text: 'Top label'

#: inject_from("Content1")

Label: text: 'bottom label'

HomeScreen@BaseScreen: Content1: Label: text: 'This label will be place between first and second label!" `

Is this functionality possible today (preferably through kv language only)?

tomplast avatar Jun 21 '22 18:06 tomplast

Here it is

#:import Content1 path.to.content.Content1

<BaseScreen@Screen>:
    Label:
        text: 'Top Label'
    Label:
        text: 'Bottom Label'
        

<HomeScreen@BaseScreen>:
    Content1:
    Label:
        text: 'This label will be place between first and second label!'

This will render, in this order

Top Label
Bottom Label
actual content of Content1
This label will be place between first and second label!

To acheive

Top Label
actual content of Content1
This label will be place between first and second label!
Bottom Label

You might need to do some pythonic stuff

Consider visiting https://kivy.org/doc/stable/guide/lang.html to more learn about kv lang

kulothunganug avatar Jun 23 '22 13:06 kulothunganug

I think it is not possible solely on the kv language side. But after you define widgets in the kv language in an ordered layout such as boxlayout, then you may remove the last label through ids of the screen and then add your content+label or necessary changes from the python side.

drahba avatar Jun 29 '22 21:06 drahba