Skip to content

Action docs update#3456

Closed
holdenweb wants to merge 2 commits intoTextualize:mainfrom
holdenweb:action-docs-update
Closed

Action docs update#3456
holdenweb wants to merge 2 commits intoTextualize:mainfrom
holdenweb:action-docs-update

Conversation

@holdenweb
Copy link
Copy Markdown
Contributor

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

This is a fairly straightforward rewrite of the actions documentation, which clarifies a few issues that caused me problems.
It doesn't seem significant enough to merit a CHANGELOG entry.

@rodrigogiraoserrao
Copy link
Copy Markdown
Contributor

Hey Steve, I think I'd have an easier time reviewing your changes if you told us exactly what issues you had with the documentation.
For example, are there things you couldn't find that you only figured out through trial and error?
Did you trip in any gotcha(s)?

Comment thread docs/guide/actions.md
## Action methods

Action methods are methods on your app or widgets prefixed with `action_`. Aside from the prefix these are regular methods which you could call directly if you wished.
Actions are handled by _action methods_ of your app or widgets - methods whose names are prefixed with `action_`. These are regular methods which you can call directly, but normally they are triggered by actions.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is partly pedantry and partly a wish to add more context, but "aside from the prefix" seems completely redundant. It's quite probably a matter of taste and style preference.

Comment thread docs/guide/actions.md
```

The `action_set_background` method is an action which sets the background of the screen. The key handler above will call this action if you press the ++r++ key.
The `action_set_background` method is an action method that sets the background of the screen. The key handler above will call this action if you press the ++r++ key.
Copy link
Copy Markdown
Contributor Author

@holdenweb holdenweb Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A method isn't an action, and sloppy usage will inevitably lead to misunderstanding on the part of at least some readers. "Which" is replaced with "that" because a professional copy editor insisted a long time ago that "which" should only follow a comma, beginning a subordinate clause. You may prefer the comma.

Comment thread docs/guide/actions.md
The `action_set_background` method is an action method that sets the background of the screen. The key handler above will call this action if you press the ++r++ key.

Although it is possible (and occasionally useful) to call action methods in this way, they are intended to be parsed from an _action string_. For instance, the string `"set_background('red')"` is an action string which would call `self.action_set_background('red')`.
Although it is possible (and occasionally useful) to call action methods directly in this way, they are more often parsed from an _action string_. For instance, the string `"set_background('red')"` is an action string which would call `action_set_background('red')`.
Copy link
Copy Markdown
Contributor Author

@holdenweb holdenweb Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A re-reading convinces me this change was based on my misreading without the context of visible code, and with that context it looks like a nit-pick. I'll modify the PR to exclude it.

Copy link
Copy Markdown
Contributor Author

@holdenweb holdenweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments weren't meant to be part of a formal review, but it's easier to log them this way than re-create the comments outside a review.

Comment thread docs/guide/actions.md
!!! important

As much as they *look* like Python code, Textual does **not** call Python's `eval` function to compile action strings.
Though they *look* like Python code, Textual does **not** call Python's `eval` function to compile action strings.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is mostly for the benefit of readers whose first language isn't English. While such idiomatic uses are fine for exchange among native speakers, they increase the cognitive load unnecessarily for others.

Comment thread docs/guide/actions.md
- the widget containing the renderable of which the action string is a part,
- the Screen containing that widget, or
- the App

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This insertion is to immediately emphasise that actions are different from events, and processed differently. It's position seems a little incongruous, but then so does a description of action handling under a "Syntax" heading. In any case I feel this point should be emphasised. If I'm the only person who's ever found this problematic you can probably just stop reading this PR now. If included it should occur before "You can specify handling ..." below.

Comment thread docs/guide/actions.md
- Actions may be followed by braces containing Python objects. For example, the action string `set_background("red")` will call `action_set_background("red")`.
- Actions may be prefixed with a _namespace_ (see below) followed by a dot.
- The name of an action (with or without a namespace) on its own will call the action method with no parameters in the given namespace, if any. For example, an action string of `"app.bell"` will call your app's `action_bell()` method.
- The action name may be followed by parentheses optionally containing a list of Python objects, which become parameters to the action method call. For example, the action string `set_background("red")` will first try to call `action_set_background("red")` as a widget method, then as a screen method, and finally as an app method.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simply a refactoring of the explanation. The first bullet explains parameterless actions while pointing out this is orthogonal to the presence of a namespace. The second demonstrates actions with parameters and explains the lookup sequence when no namespace is present. "Braces" was, of course, just plain wrong, so I presume it's a holdover from an earlier design.

Comment thread docs/guide/actions.md
### Parameters

If the action string contains parameters, these must be valid Python literals. Which means you can include numbers, strings, dicts, lists etc. but you can't include variables or references to any other Python symbols.
If the action string contains parameters, these must be valid Python literals. So you can include numbers, strings, dicts, lists etc. but NOT variables or references to any other Python symbols.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simplifying rewording, I felt. Again, perhaps largely a matter of opinion.

@holdenweb
Copy link
Copy Markdown
Contributor Author

Thanks for your comment, Rodrigo.

I did indeed have issues with the documentation, though clearly I only have my own personal experience to go on.

Having learned about events and event-handling, and being somewhat familiar with DOM concepts, I found that the different handling sequence for actions was insufficiently well-explained. In reviewing documentation I try to maintain the viewpoint of someone coming to the software for the first time, which isn't that far wrong in textual's case.

I've added some comments to the changes, and will revert one change immediately.

rodrigogiraoserrao added a commit that referenced this pull request Oct 11, 2023
Thanks to #3456.

Co-authored-by: Steve Holden <steve@holdenweb.com>
@rodrigogiraoserrao
Copy link
Copy Markdown
Contributor

rodrigogiraoserrao commented Oct 11, 2023

While we appreciate the time and effort it takes, it is hard for an external contributor to make non-trivial documentation changes because it is difficult to balance the voice of the documentation, which we want to be consistent, together with the information layout and presentation that suits best each reader.

I've opened #3511 as a follow-up to this PR, making use of some of the more objective improvements that you made with this PR and I've added you as a co-author there.
In addition to that, I will close this PR.

In the future, we encourage you to open (discussion) issues pointing out deficiencies in the documentation so that we can figure out the best way to fix those.
This should help minimise the time you invest in making the changes yourself only to figure out that your personal preferences clash with mine or someone else's.
We'll also change the contributing guide to add information to this end so that others in the future are less likely to hit the same roadblock as you did.

Thanks for your understanding 🙏

@willmcgugan
Copy link
Copy Markdown
Member

@rodrigogiraoserrao You may have to elaborate on "inglorious". I doubt that's the term you were looking for!

@rodrigogiraoserrao
Copy link
Copy Markdown
Contributor

Sorry about that. We have a 🇵🇹 phrase that I tried to translate without success!
I've reworded the “inglorious” bit.

@holdenweb
Copy link
Copy Markdown
Contributor Author

Thanks very much for the feedback. I'll engage more closely on Discord before making a PR in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants