Debian Codegraph @

examples/imageprovider_example.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 import math
20
21 def render(image_id, requested_size):
22 print('image_id: "{image_id}", size: {requested_size}'.format(**locals()))
23
24 # width and height will be -1 if not set in QML
25 if requested_size == (-1, -1):
26 requested_size = (300, 300)
27
28 width, height = requested_size
29
30 # center for circle
31 cx, cy = width/2, 10
32
33 pixels = []
34 for y in range(height):
35 for x in range(width):
36 pixels.extend(reversed([
37 255, # alpha
38 int(10 + 10 * ((x - y * 0.5) % 20)), # red
39 20 + 10 * (y % 20), # green
40 int(255 * abs(math.sin(0.3*math.sqrt((cx-x)**2 + (cy-y)**2)))) # blue
41 ]))
42 return bytearray(pixels), (width, height), pyotherside.format_argb32
43
44 pyotherside.set_image_provider(render)