Skip to content
Snippets Groups Projects
Commit 796a1a25 authored by Kentaro Wada's avatar Kentaro Wada
Browse files

Fix for flake8: labelme/shape.py

parent 95c22cd5
No related branches found
No related tags found
No related merge requests found
# flake8: noqa
# -*- coding: utf-8 -*-
# #
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid. # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
# #
...@@ -20,32 +18,32 @@ ...@@ -20,32 +18,32 @@
# #
try: try:
from PyQt5.QtGui import * from PyQt5 import QtGui
from PyQt5.QtCore import *
except ImportError: except ImportError:
from PyQt4.QtGui import * from PyQt4 import QtGui
from PyQt4.QtCore import *
from .lib import distance from .lib import distance
# TODO:
# TODO(unknown):
# - [opt] Store paths instead of creating new ones at each paint. # - [opt] Store paths instead of creating new ones at each paint.
DEFAULT_LINE_COLOR = QColor(0, 255, 0, 128)
DEFAULT_FILL_COLOR = QColor(255, 0, 0, 128) DEFAULT_LINE_COLOR = QtGui.QColor(0, 255, 0, 128)
DEFAULT_SELECT_LINE_COLOR = QColor(255, 255, 255) DEFAULT_FILL_COLOR = QtGui.QColor(255, 0, 0, 128)
DEFAULT_SELECT_FILL_COLOR = QColor(0, 128, 255, 155) DEFAULT_SELECT_LINE_COLOR = QtGui.QColor(255, 255, 255)
DEFAULT_VERTEX_FILL_COLOR = QColor(0, 255, 0, 255) DEFAULT_SELECT_FILL_COLOR = QtGui.QColor(0, 128, 255, 155)
DEFAULT_HVERTEX_FILL_COLOR = QColor(255, 0, 0) DEFAULT_VERTEX_FILL_COLOR = QtGui.QColor(0, 255, 0, 255)
DEFAULT_HVERTEX_FILL_COLOR = QtGui.QColor(255, 0, 0)
class Shape(object): class Shape(object):
P_SQUARE, P_ROUND = 0, 1 P_SQUARE, P_ROUND = 0, 1
MOVE_VERTEX, NEAR_VERTEX = 0, 1 MOVE_VERTEX, NEAR_VERTEX = 0, 1
## The following class variables influence the drawing # The following class variables influence the drawing of all shape objects.
## of _all_ shape objects.
line_color = DEFAULT_LINE_COLOR line_color = DEFAULT_LINE_COLOR
fill_color = DEFAULT_FILL_COLOR fill_color = DEFAULT_FILL_COLOR
select_line_color = DEFAULT_SELECT_LINE_COLOR select_line_color = DEFAULT_SELECT_LINE_COLOR
...@@ -100,14 +98,15 @@ class Shape(object): ...@@ -100,14 +98,15 @@ class Shape(object):
def paint(self, painter): def paint(self, painter):
if self.points: if self.points:
color = self.select_line_color if self.selected else self.line_color color = self.select_line_color \
pen = QPen(color) if self.selected else self.line_color
pen = QtGui.QPen(color)
# Try using integer sizes for smoother drawing(?) # Try using integer sizes for smoother drawing(?)
pen.setWidth(max(1, int(round(2.0 / self.scale)))) pen.setWidth(max(1, int(round(2.0 / self.scale))))
painter.setPen(pen) painter.setPen(pen)
line_path = QPainterPath() line_path = QtGui.QPainterPath()
vrtx_path = QPainterPath() vrtx_path = QtGui.QPainterPath()
line_path.moveTo(self.points[0]) line_path.moveTo(self.points[0])
# Uncommenting the following line will draw 2 paths # Uncommenting the following line will draw 2 paths
...@@ -125,7 +124,8 @@ class Shape(object): ...@@ -125,7 +124,8 @@ class Shape(object):
painter.drawPath(vrtx_path) painter.drawPath(vrtx_path)
painter.fillPath(vrtx_path, self.vertex_fill_color) painter.fillPath(vrtx_path, self.vertex_fill_color)
if self.fill: if self.fill:
color = self.select_fill_color if self.selected else self.fill_color color = self.select_fill_color \
if self.selected else self.fill_color
painter.fillPath(line_path, color) painter.fillPath(line_path, color)
def drawVertex(self, path, i): def drawVertex(self, path, i):
...@@ -160,7 +160,7 @@ class Shape(object): ...@@ -160,7 +160,7 @@ class Shape(object):
return self.makePath().contains(point) return self.makePath().contains(point)
def makePath(self): def makePath(self):
path = QPainterPath(self.points[0]) path = QtGui.QPainterPath(self.points[0])
for p in self.points[1:]: for p in self.points[1:]:
path.lineTo(p) path.lineTo(p)
return path return path
...@@ -201,4 +201,3 @@ class Shape(object): ...@@ -201,4 +201,3 @@ class Shape(object):
def __setitem__(self, key, value): def __setitem__(self, key, value):
self.points[key] = value self.points[key] = value
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment