Release 1.1.2
This commit is contained in:
62
examples/reconnect_grid.py
Normal file
62
examples/reconnect_grid.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# pyright: reportGeneralTypeIssues=false
|
||||
|
||||
import dearpygui.dearpygui as dpg
|
||||
|
||||
import dpg_gauges as dpgg
|
||||
|
||||
GRID = "connector_grid"
|
||||
ACTIVE_TAGS: list[str] = []
|
||||
CYCLE = 0
|
||||
|
||||
|
||||
def connect_connector() -> None:
|
||||
global CYCLE
|
||||
if ACTIVE_TAGS:
|
||||
return
|
||||
for index in range(5):
|
||||
tag = f"connector_{CYCLE}_{index}"
|
||||
ACTIVE_TAGS.append(tag)
|
||||
dpgg.digital_gauge(
|
||||
tag=tag,
|
||||
parent=GRID,
|
||||
label=f"Conn {CYCLE}.{index}",
|
||||
value=(CYCLE * 13 + index * 17) % 100,
|
||||
unit="%",
|
||||
height=72,
|
||||
)
|
||||
CYCLE += 1
|
||||
|
||||
|
||||
def disconnect_connector() -> None:
|
||||
while ACTIVE_TAGS:
|
||||
dpgg.delete_gauge(ACTIVE_TAGS.pop())
|
||||
|
||||
|
||||
def reconnect_connector() -> None:
|
||||
disconnect_connector()
|
||||
connect_connector()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
dpg.create_context()
|
||||
try:
|
||||
with dpg.window(label="Reconnect grid test", width=860, height=420):
|
||||
dpg.add_text("Reconnect should always start at the first grid cell.")
|
||||
with dpgg.gauge_panel(label="Connector gauges", width=820, height=230):
|
||||
dpgg.gauge_grid(tag=GRID, columns="auto", min_column_width=180)
|
||||
with dpg.group(horizontal=True):
|
||||
dpg.add_button(label="Connect", callback=connect_connector)
|
||||
dpg.add_button(label="Disconnect", callback=disconnect_connector)
|
||||
dpg.add_button(label="Reconnect", callback=reconnect_connector)
|
||||
|
||||
dpg.set_frame_callback(2, connect_connector)
|
||||
dpg.create_viewport(title="dpg-gauges reconnect grid", width=900, height=460)
|
||||
dpg.setup_dearpygui()
|
||||
dpg.show_viewport()
|
||||
dpg.start_dearpygui()
|
||||
finally:
|
||||
dpg.destroy_context()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user