DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

DearPyGui's "scope" is limited to a single font registry

Open Atlamillias opened this issue 2 years ago • 0 comments

Python: 3.12 DearPyGui: v1.10.1 OS: Windows 10/11

DPG is seemingly oblivious to any font that is not parented by the oldest existing font registry. It's very well aware of the font _item_s, but I do not believe the actual font is loaded. You can check this by comparing items in the item registry vs fonts loaded in the font manager when running the below script (you'll need to update font_fpath accordingly first).

from dearpygui import dearpygui


dearpygui.create_context()
dearpygui.setup_dearpygui()
dearpygui.create_viewport()
dearpygui.show_viewport()


font_fpath = r'Inter-Regular.ttf'   # | update with local font file!
font_name  = 'Inter-Regular'        # |


with dearpygui.window(): ... # needed to populate the item registry

with dearpygui.font_registry(label="Oldest") as fr_oldest:
    for i in range(10, 20, 2):
        dearpygui.add_font(font_fpath, i, label=f'{font_name} [{i:.1f}]')

with dearpygui.font_registry(label="Newest") as fr_newest:
    for i in range(20, 30, 2):
        dearpygui.add_font(font_fpath, i, label=f'{font_name} [{i:.1f}]')

# will still reflect the built-in ProggyClean 13px font
dearpygui.bind_font(dearpygui.last_item())


dearpygui.show_font_manager()
dearpygui.show_item_registry()
dearpygui.start_dearpygui()

image image

If fr_oldest is destroyed after its' creation but before starting the interface, the font manager will be populated with fr_newests fonts. In the above example, the application will also reflect the bound font. It will not, however, if fr_oldest is destroyed while running the interface (e.g. as a callback);

from dearpygui import dearpygui


dearpygui.create_context()
dearpygui.setup_dearpygui()
dearpygui.create_viewport()
dearpygui.show_viewport()


font_fpath = r'Inter-Regular.ttf'   # | update with local font file!
font_name  = 'Inter-Regular'        # |


with dearpygui.window():
    dearpygui.add_button(
        label="Destroy Oldest Font Registry",
        callback=lambda: dearpygui.delete_item(fr_oldest),
    )

with dearpygui.font_registry(label="Oldest") as fr_oldest:
    for i in range(10, 20, 2):
        dearpygui.add_font(font_fpath, i, label=f'{font_name} [{i:.1f}]')


with dearpygui.font_registry(label="Newest") as fr_newest:
    for i in range(20, 30, 2):
        dearpygui.add_font(font_fpath, i, label=f'{font_name} [{i:.1f}]')

dearpygui.bind_font(dearpygui.last_item())

dearpygui.show_font_manager()
dearpygui.show_item_registry()
dearpygui.start_dearpygui()

Atlamillias avatar Nov 02 '23 19:11 Atlamillias