shape.py 866 B

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