# pyright: reportGeneralTypeIssues=false import dearpygui.dearpygui as dpg import dpg_gauges as dpgg COUNTERS: dict[str, int] = {} def add_runtime_gauges(grid: str, prefix: str, count: int = 6) -> None: start = COUNTERS.get(grid, 0) for offset in range(count): index = start + offset value = (index * 17 + 23) % 101 dpgg.digital_gauge( tag=f"{prefix}_{index}", parent=grid, label=f"{prefix} {index + 1}", value=value, unit="%", height=72, ) COUNTERS[grid] = start + count def main() -> None: dpg.create_context() try: with dpg.window(label="Runtime autobreak tests", width=1220, height=900): dpg.add_text("Fixed panel, runtime gauges: expected 5 columns at width=1000") with dpgg.gauge_panel(label="Fixed 1000 x 230", width=1000, height=230): dpgg.gauge_grid(tag="fixed_runtime_grid", columns="auto", min_column_width=180) dpg.add_button( label="Add fixed gauges", callback=lambda: add_runtime_gauges("fixed_runtime_grid", "fixed"), ) dpg.add_spacer(height=10) dpg.add_text("Autosize panel with configured size: should match fixed panel") with dpgg.gauge_panel( label="Autosize configured 1000 x 230", width=1000, height=230, autosize_x=True, autosize_y=True, ): dpgg.gauge_grid(tag="autosize_runtime_grid", columns="auto", min_column_width=180) dpg.add_button( label="Add autosize gauges", callback=lambda: add_runtime_gauges("autosize_runtime_grid", "auto"), ) dpg.add_spacer(height=10) dpg.add_text("Autosize panel without width: grid falls back to the owning window width") with dpgg.gauge_panel(label="Autosize inherited width", height=230, autosize_x=True): dpgg.gauge_grid(tag="inherited_runtime_grid", columns="auto", min_column_width=180) dpg.add_button( label="Add inherited-width gauges", callback=lambda: add_runtime_gauges("inherited_runtime_grid", "inherited"), ) dpg.add_spacer(height=10) dpg.add_text("Narrow autosize panel: expected 2 columns at width=430") with dpgg.gauge_panel( label="Narrow autosize 430 x 210", width=430, height=210, autosize_x=True, autosize_y=True, ): dpgg.gauge_grid(tag="narrow_runtime_grid", columns="auto", min_column_width=180) dpg.add_button( label="Add narrow gauges", callback=lambda: add_runtime_gauges("narrow_runtime_grid", "narrow"), ) dpg.set_frame_callback(2, lambda: add_runtime_gauges("fixed_runtime_grid", "fixed")) dpg.set_frame_callback(3, lambda: add_runtime_gauges("autosize_runtime_grid", "auto")) dpg.set_frame_callback(4, lambda: add_runtime_gauges("inherited_runtime_grid", "inherited")) dpg.set_frame_callback(5, lambda: add_runtime_gauges("narrow_runtime_grid", "narrow")) dpg.create_viewport(title="dpg-gauges runtime autobreak", width=1260, height=940) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() finally: dpg.destroy_context() if __name__ == "__main__": main()