view Sphinx/source/plugins/python/sample-python-button.py @ 1013:ab270400aae1

python: overriding core API
author Alain Mazy <am@osimis.io>
date Tue, 09 Jan 2024 11:50:17 +0100
parents eb49a4ad8fbc
children
line wrap: on
line source

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'));
});
''')