33#include " Kismet/KismetSystemLibrary.h"
44#include " Kismet/KismetMathLibrary.h"
55
6+ #include " Developer/DesktopPlatform/Public/IDesktopPlatform.h"
7+ #include " Developer/DesktopPlatform/Public/DesktopPlatformModule.h"
8+
69
710
811PyObject *py_unreal_engine_log (PyObject * self, PyObject * args) {
@@ -855,3 +858,134 @@ PyObject *py_unreal_engine_get_transient_package(PyObject *self, PyObject * args
855858 Py_INCREF (ret);
856859 return (PyObject *)ret;
857860}
861+
862+ PyObject *py_unreal_engine_open_file_dialog (PyObject *self, PyObject * args) {
863+ char *title;
864+ char *default_path = (char *)" " ;
865+ char *default_file = (char *)" " ;
866+ char *file_types = (char *)" " ;
867+ PyObject *py_multiple = nullptr ;
868+
869+ if (!PyArg_ParseTuple (args, " s|sssO:open_file_dialog" , &title, &default_path, &default_file, &file_types, &py_multiple))
870+ return nullptr ;
871+
872+ IDesktopPlatform *DesktopPlatform = FDesktopPlatformModule::Get ();
873+ if (!DesktopPlatform)
874+ return PyErr_Format (PyExc_Exception, " unable to get reference to DesktopPlatform module" );
875+
876+ TSharedPtr<SWindow> ParentWindow = FGlobalTabmanager::Get ()->GetRootWindow ();
877+ if (!ParentWindow.IsValid ())
878+ return PyErr_Format (PyExc_Exception, " unable to get the Root Window" );
879+
880+ if (!ParentWindow->GetNativeWindow ().IsValid ())
881+ return PyErr_Format (PyExc_Exception, " unable to get Native Root Window" );
882+
883+ TArray<FString> files;
884+
885+ if (!DesktopPlatform->OpenFileDialog (ParentWindow->GetNativeWindow ()->GetOSWindowHandle (), FString (UTF8_TO_TCHAR (title)),
886+ FString (UTF8_TO_TCHAR (default_path)),
887+ FString (UTF8_TO_TCHAR (default_file)),
888+ FString (UTF8_TO_TCHAR (file_types)),
889+ (py_multiple && PyObject_IsTrue (py_multiple)) ? EFileDialogFlags::Multiple : EFileDialogFlags::None,
890+ files)) {
891+ Py_RETURN_NONE;
892+ }
893+
894+ PyObject *py_list = PyList_New (0 );
895+ for (FString file : files) {
896+ PyList_Append (py_list, PyUnicode_FromString (TCHAR_TO_UTF8 (*file)));
897+ }
898+ return py_list;
899+ }
900+
901+ PyObject *py_unreal_engine_open_directory_dialog (PyObject *self, PyObject * args) {
902+ char *title;
903+ char *default_path = (char *)" " ;
904+
905+ if (!PyArg_ParseTuple (args, " s|s:open_directory_dialog" , &title, &default_path))
906+ return nullptr ;
907+
908+ IDesktopPlatform *DesktopPlatform = FDesktopPlatformModule::Get ();
909+ if (!DesktopPlatform)
910+ return PyErr_Format (PyExc_Exception, " unable to get reference to DesktopPlatform module" );
911+
912+ TSharedPtr<SWindow> ParentWindow = FGlobalTabmanager::Get ()->GetRootWindow ();
913+ if (!ParentWindow.IsValid ())
914+ return PyErr_Format (PyExc_Exception, " unable to get the Root Window" );
915+
916+ if (!ParentWindow->GetNativeWindow ().IsValid ())
917+ return PyErr_Format (PyExc_Exception, " unable to get Native Root Window" );
918+
919+ FString choosen_dir;
920+
921+ if (!DesktopPlatform->OpenDirectoryDialog (ParentWindow->GetNativeWindow ()->GetOSWindowHandle (), FString (UTF8_TO_TCHAR (title)),
922+ FString (UTF8_TO_TCHAR (default_path)),
923+ choosen_dir)) {
924+ Py_RETURN_NONE;
925+ }
926+
927+ return PyUnicode_FromString (TCHAR_TO_UTF8 (*choosen_dir));
928+ }
929+
930+ PyObject *py_unreal_engine_open_font_dialog (PyObject *self, PyObject * args) {
931+
932+ IDesktopPlatform *DesktopPlatform = FDesktopPlatformModule::Get ();
933+ if (!DesktopPlatform)
934+ return PyErr_Format (PyExc_Exception, " unable to get reference to DesktopPlatform module" );
935+
936+ TSharedPtr<SWindow> ParentWindow = FGlobalTabmanager::Get ()->GetRootWindow ();
937+ if (!ParentWindow.IsValid ())
938+ return PyErr_Format (PyExc_Exception, " unable to get the Root Window" );
939+
940+ if (!ParentWindow->GetNativeWindow ().IsValid ())
941+ return PyErr_Format (PyExc_Exception, " unable to get Native Root Window" );
942+
943+ FString font_name;
944+ float height;
945+ EFontImportFlags flags;
946+
947+ if (!DesktopPlatform->OpenFontDialog (ParentWindow->GetNativeWindow ()->GetOSWindowHandle (), font_name, height, flags)) {
948+ Py_RETURN_NONE;
949+ }
950+
951+ return Py_BuildValue ((char *)" (sfi)" , TCHAR_TO_UTF8 (*font_name), height, flags);
952+ }
953+
954+ PyObject *py_unreal_engine_save_file_dialog (PyObject *self, PyObject * args) {
955+ char *title;
956+ char *default_path = (char *)" " ;
957+ char *default_file = (char *)" " ;
958+ char *file_types = (char *)" " ;
959+ PyObject *py_multiple = nullptr ;
960+
961+ if (!PyArg_ParseTuple (args, " s|sssO:save_file_dialog" , &title, &default_path, &default_file, &file_types, &py_multiple))
962+ return nullptr ;
963+
964+ IDesktopPlatform *DesktopPlatform = FDesktopPlatformModule::Get ();
965+ if (!DesktopPlatform)
966+ return PyErr_Format (PyExc_Exception, " unable to get reference to DesktopPlatform module" );
967+
968+ TSharedPtr<SWindow> ParentWindow = FGlobalTabmanager::Get ()->GetRootWindow ();
969+ if (!ParentWindow.IsValid ())
970+ return PyErr_Format (PyExc_Exception, " unable to get the Root Window" );
971+
972+ if (!ParentWindow->GetNativeWindow ().IsValid ())
973+ return PyErr_Format (PyExc_Exception, " unable to get Native Root Window" );
974+
975+ TArray<FString> files;
976+
977+ if (!DesktopPlatform->SaveFileDialog (ParentWindow->GetNativeWindow ()->GetOSWindowHandle (), FString (UTF8_TO_TCHAR (title)),
978+ FString (UTF8_TO_TCHAR (default_path)),
979+ FString (UTF8_TO_TCHAR (default_file)),
980+ FString (UTF8_TO_TCHAR (file_types)),
981+ (py_multiple && PyObject_IsTrue (py_multiple)) ? EFileDialogFlags::Multiple : EFileDialogFlags::None,
982+ files)) {
983+ Py_RETURN_NONE;
984+ }
985+
986+ PyObject *py_list = PyList_New (0 );
987+ for (FString file : files) {
988+ PyList_Append (py_list, PyUnicode_FromString (TCHAR_TO_UTF8 (*file)));
989+ }
990+ return py_list;
991+ }
0 commit comments