mirror of
https://github.com/wassname/sloth.git
synced 2026-07-23 13:10:07 +08:00
More Python 3 fixes (mostly for Python 3 version of PyQt)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
The annotationmodel module contains the classes for the AnnotationModel.
|
||||
"""
|
||||
from PyQt4.QtGui import QTreeView, QItemSelection, QItemSelectionModel, QSortFilterProxyModel
|
||||
from PyQt4.QtCore import QModelIndex, QAbstractItemModel, QVariant, Qt, pyqtSignal
|
||||
from PyQt4.QtCore import QModelIndex, QAbstractItemModel, Qt, pyqtSignal
|
||||
import os.path
|
||||
import copy
|
||||
from collections import MutableMapping
|
||||
@@ -34,7 +34,7 @@ class ModelItem:
|
||||
if role == Qt.DisplayRole:
|
||||
return ""
|
||||
if role == ItemRole:
|
||||
return QVariant(self)
|
||||
return self
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -271,7 +271,7 @@ class ImageModelItem(ModelItem):
|
||||
if child.type() == ann['type']:
|
||||
if ('id' in child and 'id' in ann and child['id'] == ann['id']) or ('id' not in child and 'id' not in ann):
|
||||
ann[None] = None
|
||||
child.setData(QVariant(ann), DataRole, 1)
|
||||
child.setData(ann, DataRole, 1)
|
||||
return
|
||||
raise Exception("No AnnotationModelItem found that could be updated!")
|
||||
|
||||
@@ -367,9 +367,9 @@ class KeyValueRowModelItem(ModelItem):
|
||||
if column == 0:
|
||||
return self._key
|
||||
elif column == 1:
|
||||
return QVariant(self.parent()[self._key])
|
||||
return self.parent()[self._key]
|
||||
else:
|
||||
return QVariant()
|
||||
return None
|
||||
else:
|
||||
return ModelItem.data(self, role, column)
|
||||
|
||||
@@ -436,7 +436,7 @@ class AnnotationModel(QAbstractItemModel):
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
if not index.isValid():
|
||||
return QVariant()
|
||||
return None
|
||||
item = self.itemFromIndex(index)
|
||||
return item.data(role, index.column())
|
||||
|
||||
@@ -454,9 +454,9 @@ class AnnotationModel(QAbstractItemModel):
|
||||
|
||||
def headerData(self, section, orientation, role):
|
||||
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
|
||||
if section == 0: return QVariant("File/Type/Key")
|
||||
elif section == 1: return QVariant("Value")
|
||||
return QVariant()
|
||||
if section == 0: return "File/Type/Key"
|
||||
elif section == 1: return "Value"
|
||||
return None
|
||||
|
||||
# Own methods
|
||||
def root(self):
|
||||
|
||||
@@ -40,7 +40,7 @@ class LabelTool(QObject):
|
||||
"Type '%s help <subcommand>' for help on a specific subcommand.\n\n"
|
||||
|
||||
# Signals
|
||||
statusMessage = pyqtSignal(QString)
|
||||
statusMessage = pyqtSignal(str)
|
||||
annotationsLoaded = pyqtSignal()
|
||||
pluginLoaded = pyqtSignal(QAction)
|
||||
# This still emits a QModelIndex, because Qt cannot handle emiting
|
||||
|
||||
@@ -106,7 +106,7 @@ class AnnotationScene(QGraphicsScene):
|
||||
# create a graphics item for each model index
|
||||
for row in range(first, last+1):
|
||||
child = self.root_.child(row, 0) # get index
|
||||
_type = str(child.data(TypeRole).toPyObject()) # get type from index
|
||||
_type = str(child.data(TypeRole)) # get type from index
|
||||
item = self.itemfactory_.create(_type, self.model_.itemFromIndex(child)) # create graphics item from factory
|
||||
if item is not None:
|
||||
self.addItem(item)
|
||||
|
||||
+14
-8
@@ -179,19 +179,25 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def loadApplicationSettings(self):
|
||||
settings = QSettings()
|
||||
self.resize(settings.value("MainWindow/Size", QVariant(QSize(800, 600))).toSize())
|
||||
self.move(settings.value("MainWindow/Position", QVariant(QPoint(10, 10))).toPoint())
|
||||
self.restoreState(settings.value("MainWindow/State").toByteArray())
|
||||
size = settings.value("MainWindow/Size", QSize(800, 600))
|
||||
pos = settings.value("MainWindow/Position", QPoint(10, 10))
|
||||
state = settings.value("MainWindow/State")
|
||||
if isinstance(size, QVariant): size = size.toSize()
|
||||
if isinstance(pos, QVariant): pos = pos.toPoint()
|
||||
if isinstance(state, QVariant): state = state.toByteArray()
|
||||
self.resize(size)
|
||||
self.move(pos)
|
||||
self.restoreState(state)
|
||||
|
||||
def saveApplicationSettings(self):
|
||||
settings = QSettings()
|
||||
settings.setValue("MainWindow/Size", QVariant(self.size()))
|
||||
settings.setValue("MainWindow/Position", QVariant(self.pos()))
|
||||
settings.setValue("MainWindow/State", QVariant(self.saveState()))
|
||||
settings.setValue("MainWindow/Size", self.size())
|
||||
settings.setValue("MainWindow/Position", self.pos())
|
||||
settings.setValue("MainWindow/State", self.saveState())
|
||||
if self.labeltool.getCurrentFilename() is not None:
|
||||
filename = QVariant(QString(self.labeltool.getCurrentFilename()))
|
||||
filename = self.labeltool.getCurrentFilename()
|
||||
else:
|
||||
filename = QVariant()
|
||||
filename = None
|
||||
settings.setValue("LastFile", filename)
|
||||
|
||||
def okToContinue(self):
|
||||
|
||||
Reference in New Issue
Block a user