提交 eecf0eac 编写于 作者: K Kentaro Wada

Use qtpy to abstract Qt python binding

上级 b99cd0c6
......@@ -6,18 +6,11 @@ import re
import subprocess
import sys
try:
from PyQt5 import QtCore
from PyQt5.QtCore import Qt
from PyQt5 import QtGui
from PyQt5 import QtWidgets
PYQT5 = True
except ImportError:
from PyQt4 import QtCore
from PyQt4.QtCore import Qt
from PyQt4 import QtGui
from PyQt4 import QtGui as QtWidgets
PYQT5 = False
from qtpy import PYQT5
from qtpy import QtCore
from qtpy.QtCore import Qt
from qtpy import QtGui
from qtpy import QtWidgets
from labelme.canvas import Canvas
from labelme.colorDialog import ColorDialog
......@@ -979,7 +972,7 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
filename = QtWidgets.QFileDialog.getOpenFileName(
self, '%s - Choose Image or Label file' % __appname__,
path, filters)
if PYQT5:
if qtpy.PYQT5:
filename, _ = filename
filename = str(filename)
if filename:
......@@ -1015,7 +1008,7 @@ class MainWindow(QtWidgets.QMainWindow, WindowMixin):
filename = dlg.getSaveFileName(
self, 'Choose File', default_labelfile_name,
'Label files (*%s)' % LabelFile.suffix)
if PYQT5:
if qtpy.PYQT5:
filename, _ = filename
filename = str(filename)
return filename
......
......@@ -2,16 +2,10 @@ from __future__ import print_function
import sys
try:
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
PYQT5 = True
except ImportError:
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtGui as QtWidgets
PYQT5 = False
from qtpy import PYQT5
from qtpy import QtCore
from qtpy import QtGui
from qtpy import QtWidgets
from labelme.lib import distance
from labelme.shape import Shape
......@@ -29,12 +23,12 @@ CURSOR_GRAB = QtCore.Qt.OpenHandCursor
class Canvas(QtWidgets.QWidget):
zoomRequest = QtCore.pyqtSignal(int, QtCore.QPoint)
scrollRequest = QtCore.pyqtSignal(int, int)
newShape = QtCore.pyqtSignal()
selectionChanged = QtCore.pyqtSignal(bool)
shapeMoved = QtCore.pyqtSignal()
drawingPolygon = QtCore.pyqtSignal(bool)
zoomRequest = QtCore.Signal(int, QtCore.QPoint)
scrollRequest = QtCore.Signal(int, int)
newShape = QtCore.Signal()
selectionChanged = QtCore.Signal(bool)
shapeMoved = QtCore.Signal()
drawingPolygon = QtCore.Signal(bool)
CREATE, EDIT = 0, 1
......
try:
from PyQt5 import QtWidgets
except ImportError:
from PyQt4 import QtGui as QtWidgets
from qtpy import QtWidgets
class ColorDialog(QtWidgets.QColorDialog):
......
try:
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
PYQT5 = True
except ImportError:
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtGui as QtWidgets
PYQT5 = False
from qtpy import PYQT5
from qtpy import QtCore
from qtpy import QtGui
from qtpy import QtWidgets
from .lib import labelValidator
from .lib import newIcon
......
from math import sqrt
import os.path as osp
try:
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
except ImportError:
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtGui as QtWidgets
from qtpy import QtCore
from qtpy import QtGui
from qtpy import QtWidgets
here = osp.dirname(osp.abspath(__file__))
......
try:
from PyQt5 import QtGui
except ImportError:
from PyQt4 import QtGui
from qtpy import QtGui
from .lib import distance
......
try:
from PyQt5 import QtCore
from PyQt5 import QtWidgets
except ImportError:
from PyQt4 import QtCore
from PyQt4 import QtGui as QtWidgets
from qtpy import QtCore
from qtpy import QtWidgets
class ToolBar(QtWidgets.QToolBar):
......
try:
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
except ImportError:
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtGui as QtWidgets
from qtpy import QtCore
from qtpy import QtGui
from qtpy import QtWidgets
class ZoomWidget(QtWidgets.QSpinBox):
......
......@@ -18,6 +18,7 @@ install_requires = [
'numpy',
'Pillow>=2.8.0',
'PyYAML',
'qtpy',
]
......
try:
from PyQt5 import QtCore
from PyQt5 import QtWidgets
except ImportError:
from PyQt4 import QtCore
from PyQt4 import QtGui as QtWidgets
from qtpy import QtCore
from qtpy import QtWidgets
from labelme import labelDialog
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册