Commit Graph

1181 Commits

Author SHA1 Message Date
Dave Pearson
2d75ca0d77 Merge pull request #2536 from davep/expand-tree-expand-messages
Ensure that `TreeNode` messages are posted when via-API changes are made
2023-05-10 14:18:24 +01:00
Rodrigo Girão Serrão
8dd627b0f4 Merge branch 'main' into sub-title-str 2023-05-10 13:10:48 +01:00
Dave Pearson
28be54d10d Merge branch 'main' into expand-tree-expand-messages 2023-05-10 10:12:58 +01:00
Dave Pearson
f19f46bba0 Merge pull request #2519 from davep/cygnus-x-1
Fix for `resolve_fraction_unit` zero division error (#2502)
2023-05-10 10:10:55 +01:00
Dave Pearson
c7fc66fa6c Ensure that TreeNode messages are posted when via-API changes are made
Until now the Tree.NodeExpanded and Tree.NodeCollapsed messages were only
sent out when changes were made to the tree by user interaction. This meant
that if any changes were made with the TreeNode expand, expand_all,
collapse, collapse_all, toggle or toggle_all API calls no messages would be
sent.

This PR corrects this.

The work here is, in part, required for #2456 (DirectoryTree lazy-loads
directory information on node expansion so if someone is expanding nodes
under code control the DirectoryTree never gets to know that it should load
a directory's content) and will build on #1644, essentially adding a missing
aspect to the latter PR.
2023-05-10 09:24:07 +01:00
Rodrigo Girão Serrão
e8baf52bdd Allow setting (sub)title of any type.
Related issues: #2521.
2023-05-09 16:56:56 +01:00
Dave Pearson
8855471125 Merge pull request #2522 from davep/move-widget-enhanced-testing
Make the widget moving tests more granular and add more tests
2023-05-09 15:07:59 +01:00
Dave Pearson
a0558e87d8 Merge branch 'main' into cygnus-x-1 2023-05-09 13:38:16 +01:00
Dave Pearson
ee70713002 Simplify the resolver zero division bug unit test 2023-05-09 13:35:55 +01:00
Dave Pearson
d3de6d1587 Make the widget moving tests more granular and add more tests
Adds two (currently xfail) tests to illustrate #1743
2023-05-09 11:19:00 +01:00
Dave Pearson
a77dbf4bee Tentative fix for resolve_fraction_unit ZeroDivision error
I'll admit to not really following what the code does, so will really need
someone with a better understanding of the aim of this code to look over the
proposed fix; but based on a bunch of runs and hand-debugging, this seems to
do the job.

This passes all existing tests and also removes the reported error.

On the other hand I'm not confident that I'm *not* just masking an
underlying issue with this function.
2023-05-09 10:38:09 +01:00
Dave Pearson
a5cc96cbc7 Make a pass of the #2502 test a fail
If/when I get this actually passing, I want the test to appear to fail so I
know things have changed for the better.

This makes sense, trust me.
2023-05-09 09:44:51 +01:00
Dave Pearson
052ec83b7a Make the test as small as possible 2023-05-09 09:44:30 +01:00
Dave Pearson
089dce1b41 Add a unit test for #2502
Currently marked as xfail, but this gets it down to the most basic level.
2023-05-09 09:39:12 +01:00
Rodrigo Girão Serrão
855c90d4f0 Extend @on decorator to filter matchable attributes (#2498)
* Add tests for #2484.

* Implement @on extension.

[skip ci]
Related issues: #2484.

* Changelog.

* Add missing @on test.

* Remove debug prints.

* Document changes.

* Update tests.

Test now fully works, as of #2490.

* Cache parsed selectors.

* Streamline exit condition.

* Fix typing.

* More succint wording.

* Document 'on' kwargs.

* Update src/textual/_on.py

Co-authored-by: Will McGugan <willmcgugan@gmail.com>

* Update docs/guide/events.md

Co-authored-by: Will McGugan <willmcgugan@gmail.com>

* Change 'on' API.

* Remove example code.

* Address feedback.

* Update src/textual/_on.py

Co-authored-by: Will McGugan <willmcgugan@gmail.com>

* Address review feedback.

* Fix #2499.

* don't require control to be manually specified

* update docstring

* deleted words

---------

Co-authored-by: Will McGugan <willmcgugan@gmail.com>
2023-05-08 17:30:07 +01:00
Will McGugan
7db7139bb8 Select widget (#2501)
* overlay rule

* select WIP

* select control, made binding description optional

* changelog

* style tweak

* Added constrain

* changelog

* test fix

* drop markup, tidy

* tidy

* select namespace

* tests

* docs

* Added changed event

* changelog

* expanded

* tests and snapshits

* examples and docs

* simplify

* update reactive attributes

* type fix

* docstrings

* allow renderables

* superfluous init

* typing fix

* optimization

* revert optimizations

* fixed words

* changelog

* docstrings

* don't need this

* changelog

* comment

* Update docs/widgets/select.md

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

* review changes

* review updates

---------

Co-authored-by: Dave Pearson <davep@davep.org>
2023-05-08 10:55:39 +01:00
Dave Pearson
c2a19bd632 Merge pull request #2510 from davep/chainsaw
Add the ability to remove nodes from a `Tree`
2023-05-08 10:51:44 +01:00
Dave Pearson
0bb0f4d179 Merge pull request #2508 from davep/add-options
Add `add_options` to `OptionList`
2023-05-08 10:51:15 +01:00
Rodrigo Girão Serrão
819b2f1eb3 Add DataTable.move_cursor (#2479)
* Add 'DataTable.move_cursor'.

Related issues: #2472.

* Fix #2471.

* Simplify cursor changes.

* Address review feedback.

Related comments: https://github.com/Textualize/textual/pull/2479\#discussion_r1185016002
2023-05-08 10:44:34 +01:00
Dave Pearson
745d595d4a Add unit tests for the new node removal methods
See #2462.
2023-05-08 09:55:32 +01:00
Dave Pearson
84ddd09223 Add extra snapshit tests
This tests the three main ways of making an option list, and ensures they
all turn out the same.
2023-05-07 20:26:12 +01:00
Dave Pearson
8be87d5931 Merge branch 'main' into add-options 2023-05-07 18:06:57 +01:00
Dave Pearson
010356a23e Allow zero items to be passed to add_options and do zero work 2023-05-07 18:01:56 +01:00
Dave Pearson
b44983e8d4 Add an add_options method to the OptionList
In doing so, pretty much make the add_option code into the add_options code,
and then just have add_option call add_options.

See #2507.
2023-05-07 17:56:02 +01:00
Dave Pearson
6139c95f3a Test that the event aliases are actually the same reference
I thought I thought I wanted what I thought but now I think about it I think
I thought wrong and now I think better.
2023-05-04 16:43:20 +01:00
Dave Pearson
8b36d29e74 Add a test for a radio set getting focus when a button gets clicked 2023-05-04 16:22:39 +01:00
Dave Pearson
19f4f64d96 Add tests for selection navigation in a radioset with no buttons pressed 2023-05-04 15:39:33 +01:00
Dave Pearson
e7d3b94334 Test that radioset wraps around when going off the bottom 2023-05-04 15:25:33 +01:00
Dave Pearson
b1443c0162 Test that radioset wraps around when going off the top 2023-05-04 15:22:30 +01:00
Dave Pearson
2113f415a0 Add a test that toggling a pressed radio button has no effect 2023-05-04 15:17:52 +01:00
Dave Pearson
b7cdbb0baa Test to ensure that Changed.control is Control.checkbox 2023-05-04 15:12:15 +01:00
Dave Pearson
0b4d7fb091 Test to ensure that Changed.control is Control.radio_button 2023-05-04 15:10:45 +01:00
Rodrigo Girão Serrão
3728555fbd Scroll cursor into view. (#2464)
* Scroll cursor into view.

Related issues: #2459.

* Add regression test.

* Update changelog.
2023-05-03 13:57:04 +01:00
Will McGugan
41dbc66b23 optimize focus (#2460)
* optimize focus

* immediate call

* update previews

* snapshot
2023-05-03 11:48:56 +01:00
Will McGugan
91a9d570a4 On decorator (#2453)
* Add on decorator

* decorator code

* docs for on decorator

* Examples

* test errors

* simplify listing

* words

* changelog

* Update docs/guide/events.md

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

* Update docs/guide/events.md

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

* Update docs/examples/events/on_decorator.css

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

* Update docs/guide/events.md

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

* rewording

* comment

* clarification

* Added note

---------

Co-authored-by: Dave Pearson <davep@davep.org>
Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2023-05-02 16:17:40 +01:00
Dave Pearson
2ad3903d43 Remove the bytewise diffing of failed snapshots
In doing so this removes the file similarity value, and as such the key that
the failure report was sorted on. This was done because, given how many
snapshot tests we have now, if lots failed, it would take a long time (often
many minutes) to compile the report.

The report is now sorted on the test name.

Now, no matter how many snapshots fail, the report should be produced pretty
much instantly.
2023-05-02 13:47:18 +01:00
Dave Pearson
27ca4969a8 Add tests for styles that have "sub-styles" and !important
This is a series of tests for checking styles that have sub-styles, or
sub-parts, or whatever the correct name would be; the testing being that if
!important is applied to the whole, that it works.

Starting with #2420 it became apparent that this didn't work as intended,
and once that work started it became obvious that it affected more than just
border.

So these tests test all of the styles that can be specified as a single
whole, or as a set of parts (sides, directions, etc).
2023-05-02 09:36:08 +01:00
Will McGugan
83b1fcc102 raise attribute error (#2443)
* raise attribute error

* fix compute defaults
2023-05-01 16:57:40 +01:00
Will McGugan
20a1612361 Invalid pseudo selectors (#2445)
* token error

* error on bad pseudo selectors
2023-05-01 16:22:35 +01:00
Dave Pearson
54db445dd7 Change private watcher support call public and private if available
See https://github.com/Textualize/textual/pull/2442#issuecomment-1529512891

This changes the original PR so that, rather than calling a private watcher
instead of a public, as originally issued, we now call public and private,
if they're both there.

If they are both there private is called first.
2023-05-01 10:28:55 +01:00
Dave Pearson
847fd6e69e Add support for private watch methods
This change allows for private watch methods. By convention they start with
an underscore. If a reactive or var has a private watch method, it will be
used in preference to a public watch method.

With this change it becomes easier to have a private reactive/var whose
watcher is also private. For example:

    _counter = var(0)
    """This is a private counter, it won't appear in the docs."

    ...

    def _watch__counter(self) -> None:
        """Watch _counter, but don't appear in the docs either."
        ...

See #2382.
2023-05-01 10:01:50 +01:00
Dave Pearson
02ed90c633 Add TreeNode.tree
Currently, in the various TreeNode messages, and the handlers you'd write to
handle them, there's no way to easily know *which* tree sent the message and
so which tree the node belongs to.

This commit adds public access to the tree reference to the nodes, so that
in an event handler the developer can check the tree involved in the event.

See #2413.
2023-04-28 10:23:38 +01:00
Will McGugan
124c45e68c Bump0220 (#2405)
* Version bump

* upate version

* fix domain name

* wrong project

* skip on Windows

* disable demo snapshot

* 37 fix
2023-04-27 15:01:46 +01:00
Will McGugan
dd70a7a2dc fix for min and max with fr unints (#2390)
* fix for min and max with fr unints

* snapshit

* forgot snapshit tests

* fix resolve

* added unit tests

* Windoze fix
2023-04-27 13:35:16 +01:00
Rodrigo Girão Serrão
4148b1d450 Implement a Progress Bar widget. (#2333)
* First prototype of PB.

* Repurpose UnderlineBar.

* Factor out 'Bar' widget.

* Revert "Factor out 'Bar' widget."

This reverts commit 0bb4871adf.

* Add Bar widget.

* Cap progress at 100%.

* Add skeleton for the ETA label.

[skip ci]

* Add ETA display.

* Improve docstrings.

* Directly compute percentage.

* Watch percentage changes directly.

[skip ci]

* Documentation.

* Make reactive percentage private.

Instead, we create a public read-only percentage property.

* Update griffe to fix documentation issue.

Related issues: #1572, https://github.com/mkdocstrings/griffe/issues/128.
Related PRs: https://github.com/mkdocstrings/griffe/pull/135.

* Add example and docs.

* Address review feedback.

[skip ci]

* More documentation.

* Add tests.

* Changelog.

* More tests.

* Fix/fake tests.

* Final tweaks.
2023-04-26 15:25:39 +01:00
Dave Pearson
7a536c790c Demo snapshot test back up to a 250 wait
Waiting 100 resulted in a fail, so let's bump back up again.
2023-04-25 15:49:43 +01:00
Dave Pearson
db45287646 Lower the wait for the demo snapshot test
250 worked; so let's try it lower.
2023-04-25 15:41:02 +01:00
Dave Pearson
88926a4bb8 Force a wee wait when testing the demo
This keeps randomly failing in Windows in CI; multiple subsequent runs gets
it going in the end, normally one further fail at a time. So let's throw a
wee wait on the end and see if that helps.
2023-04-25 15:27:43 +01:00
Dave Pearson
c45f9358ee Change RadioSet so it's less a container of widgets and more a widget
Initially we went with a RadioSet being a simple container of RadioButtons,
with the user navigating the RadioButtons like you would any other set of
widgets. This was fine but it became pretty clear pretty quickly that having
to tab through a non-trivial collection of buttons in a set to get to the
next widget wasn't ideal.

This commit, satisfying #2368, takes over the navigation of the buttons
within the container, makes the container itself a focusable widget, and
sets up some new bindings to allow a more natural and efficient interaction
with the set.
2023-04-25 15:00:44 +01:00
Dave Pearson
a6a373161f Add some unit testing of the new navigation 2023-04-25 12:06:46 +01:00