Mercurial > hg > orthanc-book
diff Sphinx/source/plugins/python/sample-python-button.py @ 975:eb49a4ad8fbc
Python plugin: Extending the Orthanc Explorer interface
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Aug 2023 14:04:48 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sphinx/source/plugins/python/sample-python-button.py Tue Aug 29 14:04:48 2023 +0200 @@ -0,0 +1,30 @@ +import orthanc +import platform + +def ExecutePython(output, uri, **request): + s = 'Python version: %s' % platform.python_version() + output.AnswerBuffer(s, 'text/plain') + +orthanc.RegisterRestCallback('/execute-python', ExecutePython) + +orthanc.ExtendOrthancExplorer(''' +$('#lookup').live('pagebeforeshow', function() { + $('#sample-python-button').remove(); + + var b = $('<a>') + .attr('id', 'sample-python-button') + .attr('data-role', 'button') + .attr('href', '#') + .attr('data-icon', 'forward') + .attr('data-theme', 'a') + .text('Execute sample Python plugin') + .button() + .click(function(e) { + $.get('../execute-python', function(answer) { + alert(answer); + }); + }); + + b.insertAfter($('#lookup-result')); +}); +''')