Scatter package: provide lot of widgets based on scatter (base, svg, plane, image...)

# Jump directly to Examples

Scatter package: provide lot of widgets based on scatter (base, svg, plane, image...)

class pymt.ui.widgets.scatter.MTScatterWidget(**kwargs)

Bases: pymt.ui.widgets.scatter.MTScatter

This class is deprecated, you should use MTScatter now.

class pymt.ui.widgets.scatter.MTScatterSvg(**kwargs)

Bases: pymt.ui.widgets.scatter.MTScatterWidget

Render an svg image into a scatter widget

Parameters :
filename : str

Filename of image

rawdata : str

Raw data of the image. If given, the filename property is used only for cache purposes.

class pymt.ui.widgets.scatter.MTScatterPlane(**kwargs)

Bases: pymt.ui.widgets.scatter.MTScatterWidget

A Plane that transforms for zoom/rotate/pan. if none of the childwidgets handles the input (the background is touched), all of them are transformed together

class pymt.ui.widgets.scatter.MTScatterImage(**kwargs)

Bases: pymt.ui.widgets.scatter.MTScatterWidget

MTScatterImage is a image showed in a Scatter widget

Parameters :
filename : str

Filename of image

image : Image

Instead of using filename, use a Image object

opacity : float, default to 1.0

Used to set the opacity of the image.

scale : float, default is 1.0

Scaling of image, default is 100%, ie 1.0

class pymt.ui.widgets.scatter.MTScatter(**kwargs)

Bases: pymt.ui.widgets.widget.MTWidget

MTScatter is a scatter widget based on MTWidget. You can scale, rotate and move with one and two finger.

Parameters :
rotation : float, default to 0.0

Set initial rotation of widget

translation : list, default to (0,0)

Set the initial translation of widget

scale : float, default to 1.0

Set the initial scaling of widget

do_rotation : boolean, default to True

Set to False for disabling rotation

do_translation : boolean or list, default to True

Set to False for disabling translation, and [‘x’], [‘y’] for limit translation only on x or y

do_scale : boolean, default to True

Set to False for disabling scale

auto_bring_to_front : boolean, default to True

Set to False for disabling widget bring to front

scale_min : float, default to 0.01

Minimum scale allowed. Don’t set to 0, or you can have error with singular matrix. The 0.01 mean you can de-zoom up to 10000% (1/0.01*100).

scale_max : float, default to None

Maximum scale allowed.

Events :
on_transform (rotation, scale, trans, intersect)

Fired whenever the Scatter Widget is transformed (rotate, scale, moved, or zoomed).

apply_angle_scale_trans(angle, scale, trans, point=[, 0, 0])

Update matrix transformation by adding new angle, scale and translate.

Parameters :
angle : float

Rotation angle to add

scale : float

Scaling value to add

trans : Vector

Vector translation to add

point : Vector, default to (0, 0)

Point to apply transformation

apply_transform(trans, post_multiply=False, anchor=(0, 0))

Transforms scatter by trans (on top of its current transformation state)

Parameters :
trans: transformation matrix from transformation lib.

Transformation to be applied to the scatter widget

anchor: tuple, default to (0, 0)

The point to use as the origin of the transformation (uses local widget space)

post_multiply: bool, default to False

If true the transform matrix is post multiplied (as if applied before the current transform)

bbox

Returns the bounding box of the widget in parent space

((x, y), (w, h)
# x, y = lower left corner
do_rotation

Determines whether user interaction can rotate the widget

do_scale

Determines whether user interaction can scale the widget

do_translation

Determines whether user interaction can translate the widget

pos

Object position (x, y). Lower left of bounding box for rotated scatter

rotation

Get/set the rotation around center of the object (in degree)

scale

Get/set the scale factor of the object

state

Save/restore the state of matrix widget (require numpy)

transform

Get/Set transformation matrix (numpy matrix)

transform_gl

Return the transformation matrix for OpenGL, read only.

transform_inv

Inverse of transformation matrix (numpy matrix), read only.

transform_inv_gl

Return the inverse transformation matrix for OpenGL, read only.

transform_mat

..deprecated:: 0.5 Use transform_gl for an OpenGL transformation instead.

update_matrices()

Update inverse and OpenGL matrices, from the current transformation. If you change manually the transformation, you should call this function, or the drawing will failed.

Examples

File ui_widgets_scatter_image.py

from pymt import *
import os

# just get the image
current_dir = os.path.dirname(__file__)
filename = os.path.join(current_dir, 'image.jpg')

# create 2 scatter with image
m = MTScatterImage(filename=filename, opacity=.5)
m2 = MTScatterImage(filename=filename, pos=(100, 100))

win = getWindow()
win.add_widget(m)
win.add_widget(m2)

runTouchApp()

File ui_widgets_scatter.py

from pymt import *

# force background draw for scatter
css_add_sheet('''
scatterwidget {
    draw-background: 1;
}''')

# add a simple scatter
scatter = MTScatterWidget(size=(300, 300))

runTouchApp(scatter)

File ui_widgets_scatter_children.py

from pymt import *

# force background draw for scatter
css_add_sheet('''
scatterwidget {
    draw-background: 1;
}''')

# add a simple scatter
scatter = MTScatterWidget(size=(300, 300), pos=(100, 100), rotation=45)

# add some children in
layout = MTBoxLayout()
layout.add_widget(MTButton(label='A1'))
layout.add_widget(MTButton(label='A2'))
scatter.add_widget(layout)

# now, the scatter is rotated, and the button too.
# it's still possible to click on the button, even
# if they are rotated too
runTouchApp(scatter)