Skip to content

zparmley/DPGMagicTag

Repository files navigation

DpgMagicTag

A composable tag system useable with DearPyGUI

Installation

pip install dpgmagictag

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

About

Magic Tags for use with DearPyGui

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages