On Mon, Jul 4, 2016 at 3:03 PM, Flavio Coelho <
fcco...@gmail.com> wrote:
> Thanks zencode,
>
> I am trying to do as You suggest, but the KV builder is complaining that
> `MyLabel` is not defined, even though I have defined the class MyLabel in my
> main.py. Any Idea of what I may be doing wrong?
you should declare MyLabel also in the kv file; something like this:
# kv file
MyLabel
ListView:
adapter:
sla.SimpleListAdapter(data=["[color=#ff3333]Item
#{0}[/color]".format(i) for i in range(100)], cls=MyLabel)
But note that in this case, where the only scope of MyLabel is to set
the value of an attribute, it is not necessary to define a new class
in Python; you can do it directly from the kv file:
#:import Factory kivy.factory.Factory
#:import SimpleListAdapter kivy.adapters.simplelistadapter.SimpleListAdapter
<MyLabel@Label>:
markup: True
ListView:
adapter: SimpleListAdapter(data=["[color=#ff3333]Item
#{0}[/color]".format(i) for i in range(100)], cls=Factory.MyLabel)
Note that when you define a new class in kv using the
<ClassName@SuperClass> syntax, it automatically becomes available in
the Factory object.
ciao,
Anto