Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dpgmagictag-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dpgmagictag-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

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

Hashes for dpgmagictag-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2e6e1d47bba1d6e295b363e2d324f5b5a8288a99bba77b884b122318c3135906
MD5 e6dea450b2110247e232f10d5533b4f4
BLAKE2b-256 f0623f058dec3c73c7add28ac23dd92c1d89a79c9069f5143c4bce78e5625ea7

See more details on using hashes here.

File details

Details for the file dpgmagictag-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dpgmagictag-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89787cb27fc370329883f6c0b4fb5fdafa9c9e5426fd4c12bc556450de41389f
MD5 a81a91bf97951de687d204d97e580ae9
BLAKE2b-256 ce791e87cd35d38f905f4ec43c1afba9a59d4f6dfffb48baf78bbe7b5b82fb67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page