A composable tag system for use with DearPyGUI
Project description
DpgMagicTag
A composable tag system useable with DearPyGUI
Motivation
DearPyGUI allows memorable tags for items but they are required to be strings. Often, especially when creating reusable components which might appear more than once in an application, I found myself using some variation of the following pattern:
base_tag = some_unique_string_generator()
with dpg.window(tag = base_tag + 'window'):
with dpg.button(tag = base_tag + 'left_button'):
...
And then later in code having to remember or use a reference to the tag exactly as I composed it. With dpgmagictag I can compose tags like paths:
base_tag = MagicTag.random_factory()
with dpg.window(tag = base_tag / 'window'):
with dpg.button(tag = base_tag / 'button'):
...
Later, to find all buttons, for instance, I can query with i.e.
button_tags = MagicTag().query('*/button')
# or, because querying is relative by default
button_tag = base_tag.query('button')[0]
Querying matches with glob-style patterns, so it feels natural once you get used to composing tags as paths.
All paths, by default, share a context. Therefore all tags are query-able with MagicTag().query(
Magic
Why are MagicTags magic? Because dearpygui treats them as strings, and they works as strings. Note, though, that there is a root (from the shared context) prepended to the string value of each tag. To see the actual string value as dearpygui would, use str():
from dpgmagictag.magictag import MagicTag
str(MagicTag('a')) ## DEFAULT_ROOT/a
n.b.
Note that composing tags like so:
tag = MagicTag() / 'window' / 'header' / 'button1'
Creates intermittent tags for /window and /window/header
Project details
Release history Release notifications | RSS feed
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 dpgmagictag-0.1.1.tar.gz.
File metadata
- Download URL: dpgmagictag-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e6e1d47bba1d6e295b363e2d324f5b5a8288a99bba77b884b122318c3135906
|
|
| MD5 |
e6dea450b2110247e232f10d5533b4f4
|
|
| BLAKE2b-256 |
f0623f058dec3c73c7add28ac23dd92c1d89a79c9069f5143c4bce78e5625ea7
|
File details
Details for the file dpgmagictag-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dpgmagictag-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89787cb27fc370329883f6c0b4fb5fdafa9c9e5426fd4c12bc556450de41389f
|
|
| MD5 |
a81a91bf97951de687d204d97e580ae9
|
|
| BLAKE2b-256 |
ce791e87cd35d38f905f4ec43c1afba9a59d4f6dfffb48baf78bbe7b5b82fb67
|