UIX: Widget: Raise Exception if widget already has parent. #585

Merged
merged 3 commits into from Jul 24, 2012

Conversation

Projects
None yet
2 participants
@akshayaurora
Member

akshayaurora commented Jul 20, 2012

Along with fixes in TabbedPanel and Bubble for issues due to this
warning.

UIX: Widget: Warn and skip addition if widget already has parent.
Along with fixes in TabbedPanel and Bubble for issues due to this
warning.
kivy/uix/widget.py
+ Logger.warning(''.join(('Cannot add Widget ', str(widget),\
+ ' It already has a parent ', str(parent),
+ ' Skipping addition')))
+ return

This comment has been minimized.

@akshayaurora

akshayaurora Jul 20, 2012

Member

This would highlight the issue, instead of just silently fixing it but could this break existing
code for people? Should we just raise a warning and add the widget any ways?

@akshayaurora

akshayaurora Jul 20, 2012

Member

This would highlight the issue, instead of just silently fixing it but could this break existing
code for people? Should we just raise a warning and add the widget any ways?

This comment has been minimized.

@tito

tito Jul 20, 2012

Member

Then, i would prefer an exception than a warning ? What do you think ?
I agreed that this shouldn't be the case, and we could fail correctly.

@tito

tito Jul 20, 2012

Member

Then, i would prefer an exception than a warning ? What do you think ?
I agreed that this shouldn't be the case, and we could fail correctly.

@@ -157,6 +157,7 @@ def __init__(self, **kwargs):
color=self.background_color)
self.content = content = BubbleContent(parent=self)
super(Bubble, self).__init__(**kwargs)
+ content.parent = None

This comment has been minimized.

@tito

tito Jul 21, 2012

Member

Is the initialization is really needed ? It shouldn't be, remove it.

@tito

tito Jul 21, 2012

Member

Is the initialization is really needed ? It shouldn't be, remove it.

This comment has been minimized.

@akshayaurora

akshayaurora Jul 21, 2012

Member

At line 158 the BubbleContent's parent is being set to self. which prevents the addition of the content to the bubble itself because the parent already exists.
Update: I think that(parent=self) part is needed because of this c0997c8

@akshayaurora

akshayaurora Jul 21, 2012

Member

At line 158 the BubbleContent's parent is being set to self. which prevents the addition of the content to the bubble itself because the parent already exists.
Update: I think that(parent=self) part is needed because of this c0997c8

kivy/uix/widget.py
+ parent = widget.parent
+ # check if widget is already a child of another widget
+ if parent:
+ raise WidgetException(''.join(('Cannot add ', str(widget),\

This comment has been minimized.

@tito

tito Jul 21, 2012

Member

I didn't seen the writing before, but don't use ''.join() for formatting, use the string / repr like that:

raise WidgetException('Cannot add %r, it already has a parent %r' % (
    widget, parent))
@tito

tito Jul 21, 2012

Member

I didn't seen the writing before, but don't use ''.join() for formatting, use the string / repr like that:

raise WidgetException('Cannot add %r, it already has a parent %r' % (
    widget, parent))

This comment has been minimized.

@tito

tito Jul 21, 2012

Member

%r = repr(arg)

@tito

tito Jul 21, 2012

Member

%r = repr(arg)

tito added a commit that referenced this pull request Jul 24, 2012

Merge pull request #585 from kivy/add__widget
UIX: Widget: Raise Exception if widget already has parent.

@tito tito merged commit 75445ea into master Jul 24, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment