Commit Graph

31 Commits

Author SHA1 Message Date
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
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
Darren Burns
9287f64a66 Add isort pre-commit hook, sort imports in src and test directories 2023-02-09 13:28:08 +00:00
Dave Pearson
d350374e59 Revert Tree.clear and add Tree.reset
After some internal discussion we've decided to keep `Tree.clear` as it was,
and add a `Tree.reset`, which does a `Tree.clear` but resets the label and
data of `Tree.root` to the values given, while mirroring how `Tree.__init__`
takes those parameters.
2023-02-01 15:08:03 +00:00
Dave Pearson
78f49f0ab2 Allow replacement of the root node data when clearing the tree 2023-02-01 13:44:53 +00:00
Dave Pearson
ff7f2488f8 Remove Tree class name clash with how pytest works
Just before doing the commit I decided to rename the test tree in the new
unit test for clearing down a tree. Of course I managed to name it in such a
way that it becomes special to pytest.

This fixes that.
2023-02-01 12:45:18 +00:00
Dave Pearson
7563d4cb7e Allow setting a new label when performing a clear on a Tree
See #1437 for background. While it would be ideal to allow for the complete
emptying of a Tree, the root node is required (and it's part of the
construction of a Tree). So, here, when clearing the Tree we optionally
allow for a new label to be given.

Ideally we'll also allow for fresh data to be provided too; but there's a
wrinkle there in knowing the difference between the data being None, and no
data being provided (so the current root's data being carried over).
Following the method of defaulting used in __init__ would cause problems. As
such, rather than roll all of this into one commit, this goes with the basic
requirement and the solution for data will follow.

Note this also starts some unit tests for the clearing of a Tree.
2023-02-01 12:33:36 +00:00
Dave Pearson
6db5217f3e Modify Tree message unit tests to take new action in to account
See #1433.
2023-01-31 13:32:46 +00:00
Will McGugan
475cd4fb1b Merge pull request #1644 from davep/tree-deeply
Add support for a method of expanding/collapsing all tree nodes from a given node down
2023-01-30 16:27:06 +01:00
Dave Pearson
cbe62fadc3 Add unit tests for all the expand/collapse/toggle Tree methods 2023-01-27 13:28:25 +00:00
Will McGugan
3eac79568c remove some pauses 2023-01-26 16:10:13 +01:00
Dave Pearson
4adfe69ec9 Remove TreeNode as a pseudo-widget
This encourages importing it from `textual.widgets.tree` instead, keeping it
in line with the other changes made for #1637.

Note this is a breaking change.
2023-01-23 17:37:58 +00:00
Dave Pearson
d0ea967aa4 Merge branch 'get-treenode-by-id' of github.com:davep/textual into get-treenode-by-id 2023-01-10 15:30:12 +00:00
Dave Pearson
494c63a72b Tweak the unknown node ID exception
See https://github.com/Textualize/textual/pull/1535#discussion_r1065904713
and https://github.com/Textualize/textual/pull/1535#discussion_r1065909144
2023-01-10 15:28:17 +00:00
Dave Pearson
c027a06ee2 Merge branch 'main' into get-treenode-by-id 2023-01-10 14:59:36 +00:00
Dave Pearson
728acc27c0 Introduce an exception specific to handling an unknown node ID
See https://github.com/Textualize/textual/pull/1535#discussion_r1065873649
2023-01-10 14:57:35 +00:00
Dave Pearson
6ea68cc112 Add Tree.get_node_by_id
The thinking here is that a user of a Tree may want to relate notes to other
parts of their UI, or other data in their application. While this could be
done by keeping a reference to the node itself, it could also be beneficial
to just track the ID. Given that ID is a public property of a TreeNode, but
given it doesn't currently have any other (public) purpose, this seems to
add some useful symmetry.
2023-01-10 10:42:07 +00:00
Dave Pearson
489ba10c8a Sprinkle some pauses into the node message tests 2023-01-09 13:36:29 +00:00
Dave Pearson
346659f47f Move typing of the tree into its own class 2023-01-09 13:28:25 +00:00
Dave Pearson
c00a6da90d Check if I need to import from the future for Python 3.8 2023-01-09 13:13:54 +00:00
Dave Pearson
151673cd53 Remove empty docstring 2023-01-09 13:12:57 +00:00
Dave Pearson
0cf299540f Add a message for when a node is highlighted
This is sort of different from selected. Selected is when someone mashes the
enter button or clicks on a node. Highlighted is when the cursor moves into
a new node.

See #1400.
2023-01-09 12:54:57 +00:00
Dave Pearson
6f10c63bb0 Perform tests on all recorded tree events 2023-01-09 12:54:26 +00:00
Dave Pearson
34ff6bf260 Add some unit tests for Tree messages/event handling
I'm about to work on #1400 and it seems like a good idea to put some tests
in place first to ensure nothing gets disturbed.
2023-01-09 11:47:40 +00:00
Dave Pearson
ea8252cfcc Run black over recent Tree tests
Now that we're running black on tests...
2023-01-07 09:30:01 +00:00
Dave Pearson
82dcf62122 Merge pull request #1495 from davep/tree-node-children-prop
Add read-only access to the children of a `TreeNode`
2023-01-06 15:17:39 +00:00
Will McGugan
428ae0e14e Merge branch 'main' into tree-node-parent-prop 2023-01-06 02:11:35 -08:00
Dave Pearson
e5869b9f7b Merge branch 'main' into tree-node-children-prop 2023-01-06 06:18:15 +00:00
Dave Pearson
7779211dcf Add read-only access to the children of a TreeNode
See #1398.
2023-01-05 21:24:47 +00:00
Dave Pearson
27a7cfc489 Add a public read-only parent property to TreeNode
See #1397.
2023-01-05 10:35:25 +00:00
Dave Pearson
d39c59c414 Move the TreeNode label tests into a better-named file
There's going to be a whole bunch of tests relating to the Tree and TreeNode
coming, let's make sure this ends up being fairly granular.

(side thought: it might be a good time soon to revisit all the tests for
Textual and try and wrangle them into some tidy structure)
2023-01-05 10:01:52 +00:00