├── requirements.txt
├── archive
├── image and texture
│ ├── SpriteMapExample.png
│ └── static_image_drawlist.py
├── logging and dpg standard dialogs
│ ├── builtin_dev_tools.py
│ ├── create_logger.py
│ └── custom_logger.py
├── drawing
│ ├── draw_items.py
│ ├── draw_viewport.py
│ └── draw_images.py
├── events inputs and item polling
│ ├── global_handlers.py
│ ├── global_handlers_global_registries.py
│ ├── widget_handlers.py
│ └── global_handlers_and_polling.py
├── menus
│ └── menu.py
└── themes
│ ├── theming_items.py
│ ├── theming_plots.py
│ └── theming_containers.py
├── .github
└── dependabot.yml
├── README.md
├── LICENSE
├── .gitignore
├── camera_capture_with_opencv.py
└── qr_writer_and_reader.py
/requirements.txt:
--------------------------------------------------------------------------------
1 | dearpygui==1.6.2
2 | opencv-python==4.5.4.58
3 | numpy==1.23.1
4 | pyzbar==0.1.9
5 | qrcode==7.3.1
6 | Pillow==9.2.0
--------------------------------------------------------------------------------
/archive/image and texture/SpriteMapExample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Pcothren/DearPyGui-Examples/HEAD/archive/image and texture/SpriteMapExample.png
--------------------------------------------------------------------------------
/archive/logging and dpg standard dialogs/builtin_dev_tools.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 | import dearpygui.logger as dpg_logger
3 |
4 | logger = dpg_logger.mvLogger()
5 |
6 | dpg.show_documentation()
7 | dpg.show_style_editor()
8 | dpg.show_debug()
9 | dpg.show_about()
10 | dpg.show_metrics()
11 | dpg.show_font_manager()
12 | dpg.show_item_registry()
13 |
14 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/archive/drawing/draw_items.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | with dpg.window(label="Tutorial"):
4 | with dpg.drawlist(width=300, height=300):
5 | dpg.draw_line((10, 10), (100, 100), color=(255, 0, 0, 255), thickness=1)
6 | dpg.draw_text((0, 0), "Origin", color=(250, 250, 250, 255), size=15)
7 | dpg.draw_arrow((50, 70), (100, 65), color=(0, 200, 255), thickness=1, size=10)
8 |
9 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/archive/events inputs and item polling/global_handlers.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | def change_text(sender, app_data, user_data):
4 | dpg.set_value(user_data, f"Mouse Button: {app_data[0]}, Down Time: {app_data[1]} seconds")
5 |
6 | with dpg.window(width=500, height=300):
7 | text_widget = dpg.add_text("Press any mouse button")
8 | with dpg.handler_registry():
9 | dpg.add_mouse_down_handler(callback=change_text, user_data=text_widget)
10 |
11 | dpg.start_dearpygui()
12 |
13 |
--------------------------------------------------------------------------------
/archive/events inputs and item polling/global_handlers_global_registries.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | dpg.setup_registries()
4 |
5 | def change_text(sender, app_data, user_data):
6 | dpg.set_value(user_data, f"Mouse Button: {app_data[0]}, Down Time: {app_data[1]} seconds")
7 |
8 | with dpg.window(width=500, height=300):
9 | text_widget = dpg.add_text("Press any mouse button")
10 | dpg.add_mouse_down_handler(callback=change_text, user_data=text_widget)
11 |
12 | dpg.start_dearpygui()
13 |
--------------------------------------------------------------------------------
/archive/events inputs and item polling/widget_handlers.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | def change_text(sender, app_data):
4 | handler = sender
5 | text_item = dpg.get_item_parent(handler)
6 | dpg.set_value(text_item, f"Mouse Button ID: {app_data}")
7 |
8 | with dpg.window(width=500, height=300):
9 | text_widget = dpg.add_text("Click me with any mouse button")
10 | dpg.add_clicked_handler(text_widget, callback=change_text, user_data=text_widget)
11 |
12 | dpg.start_dearpygui()
13 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "pip" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "daily"
12 |
--------------------------------------------------------------------------------
/archive/events inputs and item polling/global_handlers_and_polling.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | dpg.setup_registries()
4 |
5 | def change_text(sender, app_data, user_data):
6 | if (dpg.is_item_hovered(user_data)):
7 | dpg.set_value(user_data, f"Stop Hovering Me, Go away!!")
8 | else:
9 | dpg.set_value(user_data, f"Hover Me!")
10 | with dpg.window(width=500, height=300):
11 | text_widget = dpg.add_text("Hover Me!")
12 | dpg.add_mouse_move_handler(callback=change_text, user_data=text_widget)
13 |
14 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/archive/drawing/draw_viewport.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | # creating font and back viewport drawlists
4 | viewport_front = dpg.add_viewport_drawlist()
5 | viewport_back = dpg.add_viewport_drawlist(front=False)
6 |
7 | with dpg.window(label="Tutorial", width=300, height=300):
8 | dpg.add_text("Move the window over the drawings to see the effects.", wrap=300)
9 | dpg.draw_circle((100, 100), 25, color=(255, 255, 255, 255))
10 | dpg.draw_circle((100, 100), 25, color=(255, 255, 255, 255), parent=viewport_front)
11 | dpg.draw_circle((200, 200), 25, color=(255, 255, 255, 255), parent=viewport_back)
12 |
13 | dpg.start_dearpygui()
14 |
--------------------------------------------------------------------------------
/archive/drawing/draw_images.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | with dpg.texture_registry():
4 | # we are using static textures here, however dynamic and raw textures are allowed
5 | image_id = dpg.add_static_texture(100, 100, [], file='../image and texture/SpriteMapExample.png')
6 |
7 | with dpg.window(label="Tutorial"):
8 | with dpg.drawlist(width=700, height=700):
9 | dpg.draw_image(image_id, (0, 400), (200, 600), uv_min=(0, 0), uv_max=(1, 1))
10 | dpg.draw_image(image_id, (400, 300), (600, 500), uv_min=(0, 0), uv_max=(0.5, 0.5))
11 | dpg.draw_image(image_id, (0, 0), (300, 300), uv_min=(0, 0), uv_max=(2.5, 2.5))
12 |
13 | dpg.start_dearpygui()
14 |
--------------------------------------------------------------------------------
/archive/menus/menu.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | def print_me(sender):
4 | print(f"Menu Item: {sender}")
5 |
6 | with dpg.window(label="Tutorial"):
7 |
8 | with dpg.menu_bar():
9 |
10 | with dpg.menu(label="File"):
11 |
12 | dpg.add_menu_item(label="Save", callback=print_me)
13 | dpg.add_menu_item(label="Save As", callback=print_me)
14 |
15 | with dpg.menu(label="Settings"):
16 |
17 | dpg.add_menu_item(label="Setting 1", callback=print_me)
18 | dpg.add_menu_item(label="Setting 2", callback=print_me)
19 |
20 | dpg.add_menu_item(label="Help", callback=print_me)
21 |
22 | with dpg.menu(label="Widget Items"):
23 |
24 | dpg.add_checkbox(label="Pick Me", callback=print_me)
25 | dpg.add_button(label="Press Me", callback=print_me)
26 | dpg.add_color_picker(label="Color Me", callback=print_me)
27 |
28 | dpg.start_dearpygui()
29 |
--------------------------------------------------------------------------------
/archive/logging and dpg standard dialogs/create_logger.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | def print_me(sender):
4 | print(f"Menu Item: {sender}")
5 |
6 | with dpg.window(label="Tutorial"):
7 |
8 | with dpg.menu_bar():
9 |
10 | with dpg.menu(label="File"):
11 |
12 | dpg.add_menu_item(label="Save", callback=print_me)
13 | dpg.add_menu_item(label="Save As", callback=print_me)
14 |
15 | with dpg.menu(label="Settings"):
16 |
17 | dpg.add_menu_item(label="Setting 1", callback=print_me)
18 | dpg.add_menu_item(label="Setting 2", callback=print_me)
19 |
20 | dpg.add_menu_item(label="Help", callback=print_me)
21 |
22 | with dpg.menu(label="Widget Items"):
23 |
24 | dpg.add_checkbox(label="Pick Me", callback=print_me)
25 | dpg.add_button(label="Press Me", callback=print_me)
26 | dpg.add_color_picker(label="Color Me", callback=print_me)
27 |
28 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | (This repo is available under a free and permissive license)
11 |
12 | ## Overview
13 | Docs are where basic dpg examples are at [Read the Docs](https://dearpygui.readthedocs.io/en/latest/index.html)
14 |
15 | This is a repository for the example videos on [YouTube](https://www.youtube.com/channel/UCTMnJIjIB-h1hO6AvqG4KQw/featured)
16 |
17 | Archives is old 0.8 examples that will be upgraded in the future
18 |
19 | ---
20 |
21 | ## Build
22 | To install required dependencies run `pip install -r requirements.txt` or `pip3 install -r requirements.txt`
23 | from the cloned repo directory on your computer.
24 |
25 | ---
26 |
27 | ## Support
28 | If you are having issues or want to help, here are some places you can go:
29 | - [Discord Forum](https://discord.gg/tyE7Gu4)
30 | - [Reddit](https://www.reddit.com/r/DearPyGui/)
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Preston Cothren and Jonathan Hoffstadt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/archive/themes/theming_items.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | # Themes can consist of a colors and styles
4 |
5 | # You can use the style editor to test themes at runtime and find the right constants for colors and styles
6 | dpg.show_style_editor()
7 |
8 | # Create a theme container and color and styles
9 | with dpg.theme() as our_theme:
10 |
11 | dpg.add_theme_color(dpg.mvThemeCol_Button, (0, 255, 0, 255))
12 | dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (0, 255, 255, 255))
13 | dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
14 |
15 | # Some styles use only one variable "x" and some use 2 "x,"y" looking at the style editor can help
16 | dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 20)
17 | dpg.add_theme_style(dpg.mvStyleVar_FramePadding, 10, 10)
18 |
19 | with dpg.window(label="Tutorial", width=500, height=500):
20 | dpg.add_button(label="Default Theme")
21 |
22 | # Setting theme at start up
23 | our_button = dpg.add_button(label="Set At Start-up")
24 | dpg.set_item_theme(our_button, our_theme)
25 |
26 | # Themes can be set at runtime using a lambda
27 | dpg.add_button(label="Set Theme at Runtime", callback=lambda sender: dpg.set_item_theme(sender, our_theme))
28 |
29 | # Themes can be set to all items of a specific type at runtime using a callback
30 | def set_theme():
31 | dpg.set_item_type_theme(dpg.mvButton, our_theme)
32 | dpg.add_button(label="Theme all items of a specified type", callback=set_theme)
33 | dpg.add_combo(label="Combo")
34 |
35 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | env/
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 |
27 | # PyInstaller
28 | # Usually these files are written by a python script from a template
29 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
30 | *.manifest
31 | *.spec
32 |
33 | # Installer logs
34 | pip-log.txt
35 | pip-delete-this-directory.txt
36 |
37 | # Unit test / coverage reports
38 | htmlcov/
39 | .tox/
40 | .coverage
41 | .coverage.*
42 | .cache
43 | nosetests.xml
44 | coverage.xml
45 | *,cover
46 | .hypothesis/
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | *.log
54 | local_settings.py
55 |
56 | # Flask stuff:
57 | instance/
58 | .webassets-cache
59 |
60 | # Scrapy stuff:
61 | .scrapy
62 |
63 | # Sphinx documentation
64 | docs/_build/
65 |
66 | # PyBuilder
67 | target/
68 |
69 | # IPython Notebook
70 | .ipynb_checkpoints
71 |
72 | # pyenv
73 | .python-version
74 |
75 | # celery beat schedule file
76 | celerybeat-schedule
77 |
78 | # dotenv
79 | .env
80 |
81 | # virtualenv
82 | .venv/
83 | venv/
84 | ENV/
85 |
86 | # Spyder project settings
87 | .spyderproject
88 |
89 | # Rope project settings
90 | .ropeproject
91 |
92 | # Not these files they are special
93 | !.gitignore
94 | !requirements.txt
95 |
96 | # Editor Configurations
97 | .vscode/
98 | .idea/
99 |
--------------------------------------------------------------------------------
/archive/themes/theming_plots.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 | from math import sin
3 |
4 | # creating data to use in the series
5 | sindatax = []
6 | sindatay = []
7 | for i in range(0, 100):
8 | sindatax.append(i/100)
9 | sindatay.append(0.5 + 0.5*sin(50*i/100))
10 |
11 | # You can use the style editor to test themes at runtime and find the right constants for colors and styles
12 | dpg.show_style_editor()
13 |
14 | # themes applied to plots REQUIRE category to be set to plots
15 | # because plots are containers plots will propagate themes
16 | with dpg.theme() as our_plot_theme:
17 | dpg.add_theme_color(dpg.mvPlotCol_PlotBg, (100, 0, 0, 50), category=dpg.mvThemeCat_Plots)
18 | dpg.add_theme_color(dpg.mvPlotCol_Line, (0, 255, 0, 255), category=dpg.mvThemeCat_Plots)
19 | dpg.add_theme_color(dpg.mvPlotCol_XAxis, (0, 255, 255, 255), category=dpg.mvThemeCat_Plots)
20 |
21 | with dpg.theme() as series_theme:
22 | dpg.add_theme_color(dpg.mvPlotCol_Line, (150, 0, 100, 255), category=dpg.mvThemeCat_Plots)
23 |
24 |
25 | with dpg.window(label="Tutorial"):
26 |
27 | # create plot
28 | with dpg.plot(label="Line Series", height=400, width=400) as plot:
29 |
30 | # REQUIRED: create x and y axes
31 | dpg.add_plot_axis(dpg.mvXAxis, label="x")
32 | axis_y = dpg.add_plot_axis(dpg.mvYAxis, label="y")
33 |
34 | # series belong to a y axis
35 | our_series = dpg.add_line_series((0, 1), (.5, .75), label="straight line", parent=axis_y)
36 |
37 | dpg.set_item_theme(plot, our_plot_theme)
38 | dpg.set_item_theme(our_series, series_theme)
39 |
40 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/archive/image and texture/static_image_drawlist.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | with dpg.texture_registry():
4 | image_id = dpg.add_static_texture(100, 100, [], file='SpriteMapExample.png')
5 |
6 | def update_image(sender, app_data, user_data):
7 | image, controls = user_data
8 | kwargs = {}
9 | for k, v in controls.items():
10 | kwargs[k] = dpg.get_value(v)
11 | dpg.configure_item(image, **kwargs)
12 |
13 | with dpg.window(label="Main"):
14 | dpg.add_text("This is an example of a image being added to a drawlist and updated", bullet=True)
15 | dpg.add_spacing(count=5)
16 | dpg.add_separator()
17 | dpg.add_spacing()
18 | with dpg.group() as control_group:
19 | pmin = dpg.add_slider_intx(label="pmin", default_value=[0, 125], max_value=500, size=2)
20 | pmax = dpg.add_slider_intx(label="pmax", default_value=[416, 509], max_value=500, size=2)
21 | uv_min = dpg.add_slider_floatx(label="uv_min", default_value=[0, 0], max_value=3, min_value=-3, size=2)
22 | uv_max = dpg.add_slider_floatx(label="uv_max", default_value=[1, 1], max_value=3, min_value=-3, size=2)
23 | control_items = {"pmin": pmin, "pmax": pmax, "uv_min": uv_min, "uv_max": uv_max}
24 |
25 | drawing = dpg.add_drawlist(width=416, height=384)
26 | image = dpg.draw_image(image_id, dpg.get_value(pmin), dpg.get_value(pmax), uv_min=dpg.get_value(uv_min), uv_max=dpg.get_value(uv_max))
27 |
28 | controls = dpg.get_item_children(control_group)[1]
29 | for item in controls:
30 | dpg.set_item_callback(item, update_image)
31 | dpg.set_item_user_data(item, (image, control_items))
32 |
33 | dpg.start_dearpygui()
34 |
--------------------------------------------------------------------------------
/camera_capture_with_opencv.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 | import cv2 as cv
3 | import numpy as np
4 |
5 | dpg.create_context()
6 | dpg.create_viewport(title='Custom Title', width=600, height=800)
7 | dpg.setup_dearpygui()
8 |
9 | vid = cv.VideoCapture(0)
10 | ret, frame = vid.read()
11 |
12 | # image size or you can get this from image shape
13 | frame_width = vid.get(cv.CAP_PROP_FRAME_WIDTH)
14 | frame_height = vid.get(cv.CAP_PROP_FRAME_HEIGHT)
15 | video_fps = vid.get(cv.CAP_PROP_FPS)
16 | print(frame_width)
17 | print(frame_height)
18 | print(video_fps)
19 |
20 | print("Frame Array:")
21 | print("Array is of type: ", type(frame))
22 | print("No. of dimensions: ", frame.ndim)
23 | print("Shape of array: ", frame.shape)
24 | print("Size of array: ", frame.size)
25 | print("Array stores elements of type: ", frame.dtype)
26 | data = np.flip(frame, 2) # because the camera data comes in as BGR and we need RGB
27 | data = data.ravel() # flatten camera data to a 1 d stricture
28 | data = np.asfarray(data, dtype='f') # change data type to 32bit floats
29 | texture_data = np.true_divide(data, 255.0) # normalize image data to prepare for GPU
30 |
31 | print("texture_data Array:")
32 | print("Array is of type: ", type(texture_data))
33 | print("No. of dimensions: ", texture_data.ndim)
34 | print("Shape of array: ", texture_data.shape)
35 | print("Size of array: ", texture_data.size)
36 | print("Array stores elements of type: ", texture_data.dtype)
37 |
38 | with dpg.texture_registry(show=True):
39 | dpg.add_raw_texture(frame.shape[1], frame.shape[0], texture_data, tag="texture_tag", format=dpg.mvFormat_Float_rgb)
40 |
41 | with dpg.window(label="Example Window"):
42 | dpg.add_text("Hello, world")
43 | dpg.add_image("texture_tag")
44 |
45 | dpg.show_metrics()
46 | dpg.show_viewport()
47 | while dpg.is_dearpygui_running():
48 |
49 | # updating the texture in a while loop the frame rate will be limited to the camera frame rate.
50 | # commenting out the "ret, frame = vid.read()" line will show the full speed that operations and updating a texture can run at
51 |
52 | ret, frame = vid.read()
53 | data = np.flip(frame, 2)
54 | data = data.ravel()
55 | data = np.asfarray(data, dtype='f')
56 | texture_data = np.true_divide(data, 255.0)
57 | dpg.set_value("texture_tag", texture_data)
58 |
59 | # to compare to the base example in the open cv tutorials uncomment below
60 | #cv.imshow('frame', frame)
61 | dpg.render_dearpygui_frame()
62 |
63 | vid.release()
64 | #cv.destroyAllWindows() # when using upen cv window "imshow" call this also
65 | dpg.destroy_context()
--------------------------------------------------------------------------------
/archive/themes/theming_containers.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | # You can use the style editor to test themes at runtime and find the right constants for colors and styles
4 | dpg.show_style_editor()
5 |
6 | # Create a theme container and color and styles
7 | with dpg.theme() as our_theme:
8 |
9 | dpg.add_theme_color(dpg.mvThemeCol_Button, (0, 255, 0, 255))
10 | dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (0, 255, 255, 255))
11 | dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
12 |
13 | dpg.add_theme_color(dpg.mvThemeCol_TitleBg, (100, 150, 0, 255))
14 | dpg.add_theme_color(dpg.mvThemeCol_ScrollbarGrab, (0, 255, 0, 255))
15 |
16 | # Some styles use only one variable "x" and some use 2 "x,"y" looking at the style editor can help
17 | dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 20)
18 | dpg.add_theme_style(dpg.mvStyleVar_FramePadding, 10, 10)
19 |
20 | # Themes applied to containers and will propagate to any children that use that theme constant
21 | with dpg.window(label="Theme applied to child that propagates", width=300, height=300):
22 | dpg.add_button(label="Default Theme Because above theme")
23 | with dpg.child() as top_container:
24 | dpg.add_button(label="Button")
25 | dpg.add_combo(label="recursive theme Radio Button")
26 | with dpg.child():
27 | dpg.add_button(label="recursive theme Button")
28 | dpg.add_combo(label="recursive theme Radio Button")
29 | with dpg.group():
30 | dpg.add_button(label="Button")
31 | dpg.add_combo(label=" Radio Button")
32 | dpg.set_item_theme(top_container, our_theme)
33 |
34 | # Themes applied to all container types will apply and propigate to all container types across windows
35 | with dpg.window(label="Theme applied to all group containers", width=300, height=150):
36 | dpg.add_button(label="Default Theme Because above theme")
37 | with dpg.group():
38 | dpg.add_button(label="Button")
39 | dpg.add_combo(label="Radio Button")
40 | with dpg.group():
41 | dpg.add_button(label="Button")
42 | dpg.add_combo(label=" Radio Button")
43 | with dpg.group():
44 | dpg.add_button(label="recursive theme Button")
45 | dpg.add_combo(label="recursive theme Radio Button")
46 | dpg.set_item_type_theme(dpg.mvGroup, our_theme)
47 |
48 | # themes can be applied to whole windows
49 | with dpg.window(label="Themed Window") as themed_window:
50 | dpg.add_button(label="Default Theme Because above theme")
51 | with dpg.child() as top_container:
52 | dpg.add_button(label="Button")
53 | dpg.add_combo(label="recursive theme Radio Button")
54 | with dpg.child():
55 | dpg.add_button(label="recursive theme Button")
56 | dpg.add_combo(label="recursive theme Radio Button")
57 | dpg.set_item_theme(themed_window, our_theme)
58 |
59 | dpg.start_dearpygui()
--------------------------------------------------------------------------------
/qr_writer_and_reader.py:
--------------------------------------------------------------------------------
1 | #### WRITING QR ###########################################
2 | # creating a qr code image with qrcode library more info can
3 | # more info on the qrcode library
4 | # can be found here https://github.com/lincolnloop/python-qrcode
5 | import qrcode
6 | qr = qrcode.QRCode(
7 | version=1,
8 | error_correction=qrcode.constants.ERROR_CORRECT_M,
9 | box_size=5,
10 | border=4,
11 | )
12 | qr.add_data('https://github.com/hoffstadt/DearPyGui')
13 | qr.make(fit=True)
14 |
15 | img = qr.make_image(fill_color="black", back_color="white")
16 | img.save("dpg-qr.png")
17 |
18 |
19 | #### READING QR #######################################
20 | # more info on the pyzbar library can be
21 | # found here https://github.com/NaturalHistoryMuseum/pyzbar
22 | # we will read directly into dpg however you could utilize open cv
23 | # from the last example and grab the image from every camera
24 | # capture and use pyzbar to decode it
25 |
26 | # reading the qr code .png into dpg and showing it
27 | import dearpygui.dearpygui as dpg
28 | from pyzbar.pyzbar import decode
29 | import numpy
30 | import webbrowser
31 | dpg.create_context()
32 |
33 | def process_qr_image():
34 | width, height, channels, data = dpg.load_image("dpg-qr.png")
35 |
36 | # after loading with dpg we will read
37 | # into a numpy array to do some data minuplation
38 | # pyzbar wants data in a a 255 shaped format of 8 bits
39 | # but will also accept a numpy array and do the
40 | # conversion from 32 to 8 bit for us
41 | nparray = numpy.frombuffer(data, 'f')
42 | nparrayscalar = numpy.multiply(nparray, 255.0)
43 | npreshaped = numpy.reshape(nparrayscalar,(width, height, channels))
44 |
45 | # various helpful stuff to know about the array
46 | print("Array is of type: ", type(npreshaped))
47 | print("No. of dimensions: ", npreshaped.ndim)
48 | print("Shape of array: ", npreshaped.shape)
49 | print("Size of array: ", npreshaped.size)
50 | print("Array stores elements of type: ", npreshaped.dtype)
51 |
52 | # reading the image for QR
53 | qr_class = decode(npreshaped)[0]
54 |
55 | # various helpful stuff to know about the qr code class
56 | print(type(qr_class))
57 | print(qr_class)
58 |
59 | # reading for data
60 | qr_data = qr_class.data.decode()
61 |
62 | # because the data in teh qr code is a link we will open it
63 | webbrowser.open(qr_data)
64 |
65 | # we can also pull the rect or poly infor from the
66 | # qr code class and draw squares,
67 | # referenceing the open cv example also you could draw
68 | # live rectangles overtop of the images using dpg every frame
69 |
70 | width, height, channels, data = dpg.load_image("dpg-qr.png")
71 | with dpg.texture_registry():
72 | dpg.add_static_texture(width=width, height=height, default_value=data, tag="texture_tag")
73 |
74 | with dpg.window(label="Tutorial", tag="MainWin", width=800, height=600):
75 | dpg.add_image("texture_tag")
76 | dpg.add_button(label="Process QR code", callback=process_qr_image)
77 | dpg.add_text("", tag="QR Data")
78 |
79 |
80 |
81 | dpg.create_viewport(title='Custom Title', width=800, height=600)
82 | dpg.setup_dearpygui()
83 | dpg.show_viewport()
84 | dpg.start_dearpygui()
85 | dpg.destroy_context()
86 |
--------------------------------------------------------------------------------
/archive/logging and dpg standard dialogs/custom_logger.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 |
3 | # Because the built in logger was made completely from dpg commands you can reimplement it and customize it yourself!
4 | class MyCustomLogger:
5 |
6 | def __init__(self):
7 |
8 | self.log_level = 0
9 | self._auto_scroll = True
10 | self.filter_id = None
11 | self.window_id = dpg.add_window(label="mvLogger", pos=(200, 200), width=500, height=500)
12 | self.count = 0
13 | self.flush_count = 1000
14 | self.level_options = {"Trace": 0, "Debug": 1, "Info": 2, "Warning": 3, "Error": 4, "Critical": 5}
15 |
16 | with dpg.group(horizontal=True, parent=self.window_id):
17 | dpg.add_checkbox(label="Auto-scroll", default_value=True,
18 | callback=lambda sender: self.auto_scroll(dpg.get_value(sender)))
19 | dpg.add_button(label="Clear", callback=lambda: dpg.delete_item(self.filter_id, children_only=True))
20 | dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value(self.filter_id, dpg.get_value(sender)),
21 | parent=self.window_id)
22 | dpg.add_radio_button(list(self.level_options.keys()), parent=self.window_id,
23 | callback=lambda sender: self.set_level(self.level_options[dpg.get_value(sender)]))
24 | dpg.add_same_line(parent=self.window_id)
25 | self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True)
26 | self.filter_id = dpg.add_filter_set(parent=self.child_id)
27 |
28 | with dpg.theme() as self.trace_theme:
29 | dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0, 255))
30 |
31 | with dpg.theme() as self.debug_theme:
32 | dpg.add_theme_color(dpg.mvThemeCol_Text, (64, 128, 255, 255))
33 |
34 | with dpg.theme() as self.info_theme:
35 | dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 255, 255))
36 |
37 | with dpg.theme() as self.warning_theme:
38 | dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 0, 255))
39 |
40 | with dpg.theme() as self.error_theme:
41 | dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
42 |
43 | with dpg.theme() as self.critical_theme:
44 | dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
45 |
46 | def auto_scroll(self, value):
47 | self._auto_scroll = value
48 |
49 | def _log(self, message, level):
50 |
51 | if level < self.log_level:
52 | return
53 |
54 | self.count += 1
55 |
56 | if self.count > self.flush_count:
57 | self.clear_log()
58 |
59 | theme = self.info_theme
60 |
61 | if level == 0:
62 | message = "[TRACE]\t\t" + message
63 | theme = self.trace_theme
64 | elif level == 1:
65 | message = "[DEBUG]\t\t" + message
66 | theme = self.debug_theme
67 | elif level == 2:
68 | message = "[INFO]\t\t" + message
69 | elif level == 3:
70 | message = "[WARNING]\t\t" + message
71 | theme = self.warning_theme
72 | elif level == 4:
73 | message = "[ERROR]\t\t" + message
74 | theme = self.error_theme
75 | elif level == 5:
76 | message = "[CRITICAL]\t\t" + message
77 | theme = self.critical_theme
78 |
79 | new_log = dpg.add_text(message, parent=self.filter_id, filter_key=message)
80 | dpg.set_item_theme(new_log, theme)
81 | if self._auto_scroll:
82 | scroll_max = dpg.get_y_scroll_max(self.child_id)
83 | dpg.set_y_scroll(self.child_id, -1.0)
84 |
85 | def log(self, message):
86 | self._log(message, 0)
87 |
88 | def log_debug(self, message):
89 | self._log(message, 1)
90 |
91 | def log_info(self, message):
92 | self._log(message, 2)
93 |
94 | def log_warning(self, message):
95 | self._log(message, 3)
96 |
97 | def log_error(self, message):
98 | self._log(message, 4)
99 |
100 | def log_critical(self, message):
101 | self._log(message, 5)
102 |
103 | def clear_log(self):
104 | dpg.delete_item(self.filter_id, children_only=True)
105 | self.count = 0
106 |
107 | def set_level(self, level):
108 | self.log_level = level
109 |
110 | def log_things(sender, app_data, user_data):
111 | user_data.log("We can log to a trace level.")
112 | user_data.log_debug("We can log to a debug level.")
113 | user_data.log_info("We can log to an info level.")
114 | user_data.log_warning("We can log to a warning level.")
115 | user_data.log_error("We can log to a error level.")
116 | user_data.log_critical("We can log to a critical level.")
117 |
118 | with dpg.window():
119 | logger = MyCustomLogger()
120 | logger.log("This is my logger. Just like an onion it has many levels.")
121 | dpg.add_button(label="Log to logger", callback=log_things, user_data=logger)
122 |
123 | dpg.start_dearpygui()
--------------------------------------------------------------------------------