1# -*- coding: utf-8 -*-
2"""
3Demonstrate ability of ImageItem to be used as a canvas for painting with
4the mouse.
5
6"""
7
8import initExample ## Add path to library (just for examples; you do not need this)
9
10
11from pyqtgraph.Qt import QtCore, QtGui
12import numpy as np
13import pyqtgraph as pg
14
15app = pg.mkQApp("Draw Example")
16
17## Create window with GraphicsView widget
18w = pg.GraphicsView()
19w.show()
20w.resize(800,800)
21w.setWindowTitle('pyqtgraph example: Draw')
22
23view = pg.ViewBox()
24w.setCentralItem(view)
25
26## lock the aspect ratio
27view.setAspectLocked(True)
28
29## Create image item
30img = pg.ImageItem(np.zeros((200,200)))
31view.addItem(img)
32
33## Set initial view bounds
34view.setRange(QtCore.QRectF(0, 0, 200, 200))
35
36## start drawing with 3x3 brush
37kern = np.array([
38    [0.0, 0.5, 0.0],
39    [0.5, 1.0, 0.5],
40    [0.0, 0.5, 0.0]
41])
42img.setDrawKernel(kern, mask=kern, center=(1,1), mode='add')
43img.setLevels([0, 10])
44
45if __name__ == '__main__':
46    pg.exec()
47