From 85f58d31f66f14f8ee8d77d8fc1b315d3af6ef6a Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 7 Aug 2024 12:20:15 +0900 Subject: [PATCH 1/2] add init file --- src/dearpygui.cpp | 1 + src/dearpygui_commands.h | 19 +++++++++++++++++++ src/dearpygui_parsers.h | 14 ++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/dearpygui.cpp b/src/dearpygui.cpp index 58063894f..d27e196b5 100644 --- a/src/dearpygui.cpp +++ b/src/dearpygui.cpp @@ -602,6 +602,7 @@ PyInit__dearpygui(void) MV_ADD_COMMAND(is_dearpygui_running); MV_ADD_COMMAND(generate_uuid); MV_ADD_COMMAND(save_init_file); + MV_ADD_COMMAND(load_init_file); MV_ADD_COMMAND(output_frame_buffer); MV_ADD_COMMAND(load_image); MV_ADD_COMMAND(save_image); diff --git a/src/dearpygui_commands.h b/src/dearpygui_commands.h index c38b047e5..f23f00786 100644 --- a/src/dearpygui_commands.h +++ b/src/dearpygui_commands.h @@ -2152,6 +2152,25 @@ save_init_file(PyObject* self, PyObject* args, PyObject* kwargs) return GetPyNone(); } + +static PyObject* +load_init_file(PyObject* self, PyObject* args, PyObject* kwargs) +{ + const char* file; + + if (!Parse((GetParsers())["load_init_file"], args, kwargs, __FUNCTION__, &file)) + return GetPyNone(); + + if (GContext->started) + ImGui::LoadIniSettingsFromDisk(file); + else + mvThrowPythonError(mvErrorCode::mvNone, "Dear PyGui must be started to use \"load_init_file\"."); + + return GetPyNone(); +} + + + static PyObject* split_frame(PyObject* self, PyObject* args, PyObject* kwargs) { diff --git a/src/dearpygui_parsers.h b/src/dearpygui_parsers.h index 7a5b05238..50bfe6b7b 100644 --- a/src/dearpygui_parsers.h +++ b/src/dearpygui_parsers.h @@ -520,6 +520,20 @@ InsertParser_Block1(std::map& parsers) parsers.insert({ "save_init_file", parser }); } + { + std::vector args; + args.push_back({ mvPyDataType::String, "file" }); + + mvPythonParserSetup setup; + setup.about = "Load dpg.ini file."; + setup.category = { "General" }; + + mvPythonParser parser = FinalizeParser(setup, args); + parsers.insert({ "load_init_file", parser }); + } + + + { std::vector args; args.push_back({ mvPyDataType::Integer, "delay", mvArgType::KEYWORD_ARG, "32", "Minimal delay in in milliseconds" }); From f28d469f012e7dfa43ded768940f822ad2b9ff43 Mon Sep 17 00:00:00 2001 From: toby Date: Fri, 23 Aug 2024 18:13:39 +0900 Subject: [PATCH 2/2] remove duplicated function (deprecated --- dearpygui/dearpygui.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dearpygui/dearpygui.py b/dearpygui/dearpygui.py index 2c02b3771..5e0838bd3 100644 --- a/dearpygui/dearpygui.py +++ b/dearpygui/dearpygui.py @@ -1184,11 +1184,6 @@ def set_init_file(file="dpg.ini"): """ deprecated function """ internal_dpg.configure_app(init_file=file) -@deprecated("Use 'configure_app(init_file=file, load_init_file=True)'.") -def load_init_file(file): - """ deprecated function """ - internal_dpg.configure_app(init_file=file, load_init_file=True) - @deprecated("Use: `is_viewport_ok(...)`") def is_viewport_created(): """ deprecated function """ @@ -8994,6 +8989,18 @@ def save_init_file(file : str, **kwargs) -> None: return internal_dpg.save_init_file(file, **kwargs) +def load_init_file(file: str, **kwargs) -> None: + """ Load dpg.ini file. + + Args: + file (str): + Returns: + None + """ + + return internal_dpg.load_init_file(file, **kwargs) + + def set_axis_limits(axis : Union[int, str], ymin : float, ymax : float, **kwargs) -> None: """ Sets limits on the axis for pan and zoom.