Skip to content

Commit

Permalink
Update example.py
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanNazaruk committed Dec 19, 2022
1 parent 9862bce commit 5866e1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions DearPyGui_ImageController/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from .controller import get_texture_plug, image_to_dpg_texture, set_texture_registry


def add_image(href: str | Image.Image, width: int = None, height: int = None, parent=0) -> ImageViewer:
image_viewer = ImageViewer(href, width, height)
def add_image(href: str | Image.Image,
width: int = None,
height: int = None,
parent=0,
controller: ImageController = None) -> ImageViewer:
image_viewer = ImageViewer(href, width, height, controller=controller)
image_viewer.render(parent=parent)
return image_viewer
2 changes: 1 addition & 1 deletion DearPyGui_ImageController/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ImageController(Dict[ControllerImageTag, ImageInfo]):
max_inactive_time: int | float
unloading_check_sleep_time: int | float

def __init__(self, max_inactive_time: int = 10, unloading_check_sleep_time: int | float = 1, number_image_loader_workers: int = 2, queue_max_size: int = None):
def __init__(self, max_inactive_time: int = 4, unloading_check_sleep_time: int | float = 1, number_image_loader_workers: int = 2, queue_max_size: int = None):
"""
:param max_inactive_time: Time in seconds after which the picture will be unloaded from the DPG/RAM, If last time visible is not updated
:param unloading_check_sleep_time: In this number of seconds the last visibility of the image will be checked
Expand Down
8 changes: 6 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

import DearPyGui_ImageController as dpg_img

path_to_images = "test_images"

dpg.create_context()
dpg_img.set_texture_registry(dpg.add_texture_registry(show=True))
dpg_img.default_image_controller.max_inactive_time = 3
dpg_img.default_image_controller.unloading_check_sleep_time = 1

all_image_viewers: list[dpg_img.ImageViewer] = []


def add_all_pictures():
for i, file in enumerate(glob.glob("Test_images/*.*")):
for i, file in enumerate(glob.glob(f"{path_to_images}/*.*")):
if not i % 8:
group = dpg.add_group(horizontal=True, parent='picture_group')
image_viewer = dpg_img.add_image(file, height=100, parent=group) # noqa
Expand Down Expand Up @@ -41,7 +45,7 @@ def set_size():

dpg.show_metrics()

dpg.create_viewport(title='Custom Title', width=1200, height=600)
dpg.create_viewport(title='DearPyGui-ImageController', width=1200, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
Expand Down

0 comments on commit 5866e1d

Please sign in to comment.