forked from rism-digital/verovio.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython.xhtml
88 lines (75 loc) · 2.58 KB
/
python.xhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
layout: verovio
verovio-light: true
title: Verovio – Python Toolkit
active: how
how-active: how-py
---
<div class="row">
<div class="col-md-3 sidebar-offcanvas" id="sidebar" role="navigation">
<div class="panel panel-default">
{% include how-sidebar.html %}
</div>
</div>
<div class="col-md-9">
<div class="panel-body">
<h3>Python toolkit</h3>
<p>
Verovio can be compiled to a Python extention using the <a href="http://www.swig.org" target="_blank">SWIG</a>. The extension module contains a toolkit class similar to the one available in the JavaScript toolkit that can be used for rendering MEI data into SVG strings.
</p>
<h4>Basic usage</h4>
<p>
The information for building the Python extension is provided in the <a href="https://github.com/rism-ch/verovio/wiki/Building-instructions#building-the-python-toolkit">wiki</a> page. Once compiled and installed, you need to run:
</p>
{% highlight python %}>>> import verovio{% endhighlight %}
<p>
You can then create an instance of the toolkit and load data. For example:
</p>
{% highlight python %}
>>> tk = verovio.toolkit()
>>> tk.loadFile("~/gh-pages/examples/hello-world/Haydn_StringQuartet_Op1_No1-p1.mei")
[Warning] Unsupported '<dir>' within <measure>
True
>>> tk.getPageCount()
1
{% endhighlight %}
<p>
Once loaded, the data can be rendered to a string:
</p>
{% highlight python %}
>>> svg_string = tk.renderToSvg(1)
{% endhighlight %}
<p>
It can also be rendered to a file:
</p>
{% highlight python %}
>>> tk.renderToSvgFile( "page.svg", 1 )
True
{% endhighlight %}
<h4>Options</h4>
<p>
The options are set on the toolkit instance. For example, the following code will change to a landscape format and redo the layout for the previously loaded data:
</p>
{% highlight javascript %}
>>> tk.setPageHeight(2100)
True
>>> tk.setPageWidth(2900)
True
>>> tk.setScale(25)
True
>>> tk.redoLayout()
>>> tk.renderToSvgFile( "page-scaled.svg", 1 )
{% endhighlight %}
<h4>Methods</h4>
<p>
See the <code>./include/vrv/toolkit.h</code> file for the toolkit methods (to be further documented).
</p>
</div>
</div>
</div>
<script type="text/javascript">
//<![CDATA[
$( document ).ready(function() {
});
//]]>
</script>