diff --git a/examples/customrectitemconfig.py b/examples/customrectitemconfig.py index 0ca5c45..debc652 100644 --- a/examples/customrectitemconfig.py +++ b/examples/customrectitemconfig.py @@ -1,5 +1,5 @@ -from PyQt4.QtGui import QPen -from PyQt4.Qt import Qt +from PyQt5.QtGui import QPen +from PyQt5.Qt import Qt from sloth.items import RectItem diff --git a/setup.py b/setup.py index 5d09c4a..c1e1c88 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def fullsplit(path, result=None): description='The Sloth Labeling Tool', author='CV:HCI Research Group', url='http://sloth.readthedocs.org/', - requires=['importlib', 'PyQt4', 'numpy'], + requires=['importlib', 'PyQt5', 'numpy'], packages=packages, data_files=data_files, scripts=['sloth/bin/sloth'] diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index 6c0aff7..39a7a60 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -6,8 +6,9 @@ import logging import copy from collections import MutableMapping -from PyQt4.QtGui import QTreeView, QItemSelection, QItemSelectionModel, QSortFilterProxyModel, QBrush -from PyQt4.QtCore import QModelIndex, QAbstractItemModel, Qt, pyqtSignal, QVariant, QObject +from PyQt5.QtWidgets import QTreeView +from PyQt5.QtGui import QBrush +from PyQt5.QtCore import QModelIndex, QAbstractItemModel, QItemSelection, QItemSelectionModel, Qt, pyqtSignal, QVariant, QObject, QSortFilterProxyModel LOG = logging.getLogger(__name__) @@ -999,7 +1000,7 @@ def interpolateRange(self): for l in range(len(lann)): if lann[l]['type'] == fann[i]['type'] and lann[l]['class'] == fann[i]['class']: lannIdx = l - if lannIdx == None: + if lannIdx is None: LOG.error("Error: could not find matching label, skipping") continue diff --git a/sloth/bin/sloth b/sloth/bin/sloth index 4675050..e677755 100755 --- a/sloth/bin/sloth +++ b/sloth/bin/sloth @@ -2,7 +2,7 @@ import sys from os.path import dirname, realpath sys.path.insert(1, dirname(dirname(dirname(realpath(__file__))))) -from PyQt4.QtGui import QApplication +from PyQt5.QtWidgets import QApplication from sloth.core.labeltool import LabelTool from sloth import APP_NAME, ORGANIZATION_NAME, ORGANIZATION_DOMAIN diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 226bdfe..7d43182 100644 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -3,8 +3,9 @@ """ import os import sys -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * +from PyQt5.QtWidgets import * from sloth.annotations.model import * from sloth.annotations.container import AnnotationContainerFactory, AnnotationContainer from sloth.conf import config @@ -109,7 +110,7 @@ def execute_from_commandline(self, argv=None): format='%(asctime)s %(levelname)-8s %(name)-30s %(message)s') #, datefmt='%H:%M:%S.%m') # Disable PyQt log messages - logging.getLogger("PyQt4").setLevel(logging.WARNING) + logging.getLogger("PyQt5").setLevel(logging.WARNING) # Handle options common for all commands # and initialize the labeltool object from @@ -150,6 +151,7 @@ def execute_from_commandline(self, argv=None): else: # Setup GUI self._mainwindow = MainWindow(self) + self._mainwindow.doinit() self._mainwindow.show() # Load plugins @@ -448,4 +450,4 @@ def treeview(self): if self._mainwindow is None: return None else: - return self._mainwindow.treeview \ No newline at end of file + return self._mainwindow.treeview diff --git a/sloth/gui/buttonarea.py b/sloth/gui/buttonarea.py index d8863b8..178ddc2 100644 --- a/sloth/gui/buttonarea.py +++ b/sloth/gui/buttonarea.py @@ -1,6 +1,6 @@ import sys -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * from sloth.gui.floatinglayout import FloatingLayout import logging diff --git a/sloth/gui/controlbuttons.py b/sloth/gui/controlbuttons.py index 5ddb06b..2b23f52 100644 --- a/sloth/gui/controlbuttons.py +++ b/sloth/gui/controlbuttons.py @@ -1,6 +1,6 @@ -from PyQt4.QtGui import * -from PyQt4.QtCore import * - +from PyQt5.QtGui import * +from PyQt5.QtCore import * +from PyQt5.QtWidgets import * class Label(QLabel): diff --git a/sloth/gui/floatinglayout.py b/sloth/gui/floatinglayout.py index b64629a..843324c 100644 --- a/sloth/gui/floatinglayout.py +++ b/sloth/gui/floatinglayout.py @@ -1,5 +1,5 @@ -from PyQt4.QtCore import Qt, QRect, QSize, QPoint -from PyQt4.QtGui import QLayout, QSizePolicy, QWidgetItem +from PyQt5.QtCore import Qt, QRect, QSize, QPoint +from PyQt5.QtWidgets import QLayout, QSizePolicy, QWidgetItem class FloatingLayout(QLayout): diff --git a/sloth/gui/frameviewer.py b/sloth/gui/frameviewer.py index 8c85e8c..8aeb5c3 100644 --- a/sloth/gui/frameviewer.py +++ b/sloth/gui/frameviewer.py @@ -1,6 +1,7 @@ import math -from PyQt4.QtCore import * -from PyQt4.QtGui import * +from PyQt5.QtCore import * +from PyQt5.QtWidgets import * +from PyQt5.QtGui import * try: import okapy.videoio except ImportError: @@ -96,7 +97,7 @@ def setScaleRelative(self, factor): self.setScaleAbsolute(self.getScale() * factor) def wheelEvent(self, event): - factor = 1.41 ** (event.delta() / 240.0) + factor = 1.41 ** (event.angleDelta().y() / 240.0) self.setScaleRelative(factor) def focusInEvent(self, event): diff --git a/sloth/gui/labeltool.py b/sloth/gui/labeltool.py index 29f2fc1..3c81e6b 100644 --- a/sloth/gui/labeltool.py +++ b/sloth/gui/labeltool.py @@ -2,11 +2,12 @@ import logging, os import functools import fnmatch -from PyQt4.QtGui import QMainWindow, QSizePolicy, QWidget, QVBoxLayout, QAction,\ - QKeySequence, QLabel, QItemSelectionModel, QMessageBox, QFileDialog, QFrame, \ +from PyQt5.QtWidgets import QMainWindow, QSizePolicy, QWidget, QVBoxLayout, QAction,\ + QLabel, QMessageBox, QFileDialog, QFrame, \ QDockWidget, QProgressBar, QProgressDialog -from PyQt4.QtCore import SIGNAL, QSettings, QSize, QPoint, QVariant, QFileInfo, QTimer, pyqtSignal, QObject -import PyQt4.uic as uic +from PyQt5.QtGui import QKeySequence +from PyQt5.QtCore import QSettings, QSize, QPoint, QVariant, QFileInfo, QTimer, pyqtSignal, QObject, QItemSelectionModel +import PyQt5.uic as uic from sloth.gui import qrc_icons # needed for toolbar icons from sloth.gui.propertyeditor import PropertyEditor from sloth.gui.annotationscene import AnnotationScene @@ -70,6 +71,8 @@ def __init__(self, labeltool, parent=None): self.loader = None self.labeltool = labeltool + + def doinit(self): self.setupGui() self.loadApplicationSettings() self.onAnnotationsLoaded() @@ -129,7 +132,7 @@ def onCurrentImageChanged(self): img = self.labeltool.getImage(new_image) - if img == None: + if img is None: self.controls.setFilename("") self.selectionmodel.setCurrentIndex(new_image.index(), QItemSelectionModel.ClearAndSelect|QItemSelectionModel.Rows) return @@ -399,7 +402,7 @@ def fileOpen(self): format_str = ' '.join(self.labeltool.getAnnotationFilePatterns()) fname = QFileDialog.getOpenFileName(self, "%s - Load Annotations" % APP_NAME, path, - "%s annotation files (%s)" % (APP_NAME, format_str)) + "%s annotation files (%s)" % (APP_NAME, format_str))[0] if len(str(fname)) > 0: self.labeltool.loadAnnotations(fname) @@ -414,7 +417,7 @@ def fileSaveAs(self): format_str = ' '.join(self.labeltool.getAnnotationFilePatterns()) fname = QFileDialog.getSaveFileName(self, "%s - Save Annotations" % APP_NAME, fname, - "%s annotation files (%s)" % (APP_NAME, format_str)) + "%s annotation files (%s)" % (APP_NAME, format_str))[0] if len(str(fname)) > 0: return self.labeltool.saveAnnotations(str(fname)) @@ -429,7 +432,7 @@ def addMediaFile(self): image_types = [ '*.jpg', '*.bmp', '*.png', '*.pgm', '*.ppm', '*.tiff', '*.tif', '*.gif' ] video_types = [ '*.mp4', '*.mpg', '*.mpeg', '*.avi', '*.mov', '*.vob' ] format_str = ' '.join(image_types + video_types) - fnames = QFileDialog.getOpenFileNames(self, "%s - Add Media File" % APP_NAME, path, "Media files (%s)" % (format_str, )) + fnames = QFileDialog.getOpenFileNames(self, "%s - Add Media File" % APP_NAME, path, "Media files (%s)" % (format_str, ))[0] item = None numFiles = len(fnames) diff --git a/sloth/gui/propertyeditor.py b/sloth/gui/propertyeditor.py index b3b80db..fe921df 100644 --- a/sloth/gui/propertyeditor.py +++ b/sloth/gui/propertyeditor.py @@ -1,7 +1,8 @@ import time import logging -from PyQt4.QtCore import pyqtSignal, QSize, Qt -from PyQt4.QtGui import QWidget, QGroupBox, QVBoxLayout, QPushButton, QScrollArea, QLineEdit, QDoubleValidator, QIntValidator, QShortcut, QKeySequence +from PyQt5.QtCore import pyqtSignal, QSize, Qt +from PyQt5.QtWidgets import QWidget, QGroupBox, QVBoxLayout, QPushButton, QScrollArea, QLineEdit, QShortcut +from PyQt5.QtGui import QDoubleValidator, QIntValidator, QKeySequence from sloth.core.exceptions import ImproperlyConfigured from sloth.annotations.model import AnnotationModelItem from sloth.gui.floatinglayout import FloatingLayout diff --git a/sloth/gui/qrc_icons.py b/sloth/gui/qrc_icons.py index e35b501..f2ab3cd 100644 --- a/sloth/gui/qrc_icons.py +++ b/sloth/gui/qrc_icons.py @@ -7,7 +7,7 @@ # # WARNING! All changes made in this file will be lost! -from PyQt4 import QtCore +from PyQt5 import QtCore qt_resource_data = b"\ \x00\x00\x02\xb3\ diff --git a/sloth/gui/utils.py b/sloth/gui/utils.py index 28c8f93..339e1b2 100644 --- a/sloth/gui/utils.py +++ b/sloth/gui/utils.py @@ -1,5 +1,5 @@ -from PyQt4.QtCore import QSize -from PyQt4.QtGui import QVBoxLayout +from PyQt5.QtCore import QSize +from PyQt5.QtWidgets import QVBoxLayout # This is really really ugly, but the QDockWidget for some reason does not notice when diff --git a/sloth/items/inserters.py b/sloth/items/inserters.py index 371c2a4..014c554 100644 --- a/sloth/items/inserters.py +++ b/sloth/items/inserters.py @@ -1,6 +1,6 @@ import math -from PyQt4.QtGui import * -from PyQt4.Qt import * +from PyQt5.QtGui import * +from PyQt5.Qt import * class ItemInserter(QObject): diff --git a/sloth/items/items.py b/sloth/items/items.py index 2b41bc3..66e56af 100644 --- a/sloth/items/items.py +++ b/sloth/items/items.py @@ -1,5 +1,5 @@ import logging -from PyQt4.Qt import * +from PyQt5.Qt import * LOG = logging.getLogger(__name__) diff --git a/sloth/plugins/__init__.py b/sloth/plugins/__init__.py index 52ce4a9..46fbd24 100644 --- a/sloth/plugins/__init__.py +++ b/sloth/plugins/__init__.py @@ -1,5 +1,5 @@ -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * import logging diff --git a/sloth/plugins/facedetector.py b/sloth/plugins/facedetector.py index eddefef..708e9f2 100644 --- a/sloth/plugins/facedetector.py +++ b/sloth/plugins/facedetector.py @@ -1,5 +1,5 @@ -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * from sloth.annotations.model import ImageModelItem from okapy import BinaryPatternFaceDetector diff --git a/sloth/utils/__init__.py b/sloth/utils/__init__.py index 09e5d33..410b781 100644 --- a/sloth/utils/__init__.py +++ b/sloth/utils/__init__.py @@ -1,7 +1,7 @@ import numpy as np import random import colorsys -from PyQt4.QtGui import QImage, qRgb +from PyQt5.QtGui import QImage, qRgb from sloth.core.exceptions import NotImplementedException diff --git a/tests/model_test.py b/tests/model_test.py index 7d0158b..77c1995 100644 --- a/tests/model_test.py +++ b/tests/model_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import os, sys -from PyQt4.QtGui import QApplication +from PyQt5.QtWidgets import QApplication from sloth.gui import MainWindow from sloth.core.labeltool import LabelTool from sloth import APP_NAME, ORGANIZATION_NAME, ORGANIZATION_DOMAIN diff --git a/tests/pymodeltest/modeltest.py b/tests/pymodeltest/modeltest.py index 2f18fbf..f943993 100644 --- a/tests/pymodeltest/modeltest.py +++ b/tests/pymodeltest/modeltest.py @@ -22,7 +22,7 @@ ############################################################################# import sip -from PyQt4 import QtCore, QtGui +from PyQt5 import QtCore, QtGui class ModelTest(QtCore.QObject):