Преглед изворни кода

Fix for flake8: labelme/lib.py

Kentaro Wada пре 7 година
родитељ
комит
95c22cd59b
1 измењених фајлова са 17 додато и 13 уклоњено
  1. 17 13
      labelme/lib.py

+ 17 - 13
labelme/lib.py

@@ -1,4 +1,3 @@
-# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #
@@ -21,29 +20,32 @@
 from math import sqrt
 
 try:
-    from PyQt5.QtGui import *
-    from PyQt5.QtCore import *
-    from PyQt5.QtWidgets import *
+    from PyQt5 import QtCore
+    from PyQt5 import QtGui
+    from PyQt5 import QtWidgets
 except ImportError:
-    from PyQt4.QtGui import *
-    from PyQt4.QtCore import *
+    from PyQt4 import QtCore
+    from PyQt4 import QtGui
+    from PyQt4 import QtGui as QtWidgets
 
 
 def newIcon(icon):
-    return QIcon(':/' + icon)
+    return QtGui.QIcon(':/' + icon)
+
 
 def newButton(text, icon=None, slot=None):
-    b = QPushButton(text)
+    b = QtWidgets.QPushButton(text)
     if icon is not None:
         b.setIcon(newIcon(icon))
     if slot is not None:
         b.clicked.connect(slot)
     return b
 
+
 def newAction(parent, text, slot=None, shortcut=None, icon=None,
-        tip=None, checkable=False, enabled=True):
+              tip=None, checkable=False, enabled=True):
     """Create a new action and assign callbacks, shortcuts, etc."""
-    a = QAction(text, parent)
+    a = QtGui.QAction(text, parent)
     if icon is not None:
         a.setIcon(newIcon(icon))
     if shortcut is not None:
@@ -66,23 +68,25 @@ def addActions(widget, actions):
     for action in actions:
         if action is None:
             widget.addSeparator()
-        elif isinstance(action, QMenu):
+        elif isinstance(action, QtGui.QMenu):
             widget.addMenu(action)
         else:
             widget.addAction(action)
 
+
 def labelValidator():
-    return QRegExpValidator(QRegExp(r'^[^ \t].+'), None)
+    return QtGui.QRegExpValidator(QtCore.QRegExp(r'^[^ \t].+'), None)
 
 
 class struct(object):
     def __init__(self, **kwargs):
         self.__dict__.update(kwargs)
 
+
 def distance(p):
     return sqrt(p.x() * p.x() + p.y() * p.y())
 
+
 def fmtShortcut(text):
     mod, key = text.split('+', 1)
     return '<b>%s</b>+<b>%s</b>' % (mod, key)
-