kivy editable multicolumn list

Laura Creighton lac at openend.se
Tue Sep 15 12:42:47 CEST 2015


In a message of Tue, 15 Sep 2015 03:31:49 +0100, Paulo da Silva writes:
>Hi all.
>Not sure if this is the place to ask about kivy ...
>I apologize if not.
>
>I am playing with the example here
>https://gist.github.com/geojeff/4442405
>
>Now I would like to change the background color the editable field.
>
>So I added
>	def __init__(self,**kwargs):
>		super(EditableLabel,self).__init__(**kwargs)
>		with self.canvas.before:
>			Color(0,1,0)
>			Rectangle(pos=self.pos,size=self.size)
>			print(self.pos,self.size)
>
>to class EditableLabel.
>
>But when entering __init__ self.pos and self.size do not have the
>correct pos/size for the EditableLabel.
>
>How can I fix this? Please no kv solutions. I need dynamic change it in
>a real example.

I am not sure what you want for your integers_dict.  It isn't the
something that Rob Collins fixtures package provides. :)
https://pypi.python.org/pypi/fixtures

I just hardcoded it like this:

integers_dict = {str(i): {'text': str(i), 'is_selected': False}
                 for i in range(100)}

which I pasted out of http://kivy.org/docs/api-kivy.uix.listview.html
'Using an Item View Template'.  This may have no relation to what you
really want.

you also need a line
from kivy.graphics import Color, Rectangle

Then you change your class definition to be:

class EditableLabel(ListItemLabel):
    def __init__(self,**kwargs):
        super(EditableLabel, self).__init__(**kwargs)
        self.bind(pos=self.redraw)
        self.bind(size=self.redraw)

    def redraw(self, *args):
        self.canvas.clear()
        with self.canvas:
            Color(.5,.5,.5)
            Rectangle(pos=self.pos,size=self.size)

I don't know why changing self.canvas.before: to self.canvas: in the redraw
method was needed here.  I expected self.canvas.before to be what was
needed, but doesn't seem that way.

If you don't clear the canvas first, in the redraw the results look very
silly to me. However, since you are just playing around to learn things,
then that behaviour may be what you are looking for, so comment it out
and see if you like that better.

HTH,
Laura





More information about the Python-list mailing list