|
| 1 | +--- |
| 2 | +draft: true |
| 3 | +date: 2022-11-08 |
| 4 | +categories: |
| 5 | + - Release |
| 6 | +authors: |
| 7 | + - willmcgugan |
| 8 | +--- |
| 9 | + |
| 10 | +# Version 0.4.0 |
| 11 | + |
| 12 | +We've released version 0.4.0 of [Textual](https://pypi.org/search/?q=textual). |
| 13 | + |
| 14 | +As this is the first post tagged with `release` let me first explain where the blog fits in with releases. We plan on doing a post for every note-worthy release. Which likely means all but the most trivial updates (typos just aren't that interesting). Blog posts will be supplementary to release notes which you will find on the [Textual repository](https://github.com/Textualize/textual). |
| 15 | + |
| 16 | +Blog posts will give a little more background for the highlights in a release, and a rationale for changes and new additions. We embrace *building in public*, which means that we would like you to be as up-to-date with new developments as if you were sitting in our office. It's a small office, and you might not be a fan of the Scottish weather (it's [dreich](https://www.bbc.co.uk/news/uk-scotland-50476008)), but you can be here virtually. |
| 17 | + |
| 18 | +<!-- more --> |
| 19 | + |
| 20 | +Release 0.4.0 follows 0.3.0, released on October 31st. Here are the highlights of the update. |
| 21 | + |
| 22 | +## Updated Mount Method |
| 23 | + |
| 24 | +The [mount](/api/widget/#textual.widget.Widget.mount) method has seen some work. We've dropped the ability to assign an `id` via keyword attributes, which wasn't terribly useful. Now, an `id` must be assigned via the constructor. |
| 25 | + |
| 26 | +The mount method has also grown `before` and `after` parameters which tell Textual where to add a new Widget (the default was to add it to the end). Here are a few examples: |
| 27 | + |
| 28 | +```python |
| 29 | + |
| 30 | +# Mount at the start |
| 31 | +self.mount(Button(id="Buy Coffee"), before=0) |
| 32 | + |
| 33 | +# Mount after a selector |
| 34 | +self.mount(Static("Password is incorrect"), after="Dialog Input.-error") |
| 35 | + |
| 36 | +tweet = self.query_one("Tweet") |
| 37 | +self.mount(Static("Consider switching to Mastodon"), after=tweet) |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +Textual needs much of the same kind of operations as the [JS API](https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild) exposed by the browser. But we are determined to make this way more intuitive. The new mount method is a step towards that. |
| 42 | + |
| 43 | +## Faster Updates |
| 44 | + |
| 45 | +Textual now writes to stdout in a thread. The upshot of this is that Textual can work on the next update before the terminal has displayed the previous frame. |
| 46 | + |
| 47 | +This means smoother updates all round! You may notice this when scrolling and animating, but even if you don't you will have more CPU cycles to play with. |
| 48 | + |
| 49 | +<div class="excalidraw"> |
| 50 | +--8<-- "docs/blog/images/faster-updates.excalidraw.svg" |
| 51 | +</div> |
| 52 | + |
| 53 | + |
| 54 | +## Multiple CSS Paths |
| 55 | + |
| 56 | +Up to version 0.3.0, Textual would only read a single CSS file set in the `CSS_PATH` class variable. You can now supply a list of paths if you have more than one CSS file. |
| 57 | + |
| 58 | +This change was prompted by [tuilwindcss](https://github.com/koaning/tuilwindcss/) which brings a TailwindCSS like approach to building Textual Widgets. Also checkout [calmcode.io](https://calmcode.io/) by the same author, which is an amazing resource. |
0 commit comments