Commit Graph

5587 Commits

Author SHA1 Message Date
Dave Pearson
858d228da9 Fix a concerning typo 2023-03-07 13:02:01 +00:00
Dave Pearson
2047fda57d Rebuild the FAQ 2023-03-07 12:56:27 +00:00
Dave Pearson
c049888f55 Flesh out the list of problems with Terminal.app 2023-03-07 12:52:43 +00:00
Dave Pearson
3039a3fc62 Add a comment to explain the content of the warning list 2023-03-07 12:50:35 +00:00
Dave Pearson
ff532227d6 Reword the warning and link it to the FAQ entry 2023-03-07 11:51:08 +00:00
Dave Pearson
56ba7d9cc7 Add a FAQ about the default macOS terminal.app 2023-03-07 11:26:03 +00:00
Dave Pearson
e925eb7c81 Add a post-run warning hook, and test for macOS Terminal.app
This will change, this is more of a placeholder to test things. I'm next
going to write a FAQ and then we'll point to that.
2023-03-07 11:15:45 +00:00
Dave Pearson
fcc16c0e59 Correct the example Python code for the border style (#1956)
To the best of my knowledge, and in testing myself, border and border_* are
properties of a widget's `styles` property, they're not a property of the
widget itself.
2023-03-07 09:28:02 +00:00
Will McGugan
864931e94b Compound docs (#1952)
* compound example

* update bit switch

* prevent

* no css

* compound widget example

* more diagrams

* more diagrams

* diagrams

* words

* words

* remove sender

* removed priority post

* timer fix

* test fixes

* drop async version of post_message

* extended docs

* fix no app

* Added control properties

* changelog

* changelog

* changelog

* fix for stopping timers

* changelog

* docs update

* last byte example

* new section

* update of byte03

* updae to docs

* Added compound examples

* Rewording

* Use set sender

* don't need this

* hyphens

* Update docs/guide/widgets.md

Co-authored-by: Dave Pearson <davep@davep.org>

* Update docs/guide/widgets.md

Co-authored-by: Dave Pearson <davep@davep.org>

* Update docs/guide/widgets.md

Co-authored-by: Dave Pearson <davep@davep.org>

* Update docs/guide/widgets.md

Co-authored-by: Dave Pearson <davep@davep.org>

* Update docs/guide/widgets.md

Co-authored-by: Dave Pearson <davep@davep.org>

* Update docs/guide/widgets.md

Co-authored-by: Dave Pearson <davep@davep.org>

* Update docs/guide/widgets.md

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Update docs/guide/widgets.md

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Update docs/guide/widgets.md

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Update docs/guide/widgets.md

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* parenthesis

* stack diagram

---------

Co-authored-by: Dave Pearson <davep@davep.org>
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-06 16:56:24 +00:00
darrenburns
fd0e0d9983 Datatable extend background (#1946)
* Extending DataTable widget horizontally

* Fading background of extended DataTable rows

* Updating DataTable snapshots

* Update CHANGELOG.md

---------

Co-authored-by: Will McGugan <willmcgugan@gmail.com>
2023-03-06 16:27:29 +00:00
Dave Pearson
98cc1a7174 Merge pull request #1951 from davep/windows-friendly-toggle-buttons
Windows-friendly toggle buttons
2023-03-06 14:40:27 +00:00
Rodrigo Girão Serrão
8facffe8bc Merge pull request #1950 from Textualize/docs-patch
Add subsection to separate example.
2023-03-06 14:18:51 +00:00
Dave Pearson
286293b810 Update the ChangeLog 2023-03-06 13:54:58 +00:00
Rodrigo Girão Serrão
8b70a464d7 Add subsection to separate example. 2023-03-06 13:54:01 +00:00
Dave Pearson
6ba1905d4a Swap the radio button character
See #1934. Simply put: the character that we were using doesn't render well
at all in Windows Terminal on Windows 10 or 11. This one isn't ideal as it
sits a little low, at least in some environments. I want to try this one on
for a wee bit and see how we feel about it.

Honestly, I'm not 100% happy with it; but right now it's the least-worst
option I've tried.
2023-03-06 13:50:28 +00:00
Dave Pearson
f59977563f Merge branch 'main' into windows-friendly-toggle-buttons 2023-03-06 12:42:33 +00:00
Rodrigo Girão Serrão
294213e0a1 Update radio_set_changed.py (#1947)
In the aftermath of #1935 and #1940 this fell through the cracks.
2023-03-06 12:04:22 +00:00
Will McGugan
6d2e53c380 fix time (#1948)
* fix time

* no longer needed
2023-03-06 11:52:42 +00:00
Dave Pearson
f7a6981abf Swap the checkbox character to an X
See #1934. Simply put: the character that we were doesn't render well at all
in Windows Terminal on Windows 10; while there are other options available,
few seem to work well there either. So here we go for a bold X; this should
render fine everywhere.
2023-03-06 11:19:29 +00:00
Rodrigo Girão Serrão
8c59ba9875 Merge pull request #1926 from Textualize/fix-1815
Minor `keys.py` tidy up.
2023-03-06 11:14:20 +00:00
Rodrigo Girão Serrão
6c27bcfc33 Update changelog. 2023-03-06 11:07:10 +00:00
Rodrigo Girão Serrão
51a9eb4a88 Merge branch 'main' into fix-1815 2023-03-06 11:04:31 +00:00
Rodrigo Girão Serrão
571c2c3be5 Restore print. 2023-03-06 11:04:18 +00:00
Dave Pearson
623b70d4ac Add an example of using a RadioSet.Changed message (#1935)
Unlike a few other widgets, the RadioSet is pretty much all about reacting
to the selection result; the question of how you go about it has already
come up and while the message is documented, complete with all properties,
it can't hurt to have an illustrative example of code that uses it.

Here I add an extra RadioSet example that sits with the message in the
reference. This should help the reader better follow how to use it, and also
gives something to link to if someone hasn't got that far into the
documentation yet but is attempting to use the RadioSet.
2023-03-06 10:53:12 +00:00
Will McGugan
373fc95fc1 Drop explicit sender attribute from messages (#1940)
* remove sender

* removed priority post

* timer fix

* test fixes

* drop async version of post_message

* extended docs

* fix no app

* Added control properties

* changelog

* changelog

* changelog

* fix for stopping timers

* changelog

* added aliases to radio and checkbox

* Drop sender from Message init

* drop time

* drop cast

* Added aliases
2023-03-06 10:52:34 +00:00
Will McGugan
cb84d9111c Added typing for watch callbacks (#1929) 2023-03-03 11:29:49 +00:00
Rodrigo Girão Serrão
b88e4b08b4 Use keys.py utility functions consistently. 2023-03-02 17:32:23 +00:00
Rodrigo Girão Serrão
7acacf0746 Allow conversion to and from unicode names.
Throughout the code base, there are a couple of places (noted in #1830) where we take a Unicode name and make it more friendly, or take a 'friendly' name and try to recover the original Unicode name. We add a function to go from 'friendly' to the Unicode name, which tackles the issue highlighted in #1815.

Related issues: #1815, #1830.
2023-03-02 17:31:55 +00:00
Rodrigo Girão Serrão
b6b76025d0 Add regression test for #1815. 2023-03-02 17:21:19 +00:00
Will McGugan
203b31d30d fix date 2023-03-02 15:27:23 +00:00
Will McGugan
55fc89cf14 changelog v0.13.0 2023-03-02 14:51:59 +00:00
Will McGugan
2bf3ed1fea version bump (#1923) 2023-03-02 14:50:21 +00:00
Will McGugan
41003e356c Fix content width (#1910)
* fix calculation for scrollbars

* added snapshot

* fix for name change

* snapshot

* fix for textual colors

* remove logs

* scrollbar logic

* scroll logic

* remove dead code

* snapshot tests

* scrollbar mechanism

* tidy

* demo tweak

* preset window size

* no need for repaint

* Restore repaint

* wait for idle on pause

* colors tweak

* remove wait for idle

* snapshot

* small sleep

* change stabilizer

* debug tweaks

* remove debug

* remove debug

* snapshot test

* docstring

* changelog

* add pause
2023-03-02 14:39:31 +00:00
Dave Pearson
88a0349cb6 Merge pull request #1917 from davep/button-docs-widget-redux
Tidy up some Button documentation
2023-03-02 13:29:49 +00:00
Dave Pearson
0df17fc8f0 Tidy up some Button documentation
Adds missing documentation for disabled to each of the button variant
constructors, and also pulls in a couple more public-visible Button-related
types into the docs.
2023-03-01 16:46:47 +00:00
Dave Pearson
086c7d6688 Merge pull request #1909 from davep/widget-doc-sweep
Widget documentation sweep
2023-03-01 16:43:09 +00:00
Dave Pearson
d9ab2ac69c Remove omit a unnecessary word
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-01 16:21:58 +00:00
Dave Pearson
5cfa998fe4 Improved wording
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-01 16:20:52 +00:00
Dave Pearson
88fcf4f070 Improved wording
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-01 16:18:47 +00:00
Dave Pearson
b3fe97e8b4 Improved wording
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-01 16:17:12 +00:00
Dave Pearson
b1c6da2169 Improved wording
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-01 16:16:56 +00:00
Dave Pearson
348fbe2cfa Improved wording
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-03-01 16:16:41 +00:00
Dave Pearson
768d4ae864 Code tidy
Tidying up after an on-forge merge conflict resolution that of course ended
up bypassing black.
2023-03-01 16:11:54 +00:00
Dave Pearson
847e2ccc1a Merge branch 'main' into widget-doc-sweep 2023-03-01 16:07:36 +00:00
Dave Pearson
f439fa90c4 Merge pull request #1915 from davep/interdoc
Interlink the docs with the Python and Rich manuals
2023-03-01 16:05:47 +00:00
Rodrigo Girão Serrão
ed28a7019c Make mypy happy (#1831)
* Helper file for error progress tracking.

* Fix typing of Keys.???.value.

* Assert that we have frame information.

@willmcgugan I went with the asserts because the tone of the code tells me that we are kind of certain that the current and previous frames always exist. Should the function be refactored to handle None for the previous frame (or the current & previous frames) by writing to the buffer without caller information, for example?

* Use inspect.Traceback instead of inspect.FrameInfo.

Looks like the two shared a lot of attributes, so we were trying to use FrameInfo but inspect.getframeinfo returns a Traceback, so that felt like the correct type to use.

* Update after installing msgpack-types.

* Assert we have frame info.

Same fix as in b709219.

* Fix MapGeometry order information typing.

There was another alternative solution, which was to just flatten everything entirely, so that the code actually obeyed the comments.
After all, the comments for the attribute `order` in the definition of `MapGeometry` said that `order` was a tuple of integers defining the painting order, which was not true because the very first widget was having its order defined as `order = ((0,),)` instead of `order = (0,)`.
Thus, another possible solution would be to retype `order` as `tuple[int, ...]` and make everything flat, but I opted for the “tuple of tuples” approach because the sub-tuples will highlight the nested structure of the DOM hierarchy.

* Fix import and typing for fromkeys.

* Assert app is not None.

[skip cli]

* Import missing type.

* Use CallbackType for event Callback.

* Remove variable name clash.

* Ensure ScalarAnimation only receives widgets.

Two other alternatives would be:
 - leave typing of 'widget: DOMNode' and then assert 'widget' is actually of type 'Widget', which works just fine but looks weird in the sense that we type a parameter in one way but then only manage to do any work if it is of another type;
 - type it as 'widget: DOMNode | Widget' and set 'size' to something other than 'widget.outer_size' if 'widget' is a 'DOMNode'.

* Count spacing values as 1 for int instance.

Adding an 'assert not isinstance(spacing, int)' before raising the error sounds reasonable, because 'Spacing.unpack' seems to be able to handle a lone integer just fine, but I decided against it because I would not like to raise an assertion error from within an exception handling inside Textual.
So, to keep it on the safer side, I went with the conditional expression that checks if we have an integer or a tuple.

* Use correct default.

The obvious fix would be to do 'default_factory=RulesMap' but mypy will infer that the type of 'RulesMap' is 'type[RulesMap]' and will not see it as a 'Callable[[], RulesMap]'. That could be fixed by using 'cast'. I decided to use 'RulesMap.__call__'.

[skip ci]

* Use correct abstract methods.

We fix the LSP violation by using the abstract methods that the ABC already provides... Which is a shame, because I thought I was about to write my first Protocol.

* Add missing annotation.

* Fix type inference.

* Check token is not None.

* Revert "Check token is not None."

This reverts commit 0ae463366e.
Upon closer look, this is not the correct fix.

* Check that token is not None.

Checking if the token is not 'None' brings us a tiny step closer to fixing #1849, which still needs to ensure the variable definition is complete and valid, even if empty.

* Type DOMQuery instantiation correctly.

After some fiddling, some crying, and talking to Dave and Will, we got to a partial solution.
I cried a bit more and came up with the fix that entailed lifting 'ExpectType' to outside of 'DOMNode'.
Then, I realised 'ExpectType' and 'QueryType' from 'query.py' were essentially the same thing so I decided to only make use of 'QueryType'.

* Infer correct type while walking.

* Cast to remove doubt about None.

mypy can't infer that if after is None, then before won't.

* Explicitly type variable.

* Cast to console renderable.

@willmcgugan did I understand correctly that this 'cast' is exactly what renderable being possibly a 'RichCast' asks me to do..? To be honest, I was not 100% sure after reading rich's documentation for 'RichCast' and after reading the source of 'rich_cast'.

* Type variable to remove literal ambiguity.

mypy was inferring the type of the empty string as a literal and thus was not type checking the fact that 'render' would either be a string or Text.

* Assert scrollbars always have parents.

* Make scrollbar scroll actions synchronous.

The scrollbars were posting the messages and awaiting for them but that's not what Widget does, which handles scrolling synchronously. Thus, I made them synchronous methods by using 'post_message_no_wait'.

* Use link only when available.

* Update errors.

* Relax type inference.

* Ignore missing imports for uvloop.

'uvloop' is completely optional and this code only exists to cater for the case where the user _already_ has uvloop installed.
With that in mind, it makes sense to silence errors about uvloop not being available because we don't need to know about that.
We only care if uvloop happens to be installed.

* Enable variable reuse.

* Fix type issues in easing.py.

* Fix typing issues in demo.

Fixing the typing issues here involved making use of the messaging features to replace a method (wasn't exactly wrong, but this is more in line with the Textual way of doing things, which should be prevalent in the demo of the framework).
We also dealt with a typing issue in DarkSwitch.on_dark_change by deleting an unnecessary parameter, but the underlying problem is unsolved and was logged as issue #1865.

Related issues: #1865.

* Fix typing issues in _doc.py.

* Type actions with a type alias.

* Make return values optional.

As per discussion with @darrenburns.

* Make StringKey idempotent.

This set up is so that we can easily make sure that a variable of the type str | SK (where SK is a subclass of StringKey) becomes of the type SK.
Instead of having to write a conditional expression to only convert in case of a string, we make SK idempotent so that we can just call it on the value that may still be a string.

* Make sorting type safe.

* Fix typing of StringKey.__new__.

This is needed to ensure the type checkers know the exact type of the instances returned when instantiating subclasses of StringKey.

* Add explicit type variables.

* Type-safe line rendering.

* Type safe _render_line_in_row.

* Type safe _render_cell.

* Type safe ordered_rows property.

* Type safe ordered_columns property.

* Simplify handling of Nones in TwoWayDict.

In the beginning of the work on this PR, mypy flagged two issues in the implementation of TwoWayDict, which would return None when the keys/values were not available but the signatures of get/get_key did not have the missing '| None'.
When I added the '| None' to the return values of TwoWayDict.get and TwoWayDict.get_key, many new errors popped up because the implementation of DataTable assumes, in many different places, that those methods return the exact thing that we asked for, and not None.

To fix this, I started going over the call sites for get/get_key and started adding checks for 'None' and raising the appropriate RowDoesNotExist/ColumnDoesNotExist error.

At some point, I realised that went a little bit against the semantics of the code, which pretty much assumes those accesses WILL work.

So, I subclassed TwoWayDict to specialise it even further to this use case.
The subclass is meant to work with RowKey/ColumnKey as the underlying keys and it will automatically raise an error if the access fails.

CC: @darrenburns.

* Make use of idempotency of StringKey subclasses.

* Make message aware of type of sender.

* Only select when possible.

* Fix typing of reactive attribute.

* Reset cursor upon moving action if needed.

* Assure mypy we have ListItems.

This could be improved (as in, cast wouldn't be needed) if #1871 is resolved favourably.

* Add explicit return.

* Ignore argument types to watch.

Related issues: #1865.

* Type safe App._register.

* Redirect output to void.

* Remove helper file.

* Fix Python compat. issues.

* Button can only accept str/Text as label.

Fixes: #1870.

* Add runtime type check for list items.

This change follows from a discussion in issue #1871.

* Address review comments.

* Revert "Fix typing issues in demo."

This reverts commit f366783920.

* Address review comments.

Related comments: https://github.com/Textualize/textual/pull/1831\#discussion_r1118155296

* Add clarifying comment.

See: https://github.com/Textualize/textual/pull/1831\#discussion_r1118154777

* Revert changes to data table.
2023-03-01 15:50:15 +00:00
Dave Pearson
9fa10ecc18 Interlink the docs with the Python and Rich manuals
All through our docs there are mentions of Python types and also Rich types.
This change will make the vast majority of mentions of them into actual
links that people can follow. So now, for example, when someone sees a
method that returns a `Style`, they can click on it and see what a `Style`
actually is.
2023-03-01 15:42:38 +00:00
Dave Pearson
aa96b54263 Final back-read, typo squishing and markup-fixing
Delivering on a promise made in #1920.
2023-03-01 14:59:36 +00:00
Dave Pearson
24fa963241 Tidy up the docstring of Widget.scroll_to_region
Delivering on a promise made in #1920.
2023-03-01 14:54:28 +00:00
Dave Pearson
53b0e54e9d Tidy up the docstring of Widget.scroll_to_widget
Delivering on a promise made in #1920.
2023-03-01 14:53:59 +00:00