Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Command properties dynamically updatable #2700

Open
mhsmith opened this issue Jul 8, 2024 Discussed in #2691 · 5 comments
Open

Make Command properties dynamically updatable #2700

mhsmith opened this issue Jul 8, 2024 Discussed in #2691 · 5 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@mhsmith
Copy link
Member

mhsmith commented Jul 8, 2024

Discussed in #2691

Originally posted by @rontarrant


Hey, there, all,
I've been playing around with the example in section 4.1.4 of the Toga docs. Just for fun, I decided to have the Action 4 toolbar button change the text in the Action 3 toolbar button.

Here are my modifications:

def action4(widget):
    if cmd3.text == "Action 3":
        cmd3.text = "Non-action"
    else:
        cmd3.text = "Action 3"

    cmd3.enabled = not cmd3.enabled

However, the text on Action 3 didn't change. I threw in a print() statement to make sure the change was actually taking place (and it was) but the only way to see the change in the toolbar button was to remove the entire toolbar and put it back... which—of course—causes the UI to 'jump.'

Question: Is there a way to change the text that's more straightforward? Like, is there a way to access the toolbar button's text directly instead of through the Command object?

Likewise for the Menu item.

@mhsmith mhsmith added the enhancement New features, or improvements to existing features. label Jul 8, 2024
@mhsmith
Copy link
Member Author

mhsmith commented Jul 8, 2024

Originally posted by @freakboy3742


I think this is likely in the space between a feature and a bug. It's a bug in as much as it seems obvious that you should be able to change labels; it's a request for a new feature on the basis that nothing in the docs says that this behavior should be possible.

When you remove then re-add the toolbar, you're forcing a refresh; hence, the new labels are applied. You'd likely find that you'd have the same effect if you added or removed a single item to the toolbar. This is because there is a listener in place on changes to the toolbar, which causes the whole toolbar to be recreated.

So - the simplest "fix" for this would be to modify the property for the command label to trigger an update on any command set it is a part of. The complication here is that the command doesn't know what command sets it is part of.

A better fix would be to connect changes in the command label to the refreshing underlying command implementation, which should give you access to the underlying native menu and toolbar items. This would allow the labels for those items to be updated directly.

@mhsmith
Copy link
Member Author

mhsmith commented Jul 8, 2024

This applies not just to text, but also to all the other properties which don't have a @property method, such as tooltip and group.

It also applies to icon, because even though it is a @property, the setter doesn't pass the value to the implementation layer.

@rontarrant
Copy link

rontarrant commented Jul 8, 2024

Thanks for putting this in your 'TODO' list. 👍

@freakboy3742
Copy link
Member

@rontarrant To set expectations: yes, this is on our "TODO" in the sense that we've recognised the issue as something we'd like to see addressed - but that doesn't mean it's going to be addressed in the near future.

Toga (and the whole of BeeWare) is an Open Source project. The only way to guarantee that something will be fixed is to fix it yourself. We can't provide any guarantees that a someone else will implement a feature, or the timeline on which that will occur. All I can tell you is that this specific issue isn't likely to be on my personal radar for at least 6 months, if not longer.

If this is an issue that impacts you, then I'd encourage you to make an attempt at fixing it. We're happy to provide any assistance or pointers to get you started, and we'll review any contributions that are made (merging once they pass review).

@rontarrant
Copy link

Noted, @freakboy3742 . I've got my hands full already, but I'll add it to my list of things I might get to sometime down the road... if I get some free time. For now, I'll use PySide6 for my current projects. Deadlines, you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

3 participants