A selection of widgets for Textual
Project description
Zandev Textual Widgets
This is a collection of widgets for Textual with a focus on aiding writing apps which look and function more like desktop apps.
Installation
Install with
pip install zandev_textual_widgets
or just copy the code to your project.
Dependencies are just textual, and pywin32 if you are running on Windows.
Example
See testapp.py as a simple example.
Widgets
Cascading drop down menus
This is a system of drop down menus intended to replace the Textual Header Widget with typical desktop app menus.
Alternatively (or in addition), these can be triggered in a pop-up mode for example for context menus.
As is common on destop menus, navigation is by one of individual click, click and release or keyboard, but only one navigation mode will be active at once.
Usage
Create a screen from MenuScreen and add it to your App, e.g:
SCREENS = {
"menu": MenuScreen(),
}
The MenuScreen should exist for the lifetime of your app, and contains menus for all of your screens which are dynamically displayed as needed.
For each menu, create a Menu containing MenuItem children, e.g.:
app_menu = Menu(
MenuItem(name="About", menu_action="screen.about"),
MenuItem(name="Quit", menu_action="screen.quit"),
id="app_menu",
)
menu_screen.mount(app_menu)
The menu_action is the Textual action to trigger. Alternatively you can provide a callback which will be called with the menu item name and action, e.g.:
MenuItem(
name="callback_test", menu_action="callback_test", callback=my_callback
),
To add a spacer to the menu, add a disabled MenuItem.
To add a menu bar to a screen, add a MenuBar to your screen containing MenuHeader children insead of the standard Textual Header, with menu_id being the id of the menu to open, e.g. in the compose method:
yield MenuBar(
MenuHeader(name="TestApp", menu_id="app_menu"),
MenuHeader(name="File", menu_id="file_menu"),
)
To add a sub-menu, in a MenuItem, give a menu_action with a name which is "menu." followed by the id of the sub-menu, e.g:
sub_item = MenuItem(name="More...", menu_action="menu.more_menu")
To trigger the keyboard navigation mode of the menu bar, call the activate method of MenuBar, e.g.:
self.menu_bar.activate()
To trigger a single menu as a pop-up, call the context_menu method of the MenuScreen, with the id of the target menu, the Offset of the position to place the menu and whether it is in keyboard navigation mode, e.g.:
await self.app.get_screen("menu").context_menu(
"test_menu", Offset(widget.region.x, widget.region.y), key=True
)
File selector
This provides a modal file selector similar in style to the Windows one.
Features include:
- Filtering by type.
- Selection of parent directories by clicking on path elements.
- Directory navigation by tree.
- Resizable file area (by dragging).
- Resizable and sortable columns in the file area.
Usage
Create a FileSelector screen and trigger is as a standard Textual modal dialog, e.g.:
self.app.push_screen(FileSelector(directory=os.getcwd()), callback=file_result)
The return is the absolute path of the selection.
The parameters to the FileSelector constructor are:
mode: one of the FileSelectorMode enum values: EXISTING to allow selection of an existing file (e.g. for an open), NEW to allow naming of a new file (e.g. for a save as), and DIRECTORY to allow navigation to a directory but not selection of a file.filename: the initial name of a file.directory: the initial directory to start in.filter: the initial filter glob (defaults to*).ok_text: what to name the confirmation button, e.g. Open or Save.show_all: by default, only files or directories are shown in the file area dependent on mode. Set this to True to show both.
Simple dialog
This is a simple modal dialog for quick confirmation or informational dialogs.
Usage
Create a Dialog with an id, a label and a list of tuples of (button id, button name, variant) of buttons, e.g.:
quit_dialog = Dialog(
id="quit_dialog",
label="Quit application?",
buttons=[("Quit", "quit", "error"), ("Cancel", "cancel", "primary")],
)
Then trigger this as a standard Textual modal dialog, e.g.:
self.app.push_screen(quit_dialog, check_quit)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zandev_textual_widgets-1.0.0.tar.gz.
File metadata
- Download URL: zandev_textual_widgets-1.0.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08aca9ebbd9d3b4d98178bb7c01fde7dbed51637abd5f07ac0db1a70b593e236
|
|
| MD5 |
60c9ed5d0839bd2743f1dec52361f65a
|
|
| BLAKE2b-256 |
00dbe2f2b5b51fc3a32521d5ef09e9486282e6779d9076ad4cd9956d0f5060d0
|
File details
Details for the file zandev_textual_widgets-1.0.0-py3-none-any.whl.
File metadata
- Download URL: zandev_textual_widgets-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8a4ae44bd4bef4f77314c0bd5057d999b5916dd49bed8fd3d73e2f5dd154db1
|
|
| MD5 |
ba765ab7c6e9c0763304bd7847d64770
|
|
| BLAKE2b-256 |
3a06341db5e5b349b2d82319da571ce524bf20c4daf7bf77c7b79597d961f3bc
|