Debian Codegraph @

examples/imageprovider_svg_data.py

raw symbols SCIP
1 #
2 # PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
3 # Copyright (c) 2011, 2013, Thomas Perl <[email protected]>
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11 # FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
16 #
17
18 import pyotherside
19
20 import os
21
22 HERE = os.path.dirname(__file__) or '.'
23
24 def load_data(image_id, requested_size):
25 # If you return data in the format "pyotherside.format_svg_data" requested_size
26 # is is used as the target size when rendering the SVG image
27
28 # We use the image id to get name of the SVG file to render
29 with open(os.path.join(HERE, image_id), 'rb') as f:
30 svg_image_data = f.read()
31
32 return bytearray(svg_image_data), requested_size, pyotherside.format_svg_data
33
34 pyotherside.set_image_provider(load_data)