mirror of
https://github.com/wassname/sloth.git
synced 2026-08-11 11:26:22 +08:00
pep8 fixes
This commit is contained in:
+16
-11
@@ -1,23 +1,25 @@
|
|||||||
"""
|
"""
|
||||||
The annotationmodel module contains the classes for the AnnotationModel.
|
The annotationmodel module contains the classes for the AnnotationModel.
|
||||||
"""
|
"""
|
||||||
from PyQt4.QtGui import QTreeView, QItemSelection, QItemSelectionModel, QSortFilterProxyModel, QBrush
|
import os.path
|
||||||
from PyQt4.QtCore import QModelIndex, QAbstractItemModel, Qt, pyqtSignal, QVariant
|
|
||||||
import os.path, sys
|
|
||||||
import copy
|
|
||||||
from collections import MutableMapping
|
|
||||||
import time
|
import time
|
||||||
import logging
|
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
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
ItemRole, DataRole, ImageRole = [Qt.UserRole + i + 1 for i in range(3)]
|
ItemRole, DataRole, ImageRole = [Qt.UserRole + i + 1 for i in range(3)]
|
||||||
|
|
||||||
|
|
||||||
class ModelItem:
|
class ModelItem:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._loaded = True
|
self._loaded = True
|
||||||
self._model = None
|
self._model = None
|
||||||
self._parent = None
|
self._parent = None
|
||||||
self._row = -1
|
self._row = -1
|
||||||
if not hasattr(self, "_children"):
|
if not hasattr(self, "_children"):
|
||||||
self._children = []
|
self._children = []
|
||||||
|
|
||||||
@@ -579,18 +581,21 @@ class KeyValueRowModelItem(ModelItem):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class AnnotationModel(QAbstractItemModel):
|
class AnnotationModel(QAbstractItemModel):
|
||||||
# signals
|
# signals
|
||||||
dirtyChanged = pyqtSignal(bool, name='dirtyChanged')
|
dirtyChanged = pyqtSignal(bool, name='dirtyChanged')
|
||||||
|
|
||||||
def __init__(self, annotations, parent=None):
|
def __init__(self, annotations, parent=None):
|
||||||
QAbstractItemModel.__init__(self, parent)
|
QAbstractItemModel.__init__(self, parent)
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
self._annotations = annotations
|
self._annotations = annotations
|
||||||
self._dirty = False
|
self._dirty = False
|
||||||
self._root = RootModelItem(self, annotations)
|
self._root = RootModelItem(self, annotations)
|
||||||
diff = time.time() - start
|
diff = time.time() - start
|
||||||
LOG.info("Created AnnotationModel in %.2fs" % (diff, ))
|
LOG.info("Created AnnotationModel in %.2fs" % (diff, ))
|
||||||
|
|
||||||
self.dataChanged.connect(self.onDataChanged)
|
self.dataChanged.connect(self.onDataChanged)
|
||||||
self.rowsInserted.connect(self.onDataChanged)
|
self.rowsInserted.connect(self.onDataChanged)
|
||||||
self.rowsRemoved.connect(self.onDataChanged)
|
self.rowsRemoved.connect(self.onDataChanged)
|
||||||
|
|||||||
+22
-12
@@ -1,24 +1,31 @@
|
|||||||
|
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 sloth.core.exceptions import ImproperlyConfigured
|
from sloth.core.exceptions import ImproperlyConfigured
|
||||||
from sloth.annotations.model import AnnotationModelItem
|
from sloth.annotations.model import AnnotationModelItem
|
||||||
from sloth.gui.floatinglayout import FloatingLayout
|
from sloth.gui.floatinglayout import FloatingLayout
|
||||||
from sloth.gui.utils import MyVBoxLayout
|
from sloth.gui.utils import MyVBoxLayout
|
||||||
from sloth.utils.bind import bind
|
from sloth.utils.bind import bind
|
||||||
from PyQt4.QtCore import pyqtSignal, QSize, Qt
|
|
||||||
from PyQt4.QtGui import QWidget, QGroupBox, QVBoxLayout, QPushButton, QScrollArea, QLineEdit, QDoubleValidator, QIntValidator, QShortcut, QKeySequence
|
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AbstractAttributeHandler:
|
class AbstractAttributeHandler:
|
||||||
def defaults(self):
|
def defaults(self):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def updateValues(self, values):
|
def updateValues(self, values):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setItems(self, items, showItemClasses=False):
|
def setItems(self, items, showItemClasses=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def autoAddEnabled(self):
|
def autoAddEnabled(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class AttributeHandlerFactory:
|
class AttributeHandlerFactory:
|
||||||
def create(self, attribute, values):
|
def create(self, attribute, values):
|
||||||
# Class attribute cannot be changed
|
# Class attribute cannot be changed
|
||||||
@@ -36,17 +43,18 @@ class AttributeHandlerFactory:
|
|||||||
# Else, we create our own default handler
|
# Else, we create our own default handler
|
||||||
return DefaultAttributeHandler(attribute, values)
|
return DefaultAttributeHandler(attribute, values)
|
||||||
|
|
||||||
|
|
||||||
class DefaultAttributeHandler(QGroupBox, AbstractAttributeHandler):
|
class DefaultAttributeHandler(QGroupBox, AbstractAttributeHandler):
|
||||||
def __init__(self, attribute, values, parent=None):
|
def __init__(self, attribute, values, parent=None):
|
||||||
QGroupBox.__init__(self, attribute, parent)
|
QGroupBox.__init__(self, attribute, parent)
|
||||||
self._attribute = attribute
|
self._attribute = attribute
|
||||||
self._current_items = []
|
self._current_items = []
|
||||||
self._defaults = {}
|
self._defaults = {}
|
||||||
self._inputField = None
|
self._inputField = None
|
||||||
self._inputFieldType = None
|
self._inputFieldType = None
|
||||||
self._insertIndex = -1
|
self._insertIndex = -1
|
||||||
self._insertAtEnd = False
|
self._insertAtEnd = False
|
||||||
self._shortcuts = {}
|
self._shortcuts = {}
|
||||||
|
|
||||||
# Setup GUI
|
# Setup GUI
|
||||||
self._layout = FloatingLayout()
|
self._layout = FloatingLayout()
|
||||||
@@ -257,7 +265,8 @@ class LabelEditor(QScrollArea):
|
|||||||
handler = self._editor.getHandler(attr)
|
handler = self._editor.getHandler(attr)
|
||||||
if handler is not None:
|
if handler is not None:
|
||||||
if len(items) > 1:
|
if len(items) > 1:
|
||||||
valid_items = [item for item in items if attr in self._editor.getLabelClassAttributes(item['class'])]
|
valid_items = [item for item in items
|
||||||
|
if attr in self._editor.getLabelClassAttributes(item['class'])]
|
||||||
handler.setItems(valid_items, True)
|
handler.setItems(valid_items, True)
|
||||||
else:
|
else:
|
||||||
handler.setItems(items)
|
handler.setItems(items)
|
||||||
@@ -285,6 +294,7 @@ class LabelEditor(QScrollArea):
|
|||||||
def insertionMode(self):
|
def insertionMode(self):
|
||||||
return self._insertion_mode
|
return self._insertion_mode
|
||||||
|
|
||||||
|
|
||||||
class PropertyEditor(QWidget):
|
class PropertyEditor(QWidget):
|
||||||
# Signals
|
# Signals
|
||||||
insertionModeStarted = pyqtSignal(str)
|
insertionModeStarted = pyqtSignal(str)
|
||||||
|
|||||||
Reference in New Issue
Block a user