Exemplo n.º 1
0
	def __init__(self, parent, app, trafo=[] + sk2_const.NORMAL_TRAFO,
				transforms=[] + sk2_const.PATTERN_TRANSFORMS, onchange=None):
		self.app = app
		self.callback = onchange
		wal.VPanel.__init__(self, parent)

		grid = wal.GridPanel(self, 3, 7, 3, 2)

		#---Origin X
		txt = _('Horizontal origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_X, txt))
		self.origin_x = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_x)
		grid.pack(StaticUnitLabel(app, grid))

		grid.pack((10, 5))

		#---Origin Y
		txt = _('Vertical origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_Y, txt))
		self.origin_y = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_y)
		grid.pack(StaticUnitLabel(app, grid))

		#---Scale X
		txt = _('Scale horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_X, txt))
		self.scale_x = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_x)
		grid.pack(wal.Label(grid, '%'))

		grid.pack((10, 5))

		#---Scale Y
		txt = _('Scale vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_Y, txt))
		self.scale_y = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_y)
		grid.pack(wal.Label(grid, '%'))

		#---Shear X
		txt = _('Shear horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_X, txt))
		self.shear_x = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_x)
		grid.pack(wal.Label(grid, u'°'))

		grid.pack((10, 5))

		#---Shear X
		txt = _('Shear vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_Y, txt))
		self.shear_y = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_y)
		grid.pack(wal.Label(grid, u'°'))

		self.pack(grid)

		#---Rotate
		rot_panel = wal.HPanel(self)
		txt = _('Rotate pattern')
		rot_panel.pack(get_bmp(rot_panel, icons.PD_PATTERN_ROTATE, txt))
		self.rotate = wal.FloatSpin(rot_panel, range_val=(-360.0, 360.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		rot_panel.pack(self.rotate, padding=3)
		rot_panel.pack(wal.Label(rot_panel, u'°'))

		self.pack(rot_panel, padding=5)

		self.set_trafo(trafo, transforms)
Exemplo n.º 2
0
	def __init__(self, parent, app, trafo=[] + sk2_const.NORMAL_TRAFO,
				transforms=[] + sk2_const.PATTERN_TRANSFORMS, onchange=None):
		self.app = app
		self.callback = onchange
		wal.VPanel.__init__(self, parent)

		grid = wal.GridPanel(self, 3, 7, 3, 2)

		#---Origin X
		txt = _('Horizontal origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_X, txt))
		self.origin_x = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_x)
		grid.pack(StaticUnitLabel(app, grid))

		grid.pack((10, 5))

		#---Origin Y
		txt = _('Vertical origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_Y, txt))
		self.origin_y = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_y)
		grid.pack(StaticUnitLabel(app, grid))

		#---Scale X
		txt = _('Scale horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_X, txt))
		self.scale_x = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_x)
		grid.pack(wal.Label(grid, '%'))

		grid.pack((10, 5))

		#---Scale Y
		txt = _('Scale vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_Y, txt))
		self.scale_y = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_y)
		grid.pack(wal.Label(grid, '%'))

		#---Shear X
		txt = _('Shear horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_X, txt))
		self.shear_x = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_x)
		grid.pack(wal.Label(grid, '°'))

		grid.pack((10, 5))

		#---Shear X
		txt = _('Shear vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_Y, txt))
		self.shear_y = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_y)
		grid.pack(wal.Label(grid, '°'))

		self.pack(grid)

		#---Rotate
		rot_panel = wal.HPanel(self)
		txt = _('Rotate pattern')
		rot_panel.pack(get_bmp(rot_panel, icons.PD_PATTERN_ROTATE, txt))
		self.rotate = wal.FloatSpin(rot_panel, range_val=(-360.0, 360.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		rot_panel.pack(self.rotate, padding=3)
		rot_panel.pack(wal.Label(rot_panel, '°'))

		self.pack(rot_panel, padding=5)

		self.set_trafo(trafo, transforms)
Exemplo n.º 3
0
class TransformEditor(wal.VPanel):

	app = None
	callback = None
	transforms = []


	def __init__(self, parent, app, trafo=[] + sk2_const.NORMAL_TRAFO,
				transforms=[] + sk2_const.PATTERN_TRANSFORMS, onchange=None):
		self.app = app
		self.callback = onchange
		wal.VPanel.__init__(self, parent)

		grid = wal.GridPanel(self, 3, 7, 3, 2)

		#---Origin X
		txt = _('Horizontal origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_X, txt))
		self.origin_x = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_x)
		grid.pack(StaticUnitLabel(app, grid))

		grid.pack((10, 5))

		#---Origin Y
		txt = _('Vertical origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_Y, txt))
		self.origin_y = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_y)
		grid.pack(StaticUnitLabel(app, grid))

		#---Scale X
		txt = _('Scale horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_X, txt))
		self.scale_x = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_x)
		grid.pack(wal.Label(grid, '%'))

		grid.pack((10, 5))

		#---Scale Y
		txt = _('Scale vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_Y, txt))
		self.scale_y = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_y)
		grid.pack(wal.Label(grid, '%'))

		#---Shear X
		txt = _('Shear horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_X, txt))
		self.shear_x = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_x)
		grid.pack(wal.Label(grid, u'°'))

		grid.pack((10, 5))

		#---Shear X
		txt = _('Shear vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_Y, txt))
		self.shear_y = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_y)
		grid.pack(wal.Label(grid, u'°'))

		self.pack(grid)

		#---Rotate
		rot_panel = wal.HPanel(self)
		txt = _('Rotate pattern')
		rot_panel.pack(get_bmp(rot_panel, icons.PD_PATTERN_ROTATE, txt))
		self.rotate = wal.FloatSpin(rot_panel, range_val=(-360.0, 360.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		rot_panel.pack(self.rotate, padding=3)
		rot_panel.pack(wal.Label(rot_panel, u'°'))

		self.pack(rot_panel, padding=5)

		self.set_trafo(trafo, transforms)

	def set_trafo(self, trafo, transforms):
		x0, y0 = trafo[-2:]
		sx, sy, shx, shy, rotate = transforms
		self.origin_x.set_point_value(x0)
		self.origin_y.set_point_value(y0)
		self.scale_x.set_value(sx * 100.0)
		self.scale_y.set_value(sy * 100.0)
		self.shear_x.set_value(shx * 180.0 / math.pi)
		self.shear_y.set_value(shy * 180.0 / math.pi)
		self.rotate.set_value(rotate * 180.0 / math.pi)
		self.transforms = transforms

	def get_trafo(self):
		x0 = self.origin_x.get_point_value()
		y0 = self.origin_y.get_point_value()
		sx = self.scale_x.get_value() / 100.0
		sy = self.scale_y.get_value() / 100.0
		shx = self.shear_x.get_value()
		shy = self.shear_y.get_value()

		if shx + shy > 85:
			if shx == self.transforms[3]: shy = 85 - shx
			else: shx = 85 - shy

		shx = math.pi * shx / 180.0
		shy = math.pi * shy / 180.0

		angle = math.pi * self.rotate.get_value() / 180.0

		trafo = [sx, 0.0, 0.0, sy, x0, y0]
		if angle:
			trafo2 = [math.cos(angle), math.sin(angle),
					- math.sin(angle), math.cos(angle), 0.0, 0.0]
			trafo = libgeom.multiply_trafo(trafo, trafo2)
		if shx or shy:
			trafo2 = [1.0, math.tan(shy), math.tan(shx), 1.0, 0.0, 0.0]
			trafo = libgeom.multiply_trafo(trafo, trafo2)

		self.transforms = [sx, sy, shx, shy, angle]
		return trafo, [sx, sy, shx, shy, angle]

	def changes(self, *args):
		if self.callback: self.callback(*self.get_trafo())
Exemplo n.º 4
0
class TransformEditor(wal.VPanel):

	app = None
	callback = None
	transforms = []


	def __init__(self, parent, app, trafo=[] + sk2_const.NORMAL_TRAFO,
				transforms=[] + sk2_const.PATTERN_TRANSFORMS, onchange=None):
		self.app = app
		self.callback = onchange
		wal.VPanel.__init__(self, parent)

		grid = wal.GridPanel(self, 3, 7, 3, 2)

		#---Origin X
		txt = _('Horizontal origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_X, txt))
		self.origin_x = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_x)
		grid.pack(StaticUnitLabel(app, grid))

		grid.pack((10, 5))

		#---Origin Y
		txt = _('Vertical origin shift')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_Y, txt))
		self.origin_y = UnitSpin(app, grid, can_be_negative=True,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.origin_y)
		grid.pack(StaticUnitLabel(app, grid))

		#---Scale X
		txt = _('Scale horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_X, txt))
		self.scale_x = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_x)
		grid.pack(wal.Label(grid, '%'))

		grid.pack((10, 5))

		#---Scale Y
		txt = _('Scale vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_Y, txt))
		self.scale_y = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0),
								step=1.0, width=5,
								onchange=self.changes, onenter=self.changes)
		grid.pack(self.scale_y)
		grid.pack(wal.Label(grid, '%'))

		#---Shear X
		txt = _('Shear horizontally')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_X, txt))
		self.shear_x = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_x)
		grid.pack(wal.Label(grid, '°'))

		grid.pack((10, 5))

		#---Shear X
		txt = _('Shear vertically')
		grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_Y, txt))
		self.shear_y = wal.FloatSpin(grid, range_val=(0.0, 85.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		grid.pack(self.shear_y)
		grid.pack(wal.Label(grid, '°'))

		self.pack(grid)

		#---Rotate
		rot_panel = wal.HPanel(self)
		txt = _('Rotate pattern')
		rot_panel.pack(get_bmp(rot_panel, icons.PD_PATTERN_ROTATE, txt))
		self.rotate = wal.FloatSpin(rot_panel, range_val=(-360.0, 360.0),
						step=1.0, width=5,
						onchange=self.changes, onenter=self.changes)
		rot_panel.pack(self.rotate, padding=3)
		rot_panel.pack(wal.Label(rot_panel, '°'))

		self.pack(rot_panel, padding=5)

		self.set_trafo(trafo, transforms)

	def set_trafo(self, trafo, transforms):
		x0, y0 = trafo[-2:]
		sx, sy, shx, shy, rotate = transforms
		self.origin_x.set_point_value(x0)
		self.origin_y.set_point_value(y0)
		self.scale_x.set_value(sx * 100.0)
		self.scale_y.set_value(sy * 100.0)
		self.shear_x.set_value(shx * 180.0 / math.pi)
		self.shear_y.set_value(shy * 180.0 / math.pi)
		self.rotate.set_value(rotate * 180.0 / math.pi)
		self.transforms = transforms

	def get_trafo(self):
		x0 = self.origin_x.get_point_value()
		y0 = self.origin_y.get_point_value()
		sx = self.scale_x.get_value() / 100.0
		sy = self.scale_y.get_value() / 100.0
		shx = self.shear_x.get_value()
		shy = self.shear_y.get_value()

		if shx + shy > 85:
			if shx == self.transforms[3]: shy = 85 - shx
			else: shx = 85 - shy

		shx = math.pi * shx / 180.0
		shy = math.pi * shy / 180.0

		angle = math.pi * self.rotate.get_value() / 180.0

		trafo = [sx, 0.0, 0.0, sy, x0, y0]
		if angle:
			trafo2 = [math.cos(angle), math.sin(angle),
					- math.sin(angle), math.cos(angle), 0.0, 0.0]
			trafo = libgeom.multiply_trafo(trafo, trafo2)
		if shx or shy:
			trafo2 = [1.0, math.tan(shy), math.tan(shx), 1.0, 0.0, 0.0]
			trafo = libgeom.multiply_trafo(trafo, trafo2)

		self.transforms = [sx, sy, shx, shy, angle]
		return trafo, [sx, sy, shx, shy, angle]

	def changes(self, *args):
		if self.callback: self.callback(*self.get_trafo())