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