Skip to content

Instantly share code, notes, and snippets.

@ProfFan
Last active August 2, 2021 19:08
Show Gist options
  • Save ProfFan/aaad863eaf820743a8a9f2dd286ddf47 to your computer and use it in GitHub Desktop.
Save ProfFan/aaad863eaf820743a8a9f2dd286ddf47 to your computer and use it in GitHub Desktop.
import dearpygui.dearpygui as dpg
dpg.enable_docking(dock_space=True)
import numpy as np
width = 800
height = 800
grid_arr = np.ones((width, height, 4), dtype=np.float32)
rng = np.random.default_rng()
with dpg.texture_registry():
image_id = dpg.add_raw_texture(width,
height,
grid_arr,
format=dpg.mvFormat_Float_rgba)
def clicked_callback(sender, app_data, user_data):
print(f"[{sender}]: {app_data}, {user_data}")
with dpg.window(label="Tutorial"):
# with dpg.drawlist(width=width, height=height):
img_widget = dpg.add_image(image_id) # , (0, 0), (width, height))
with dpg.handler_registry():
dpg.add_clicked_handler(img_widget, label="clicked", user_data = "click", callback=clicked_callback)
dpg.add_mouse_down_handler(img_widget, label="down", user_data = "down", callback=clicked_callback)
# dpg.add_hover_handler(img_widget, user_data="hover", callback=clicked_callback)
dpg.add_mouse_release_handler(img_widget, user_data="release", callback=clicked_callback)
# dpg.add_mouse_move_handler(img_widget, user_data="move", callback=clicked_callback)
if __name__ == "__main__":
dpg.setup_viewport()
while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
dpg.cleanup_dearpygui()
from OpenGL import platform as gl_platform
import dearpygui.dearpygui as dpg
from dearpygui.demo import show_demo
dpg.enable_docking(dock_space=True)
with dpg.font_registry():
# add font (set as default for entire app)
dpg.add_font(
"/usr/share/fonts/adobe-source-han-sans/SourceHanSansCN-Regular.otf",
40,
default_font=True)
import numpy as np
import threading
width = 800
height = 800
grid_arr = np.ones((width, height, 4), dtype=np.float32)
rng = np.random.default_rng()
with dpg.texture_registry():
image_id = dpg.add_raw_texture(width,
height,
grid_arr,
format=dpg.mvFormat_Float_rgba)
image_id_1 = dpg.add_raw_texture(width,
height,
grid_arr,
format=dpg.mvFormat_Float_rgba)
def clicked_callback(sender, app_data, user_data):
print(f"[{sender}]: {app_data}, {user_data}")
with dpg.window(label="Tutorial"):
# with dpg.drawlist(width=width, height=height):
img_widget = dpg.add_image(image_id) # , (0, 0), (width, height))
with dpg.handler_registry():
dpg.add_clicked_handler(img_widget, label="3D clicked", user_data = "click", callback=clicked_callback)
dpg.add_mouse_down_handler(img_widget, label="3D dragged", user_data = "down", callback=clicked_callback)
# dpg.add_hover_handler(img_widget, user_data="hover", callback=clicked_callback)
dpg.add_mouse_release_handler(img_widget, user_data="release", callback=clicked_callback)
# dpg.add_mouse_move_handler(img_widget, user_data="move", callback=clicked_callback)
should_continue = True
def setter():
import time
while should_continue:
rng.standard_normal(out=grid_arr, dtype=np.float32)
# dpg.set_value(image_id, grid_arr)
time.sleep(0.01)
t = threading.Thread(target=setter)
t.start()
def exit_handler():
global should_continue
print("EXIT!")
should_continue = False
dpg.set_exit_callback(exit_handler)
if __name__ == "__main__":
dpg.setup_viewport()
dpg_context = gl_platform.GetCurrentContext()
print(f"DPG context: {dpg_context}")
show_demo()
glp = None
while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
dpg.cleanup_dearpygui()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment