Tool ExampleΒΆ

Example of a tool.

import litho.core as lc
import litho.smile as ls
from PyQt5 import QtGui, QtCore

class TestTool(ls.Tool):
	def __init__(self):
		super().__init__(self)
		self.mouseDown=False
		self.pos = QtCore.QPoint()
	
	def selectionChanged(self):
		print("Selection changed")
	
	def mousePressEvent(self, ev):
		if ev.button() == QtCore.Qt.LeftButton: 
			self.mouseDown = True
			self.pos = ev.pos()
			self.overlayUpdate()
			print("Mouse press")
			return True
		return False
	
	def mouseReleaseEvent(self, ev):
		if ev.button() == QtCore.Qt.LeftButton: 
			self.mouseDown = False
			self.overlayUpdate()
			print("Mouse release")
			return True
		return False

	def mouseMoveEvent(self, ev):
		if self.mouseDown == True: 
			self.pos = ev.pos()
			return True
		return False
	
	def paintOverlay(self, p):
		if self.mouseDown == False: 
			return
		qp = p.qPainter()
#		qp = QtGui.QPainter()
		qp.setPen(QtGui.QPen(QtGui.QColor(255,0,0), 4))
		qp.drawEllipse(self.pos, 10, 10)
	

if lc.lObj.isObjectType("TestTool"):
	lc.removeType(TestTool)

lc.registerObjectType(TestTool)
ls.mainWindow().currentDocument.activateTool("TestTool")