-
Notifications
You must be signed in to change notification settings - Fork 50
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
What things should and shouldn't be actions? #1397
Comments
After more research, I think that |
I don't think these should be converted to action consumers.
|
|
So does that mean yes to tab and save being an action consumer, but no to enter and arrow keys? I will have to get more familiar with |
As I see it, binds are great for handling key presses in various widgets, and actions are for stuff that was previously handled by the menubar. Some examples:
Maybe you can ask whether it makes sense to do X with the command palette or the menubar. These are action consumers that apply to all or almost all actions. For example:
This should really be documented somewhere, but import tkinter
def foo(event):
print("foo")
def bar(event):
print("bar")
return "break"
def baz(event):
print("baz")
root = tkinter.Tk()
root.bind("<Button-1>", foo, add=True)
root.bind("<Button-1>", bar, add=True)
root.bind("<Button-1>", baz, add=True)
root.mainloop() This will print
I'm pretty happy with |
I think I see the disconnect in how we are thinking about this. To me, "actions" do two things:
Basically, I want to convert the markdown stuff I've been working on into actions, but to do that tab needs to be an action consumer. It doesn't only have to be an action consumer; I certainly agree we shouldn't go and re-work the way that all the bindings work for say, the text widget. Does this make sense at all? Am I missing something? |
I like your markdown list indentation example. It feels like an action, since you might want to trigger it from a toolbar. But there should also be a It is possible to specify a global key binding for an action (currently goes through menubar and keybindings.tcl but rewriting is planned). This won't work well for I think you should simply add an action and a bind. This is basically what the comment_selected_lines plugin does now. It adds a thing to menubar (ideally this would be an action) and makes the text widget do the right thing when a special key is pressed (currently that key is the filetype's comment character): def comment_or_uncomment(tab: tabs.FileTab, pressed_key: str | None = None) -> str | None:
if <some condition>:
return None
<it does stuff here>
return "break"
def on_new_filetab(tab: tabs.FileTab) -> None:
tab.textwidget.bind("<Key>", (lambda event: comment_or_uncomment(tab, event.char)), add=True)
def setup():
menubar.add_filetab_command("Edit/Comment//uncomment selected lines", comment_or_uncomment)
get_tab_manager().add_filetab_callback(on_new_filetab)
... I'd imagine you typically want the bind to check that the action is currently available and then run it (though there's no particular reason why it would need to do exactly that). To make it easier, we could add a class FileTabAction:
...
def invoke(self, tab):
if self.availability_callback(tab):
self.callback(tab) |
I think we are mostly on the same page now, thanks for working through this with me :)
IMO not just because you "might want to trigger it from a toolbar", but also because it is conditionally available (with the same sorts of conditions that other actions use). Even if we weren't wanting to use it in a toolbar I would want it to be an action to reduce the number of places the same sort of conditional availability logic needs to be managed.
I assume you are talking about #1351 / #1346 ?
I'm not 100% sure what you mean by this. In my mind, every time Thinking about it though, you would need a way to return "break" from the action (not currently done). More thought is needed on that.
This makes sense to me. A better way to phrase this whole proposal would have been "I want to have an established pattern for making Actions work with binds".
Yeah that is very similar to how an action looks/works
Or perhaps I'm going to do some playing around with this, and maybe start with the "comment_or_uncomment" plugin instead of Markdown as |
Related to #1305 and #1342
I think
<Tab>
should be an Action consumer, so when it is pressed it checks the registered actions (such as an indenting action, based on the availability callbacks, etc)Other things that I think should be action consumers, with similar logic:
Thoughts?
The text was updated successfully, but these errors were encountered: