Link is a ColumnPanel instance ... because reasons

Dudes.

for a control of type Link,

isinstance(control, Link) is True but
isinstance(control, ColumnPanel) is ALSO True.

There may well be good internal reasons that Link is a subclass of ColumnPanel (can’t think of a single one offhand, but hey, you do you!) but if a girl wanted to, say, loop through a form’s components and Do Something to labels and links, and in order to catch everything she would recursively call the routine on containers like FlowPanels and ColumnPanels, the fact that the link would get treated as a container and go off into recursive la la land rather than Do Something would be the kind of bug that might take, you know, a few hours to track down.

So maybe this could go in the documentation or maybe not happen at all?

Thanks,
Heidi

1 Like

Link components are containers - it’s a way to allow any component to be clickable.

Since it’s a container it makes sense that it would inherit from another container so that methods like add_component can be inherited. And would also make sense to be able to loop over a link’s child components in the same way.

While it’s not obvious that this is the case - the api reference does provide the base class for each anvil component:
https://anvil.works/docs/api/anvil#Link

And you’d be forgiven for thinking that the Link component inherited from LinearPanel since that’s what’s listed in the docs :roll_eyes: -

Anvil Documentation Suggestions [ON-GOING]

  • there seem to be some hangovers from this inheritance in the autocomplete (index comes up when you call add component for example)

I’m sure you came up with an alternative code snippet but you might use if type(component) is Link:

1 Like

I didn’t notice that note in the documentation, and the explanation makes sense… thank you! I was able to fix the code by checking for link before the containers. Definitely a case where, it’s not hard to fix it once you figured out what was happening; it was just maddeningly non-obvious,… especially when everything else was working as expected…

1 Like

Though you may not have realized it at the time, this is a specific example of a general technique: When matching items to a position in a hierarchy, always try the most-specific matches (the “leaves” of the “tree”) first.

Edit: clarified “This” in the paragraph above.

Thanks @stucork for clarifying.

I’ve fixed the Link issue in the API Docs - you should see that change on the website in the next few days :slight_smile:

I’ve also made a note to expand the documentation on the Link component to explain that they are containers and inherit from ColumnPanel.

2 Likes

Thank you Bridget! It could be useful to use the link as a container in that way … hadn’t thought of it before! But is there a way to turn the link off??? I’ve started making little flow containers that have both a link and and a label with the same Data assignment, and then if it’s not clickable I make the label visible and the link invisible (and vice versa).

1 Like

A good rule but again, since I didn’t realize the link was at a lower hierarchical level than say Label, it wouldn’t have helped.

That was clear to me. Hence, my post. I was trying to help others see that your solution was much more general than it seemed; that it would apply, in principle, in many other cases they might have.

However, it seems that it came off as a criticism of you. For that, I apologize. I’ve now edited my original post to try to clarify, for a wider readership. If you still feel that it is a criticism, then I’ll delete it.

Here’s some related posts on the topic of disabling links that might be useful

No Enabled Setting For Links In IDE

[CLOSED] Disable a Link component

Just wondering, is there any way I can disable link component?

1 Like

No worries. Not taken as criticism at all. :grinning: