shape.py 912 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from PyQt4.QtGui import *
  4. from PyQt4.QtCore import *
  5. class shape(object):
  6. def __init__(self ,label,color):
  7. self.label=label
  8. self.points=[]
  9. self.color=color
  10. self.fill=False
  11. def getLabel(self):
  12. return label
  13. def setLabel(self,label):
  14. self.label=label
  15. def setFill(self,fillB):
  16. self.fill=fillB
  17. def addPoint(self,point):
  18. self.points.append(point)
  19. def drawShape(self,painter):
  20. if len(self.points) >0 :
  21. pen=QPen(self.color)
  22. painter.setPen(pen)
  23. prePoint=self.points[0]
  24. path=QPainterPath()
  25. path.moveTo(prePoint.x(),prePoint.y())
  26. for point in self.points:
  27. path.lineTo(point.x(),point.y())
  28. painter.drawPath(path)
  29. if self.fill:
  30. painter.fillPath(path,Qt.red)