When does a new widget start receiving events?

49 views
Skip to first unread message

GreyGnome

unread,
Jan 9, 2017, 11:57:12 PM1/9/17
to Kivy users support
Hello,
I have an app with a label in the lower lefthand corner, which when pressed brings up a new widget hierarchy. One of the components of that new set of stuff is a button that, when pressed, is supposed to remove the widget hierarchy.

My problem is that when the new stuff is added, the on_press event is sent to the new button. Since it's not yet on screen, the button has an x, y position of 0,0 and width, height of 100, 100. This is right about where by label is, so the new button thinks that it was pressed and it immediately closes the window... in other words, it never appears on-screen.

Does this make sense? Why would a new widget (and its children) receive an event that was generated prior to their existence? How do I properly handle this situation?

Thanks.

Oon-Ee Ng

unread,
Jan 10, 2017, 3:03:24 AM1/10/17
to kivy-...@googlegroups.com
Some working minimal code would help here. A workaround I can think of
is to use on_release instead of on_press for your initial button.
> --
> You received this message because you are subscribed to the Google Groups
> "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

GreyGnome

unread,
Jan 10, 2017, 6:58:29 PM1/10/17
to Kivy users support
I must have a bug. I created a minimal app that added a button on top of a button when said button is pressed, and the new button does not receive any events...

*sigh*  Thanks for the suggestion.

Oon-Ee Ng

unread,
Jan 11, 2017, 3:36:07 AM1/11/17
to kivy-...@googlegroups.com
Another thing to check is whether you have a problem with inheritance
(again, without code I'm only speculating)....

GreyGnome

unread,
Jan 20, 2017, 11:09:41 PM1/20/17
to Kivy users support
I created an app and can demonstrate the behavior. Here it is: https://gist.github.com/GreyGnome/166eb80812afdb95e248a71a47ddccd3 (minus some .png files, but you don't need them).

When one clicks the "New" button in the lower left hand corner, a new widget set is added. That widget set gets the on_press event, as seen in the console:

SubWindow: Added to parent
SubWindow: touch_down ***BIG TITLE***: 0 0 100 100 touch coords: 32.0 29.0
           touch_down: Parent: <kivy.uix.boxlayout.BoxLayout object at 0x7f376a1d2d00>


...Even though it's not fully on-screen yet, it gets events that took place before it existed.

Is it adequate to look at <widget>._trigger_layout._is_triggered in the on_press() method? Because it looks like its value is "True" until the final layout of the widget is completed. Until that point, I can ignore events. If this value is True the first time an event takes place, we should ignore the event. Then we set a flag, then later we can check that flag. At that point we don't worry about _is_triggered... the flag tells us that the widget has been fully implemented.
Message has been deleted

GreyGnome

unread,
Jan 22, 2017, 9:10:21 AM1/22/17
to Kivy users support
On Friday, January 20, 2017 at 10:09:41 PM UTC-6, GreyGnome wrote:
I created an app and can demonstrate the behavior.

So I have routed around this issue by doing this: In the widget class which gets opened under a button that I press, I am putting this in init():
self.had_initial_layout = False
...because during init() it's not laid out properly on the screen (x,y is 0,0 and width, height is 100,100) and _trigger_layout.is_triggered is True. It appears that is_triggered is part of some mechanism that ensures that the widget is repainted as soon as it's put up.

And I am putting this in the callback that's run from the press event. So if we receive an event before the is_triggered is false, we will not do anything. We'll just flag it, and return. Later we will action on it, even if a layout is triggered, because our flag is set:
def press(self, thingy):
if self._trigger_layout.is_triggered and not self.had_initial_layout:
self.had_initial_layout = True
return
# The initial layout must have taken place by this point.
self.had_initial_layout = True
print " press: to be actioned upon!"
 
...Am I using _trigger_layout.is_triggered reliably? Thanks.

GreyGnome

unread,
Jan 26, 2017, 1:24:43 PM1/26/17
to Kivy users support
Bumpity-bump-bump! I just need to know: ".Am I using _trigger_layout.is_triggered reliably?" Thanks.

GreyGnome

unread,
Feb 3, 2017, 8:42:44 AM2/3/17
to Kivy users support
...Bueller...? Bueller...?


On Sunday, January 22, 2017 at 8:10:21 AM UTC-6, GreyGnome wrote:
Reply all
Reply to author
Forward
0 new messages