@ -223,6 +223,50 @@ namespace RedirectOutput
}
}
} // namespace RedirectOutput
} // namespace RedirectOutput
namespace O3DEProjectManagerPy
{
using DownloadProgressFunc = AZStd : : function < void ( int ) > ;
DownloadProgressFunc currentProgressCallback ;
bool requestCancelDownload = false ;
static PyObject * CLICancelDownload ( PyObject * /*self*/ , PyObject * /*args*/ )
{
if ( requestCancelDownload )
{
return Py_True ;
}
else
{
return Py_False ;
}
}
static PyObject * CLIDownloadProgress ( PyObject * /*self*/ , PyObject * args )
{
int progress_percentage = 0 ;
if ( ! PyArg_ParseTuple ( args , " i " , & progress_percentage ) )
return NULL ;
if ( currentProgressCallback )
{
currentProgressCallback ( progress_percentage ) ;
}
Py_RETURN_NONE ;
}
static PyMethodDef O3DEPMPyMethods [ ] = { { " download_progress " , CLIDownloadProgress , METH_VARARGS , " Used to call back to the UI to inform of download progress. " } ,
{ " request_cancel_download " , CLICancelDownload , METH_NOARGS , " Returns that the UI is requesting that the current download be cancelled. " } ,
{ NULL , NULL , 0 , NULL } } ;
static PyModuleDef O3DEPMPyModule = { PyModuleDef_HEAD_INIT , " o3de_projectmanager " , NULL , - 1 , O3DEPMPyMethods , NULL , NULL , NULL , NULL } ;
static PyObject * PyInit_O3DEPMPy ( void )
{
return PyModule_Create ( & O3DEPMPyModule ) ;
}
} // namespace O3DEProjectManagerPy
namespace O3DE : : ProjectManager
namespace O3DE : : ProjectManager
{
{
PythonBindings : : PythonBindings ( const AZ : : IO : : PathView & enginePath )
PythonBindings : : PythonBindings ( const AZ : : IO : : PathView & enginePath )
@ -270,6 +314,7 @@ namespace O3DE::ProjectManager
AZ_TracePrintf ( " python " , " Py_GetProgramFullPath=%ls \n " , Py_GetProgramFullPath ( ) ) ;
AZ_TracePrintf ( " python " , " Py_GetProgramFullPath=%ls \n " , Py_GetProgramFullPath ( ) ) ;
PyImport_AppendInittab ( " azlmbr_redirect " , RedirectOutput : : PyInit_RedirectOutput ) ;
PyImport_AppendInittab ( " azlmbr_redirect " , RedirectOutput : : PyInit_RedirectOutput ) ;
PyImport_AppendInittab ( " o3de_projectmanager " , & O3DEProjectManagerPy : : PyInit_O3DEPMPy ) ;
try
try
{
{
@ -1080,6 +1125,8 @@ namespace O3DE::ProjectManager
AZ : : Outcome < void , AZStd : : string > PythonBindings : : DownloadGem ( const QString & gemName , std : : function < void ( int ) > gemProgressCallback )
AZ : : Outcome < void , AZStd : : string > PythonBindings : : DownloadGem ( const QString & gemName , std : : function < void ( int ) > gemProgressCallback )
{
{
bool downloadSucceeded = false ;
bool downloadSucceeded = false ;
O3DEProjectManagerPy : : currentProgressCallback = gemProgressCallback ;
O3DEProjectManagerPy : : requestCancelDownload = false ;
auto result = ExecuteWithLockErrorHandling (
auto result = ExecuteWithLockErrorHandling (
[ & ]
[ & ]
{
{
@ -1091,6 +1138,8 @@ namespace O3DE::ProjectManager
downloadSucceeded = ( downloadResult . cast < int > ( ) = = 0 ) ;
downloadSucceeded = ( downloadResult . cast < int > ( ) = = 0 ) ;
} ) ;
} ) ;
O3DEProjectManagerPy : : currentProgressCallback = nullptr ;
if ( ! result . IsSuccess ( ) )
if ( ! result . IsSuccess ( ) )
{
{
return result ;
return result ;
@ -1102,4 +1151,9 @@ namespace O3DE::ProjectManager
return AZ : : Success ( ) ;
return AZ : : Success ( ) ;
}
}
void PythonBindings : : CancelDownload ( )
{
O3DEProjectManagerPy : : requestCancelDownload = true ;
}
}
}