From e95717c6508aa547f76018719ad52db76880658f Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Fri, 22 Mar 2013 15:06:33 -0500 Subject: [PATCH] widget: fix widget insertion with or without canvas.before. closes #1021. --- kivy/graphics/instructions.pxd | 2 +- kivy/graphics/instructions.pyx | 17 +++++++++++++++++ kivy/uix/widget.py | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/kivy/graphics/instructions.pxd b/kivy/graphics/instructions.pxd index 196d931ef..9a8369489 100644 --- a/kivy/graphics/instructions.pxd +++ b/kivy/graphics/instructions.pxd @@ -33,7 +33,7 @@ cdef class Instruction: cdef void rremove(self, InstructionGroup ig) cdef class InstructionGroup(Instruction): - cdef list children + cdef public list children cdef InstructionGroup compiled_children cdef GraphicsCompiler compiler cdef void build(self) diff --git a/kivy/graphics/instructions.pyx b/kivy/graphics/instructions.pyx index bfa2a510b..bc4290bf7 100644 --- a/kivy/graphics/instructions.pyx +++ b/kivy/graphics/instructions.pyx @@ -595,6 +595,23 @@ cdef class Canvas(CanvasBase): self._after = c return self._after + property has_before: + '''Property to see if the canvas.before is already created + + .. versionadded:: 1.6.1 + ''' + def __get__(self): + return self._before is not None + + property has_after: + '''Property to see if the canvas.after is already created + + .. versionadded:: 1.6.1 + ''' + def __get__(self): + return self._after is not None + + property opacity: '''Property for get/set the opacity value of the canvas. diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py index 9eddb38d7..ff5194408 100644 --- a/kivy/uix/widget.py +++ b/kivy/uix/widget.py @@ -280,7 +280,7 @@ class Widget(EventDispatcher): children = self.children if index >= len(children): index = len(children) - next_index = -1 + next_index = 0 else: next_child = children[index] next_index = canvas.indexof(next_child.canvas) @@ -290,6 +290,9 @@ class Widget(EventDispatcher): next_index += 1 children.insert(index, widget) + # we never want to insert widget _before_ canvas.before. + if next_index == 0: + next_index = 1 canvas.insert(next_index, widget.canvas) def remove_widget(self, widget):