Kaynağa Gözat

Fix for PyQt4

Kentaro Wada 7 yıl önce
ebeveyn
işleme
dc1fd35fde
3 değiştirilmiş dosya ile 17 ekleme ve 27 silme
  1. 2 3
      labelme/app.py
  2. 15 16
      labelme/canvas.py
  3. 0 8
      labelme/compat.py

+ 2 - 3
labelme/app.py

@@ -16,7 +16,6 @@ from labelme import __appname__
 from labelme import __version__
 from labelme.canvas import Canvas
 from labelme.colorDialog import ColorDialog
-from labelme.compat import QPoint
 from labelme.compat import QT5
 from labelme.config import get_config
 from labelme.labelDialog import LabelDialog
@@ -445,7 +444,7 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
         # FIXME: QSettings.value can return None on PyQt4
         self.recentFiles = self.settings.value('recentFiles', []) or []
         size = self.settings.value('window/size', QtCore.QSize(600, 500))
-        position = self.settings.value('window/position', QPoint(0, 0))
+        position = self.settings.value('window/position', QtCore.QPoint(0, 0))
         self.resize(size)
         self.move(position)
         # or simply:
@@ -695,7 +694,7 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
         for label, points, line_color, fill_color in shapes:
             shape = Shape(label=label)
             for x, y in points:
-                shape.addPoint(QPoint(x, y))
+                shape.addPoint(QtCore.QPoint(x, y))
             shape.close()
             s.append(shape)
             if line_color:

+ 15 - 16
labelme/canvas.py

@@ -2,7 +2,6 @@ from qtpy import QtCore
 from qtpy import QtGui
 from qtpy import QtWidgets
 
-from labelme.compat import QPoint
 from labelme.compat import QT5
 from labelme.lib import distance
 from labelme.shape import Shape
@@ -21,7 +20,7 @@ CURSOR_GRAB = QtCore.Qt.OpenHandCursor
 
 class Canvas(QtWidgets.QWidget):
 
-    zoomRequest = QtCore.Signal(int, QPoint)
+    zoomRequest = QtCore.Signal(int, QtCore.QPoint)
     scrollRequest = QtCore.Signal(int, int)
     newShape = QtCore.Signal()
     selectionChanged = QtCore.Signal(bool)
@@ -44,9 +43,9 @@ class Canvas(QtWidgets.QWidget):
         self.selectedShapeCopy = None
         self.lineColor = QtGui.QColor(0, 0, 255)
         self.line = Shape(line_color=self.lineColor)
-        self.prevPoint = QPoint()
-        self.prevMovePoint = QPoint()
-        self.offsets = QPoint(), QPoint()
+        self.prevPoint = QtCore.QPoint()
+        self.prevMovePoint = QtCore.QPoint()
+        self.offsets = QtCore.QPoint(), QtCore.QPoint()
         self.scale = 1.0
         self.pixmap = QtGui.QPixmap()
         self.visible = {}
@@ -344,7 +343,7 @@ class Canvas(QtWidgets.QWidget):
         y1 = rect.y() - point.y()
         x2 = (rect.x() + rect.width()) - point.x()
         y2 = (rect.y() + rect.height()) - point.y()
-        self.offsets = QPoint(x1, y1), QPoint(x2, y2)
+        self.offsets = QtCore.QPoint(x1, y1), QtCore.QPoint(x2, y2)
 
     def boundedMoveVertex(self, pos):
         index, shape = self.hVertex, self.hShape
@@ -358,11 +357,11 @@ class Canvas(QtWidgets.QWidget):
             return False  # No need to move
         o1 = pos + self.offsets[0]
         if self.outOfPixmap(o1):
-            pos -= QPoint(min(0, o1.x()), min(0, o1.y()))
+            pos -= QtCore.QPoint(min(0, o1.x()), min(0, o1.y()))
         o2 = pos + self.offsets[1]
         if self.outOfPixmap(o2):
-            pos += QPoint(min(0, self.pixmap.width() - o2.x()),
-                          min(0, self.pixmap.height() - o2.y()))
+            pos += QtCore.QPoint(min(0, self.pixmap.width() - o2.x()),
+                                 min(0, self.pixmap.height() - o2.y()))
         # XXX: The next line tracks the new position of the cursor
         # relative to the shape, but also results in making it
         # a bit "shaky" when nearing the border and allows it to
@@ -407,7 +406,7 @@ class Canvas(QtWidgets.QWidget):
         # Try to move in one direction, and if it fails in another.
         # Give up if both fail.
         point = shape[0]
-        offset = QPoint(2.0, 2.0)
+        offset = QtCore.QPoint(2.0, 2.0)
         self.calculateOffsets(shape, point)
         self.prevPoint = point
         if not self.boundedMoveShape(shape, point - offset):
@@ -452,7 +451,7 @@ class Canvas(QtWidgets.QWidget):
         aw, ah = area.width(), area.height()
         x = (aw - w) / (2 * s) if aw > w else 0
         y = (ah - h) / (2 * s) if ah > h else 0
-        return QPoint(x, y)
+        return QtCore.QPoint(x, y)
 
     def outOfPixmap(self, p):
         w, h = self.pixmap.width(), self.pixmap.height()
@@ -491,10 +490,10 @@ class Canvas(QtWidgets.QWidget):
         if (x, y) == (x1, y1):
             # Handle cases where previous point is on one of the edges.
             if x3 == x4:
-                return QPoint(x3, min(max(0, y2), max(y3, y4)))
+                return QtCore.QPoint(x3, min(max(0, y2), max(y3, y4)))
             else:  # y3 == y4
-                return QPoint(min(max(0, x2), max(x3, x4)), y3)
-        return QPoint(x, y)
+                return QtCore.QPoint(min(max(0, x2), max(x3, x4)), y3)
+        return QtCore.QPoint(x, y)
 
     def intersectingEdges(self, point1, point2, points):
         """Find intersecting edges.
@@ -521,8 +520,8 @@ class Canvas(QtWidgets.QWidget):
             if 0 <= ua <= 1 and 0 <= ub <= 1:
                 x = x1 + ua * (x2 - x1)
                 y = y1 + ua * (y2 - y1)
-                m = QPoint((x3 + x4) / 2, (y3 + y4) / 2)
-                d = distance(m - QPoint(x2, y2))
+                m = QtCore.QPoint((x3 + x4) / 2, (y3 + y4) / 2)
+                d = distance(m - QtCore.QPoint(x2, y2))
                 yield d, i, (x, y)
 
     # These two, along with a call to adjustSize are required for the

+ 0 - 8
labelme/compat.py

@@ -1,15 +1,7 @@
 from qtpy import QT_VERSION
-from qtpy import QtCore
 
 
 QT5 = QT_VERSION[0] == '5'
 
 
-if QT5:
-    QPoint = QtCore.QPoint
-else:
-    QPoint = QtCore.QPointF
-
-
 del QT_VERSION
-del QtCore