annotate Sphinx/source/plugins/python/sample-python-button.py @ 1018:868552e0caf8

python venv
author Alain Mazy <am@osimis.io>
date Thu, 25 Jan 2024 11:33:50 +0100
parents eb49a4ad8fbc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
975
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 import orthanc
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import platform
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 def ExecutePython(output, uri, **request):
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 s = 'Python version: %s' % platform.python_version()
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 output.AnswerBuffer(s, 'text/plain')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 orthanc.RegisterRestCallback('/execute-python', ExecutePython)
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 orthanc.ExtendOrthancExplorer('''
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 $('#lookup').live('pagebeforeshow', function() {
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 $('#sample-python-button').remove();
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 var b = $('<a>')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 .attr('id', 'sample-python-button')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 .attr('data-role', 'button')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 .attr('href', '#')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 .attr('data-icon', 'forward')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 .attr('data-theme', 'a')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 .text('Execute sample Python plugin')
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 .button()
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 .click(function(e) {
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 $.get('../execute-python', function(answer) {
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 alert(answer);
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 });
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 });
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 b.insertAfter($('#lookup-result'));
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 });
eb49a4ad8fbc Python plugin: Extending the Orthanc Explorer interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 ''')