Raise Event on Children - Not being picked up

Hi,

I am trying to use “raise-event on children” to raise events on forms that are loaded dynamically by a “Main” form.

Main Form

  1. has timer component, set to 5 second interval in design mode
  2. has column panel & flow panel that contain 4 forms (as components)
  def timer_1_tick(self, **event_args):
    """This method is called Every [interval] seconds. Does not trigger if [interval] is 0."""
    self.content_panel.raise_event_on_children("x-Timer-Tick")

Child Form

def __init__(self, tabSize = 400, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

    # Set Form Event Handlers
    self.set_event_handler("x-Timer-Tick", self.TimerTick)

def TimerTick(self, **kw):
    print('feed timer tick')  # this never prints

To make sure that the event was working within the Child Form, I tested it by raising the event at the end of the init and that worked great.

So it would seem to me that the raise_event_in_children isn’t raising it in what I would have considered to be a child form?

Any help is appreciated!

I’m wondering if the child form is a direct child of self.content_panel. If not, I don’t think the event will get raised on the child form.

If so, can you share a clone link to an app exhibiting this behavior?

I can’t provide more insight than what @hugetim already did above. But I found the Publisher in Anvil Extras Library to pretty useful in situations like these :slight_smile:

1 Like

That Publisher looks like it’ll do the trick!

This may be a silly question, but why are things like this in the “extras” and not just in Anvil itself? (ie, in the docs)

1 Like

I tend to agree with you that some things like that probably should be included in standard Anvil (and such feature requests are welcomed and often acted upon by Anvil staff), but these are the kinds of considerations that make it a tough call: Adding to the Stdlib (Adding to the Python standard library is obviously not the same, but I hope it’s a helpful analogy nonetheless.)

1 Like