Browse Source

fixed copy shape

Hussein 13 years ago
parent
commit
f51cb91f7c
3 changed files with 14 additions and 4 deletions
  1. 11 1
      canvas.py
  2. 1 1
      labelme.py
  3. 2 2
      shape.py

+ 11 - 1
canvas.py

@@ -355,7 +355,17 @@ class Canvas(QWidget):
         self.shapes = list(shapes)
         self.current = None
         self.repaint()
-
+        
+    def copySelectedShape(self):
+        if self.selectedShape:
+            newShape=self.selectedShape.copy()
+            self.shapes.append(newShape)
+            self.deSelectShape()
+            self.shapes[-1].selected=True
+            self.selectedShape=self.shapes[-1]
+            self.repaint()
+            return self.selectedShape
+    
     def setShapeVisible(self, shape, value):
         self.visible[shape] = value
         self.repaint()

+ 1 - 1
labelme.py

@@ -231,7 +231,7 @@ class MainWindow(QMainWindow, WindowMixin):
         lf.save(filename, shapes, unicode(self.filename), self.imageData)
 
     def copySelectedShape(self):
-        self.addLabel(self.copySelectedShape())
+        self.addLabel(self.canvas.copySelectedShape())
 
     def highlightLabel(self, item):
         if self.highlighted:

+ 2 - 2
shape.py

@@ -89,9 +89,9 @@ class Shape(object):
         self.points = [p + offset for p in self.points]
 
     def copy(self):
-        shape = Shape()
+        shape = Shape("Copy of %s" % self.label )
         shape.points= [p for p in self.points]
-        shape.label = "Copy of %s" % self.label
+        #shape.label = 
         shape.fill = self.fill
         shape.selected = self.selected
         return shape