This commit is contained in:
Martin Baeuml
2014-03-19 14:53:47 +01:00
parent a811b9cccf
commit 1c0387a192
2 changed files with 24 additions and 7 deletions
+18 -7
View File
@@ -11,7 +11,7 @@ from PyQt4.QtCore import QModelIndex, QAbstractItemModel, Qt, pyqtSignal, QVaria
LOG = logging.getLogger(__name__)
ItemRole, DataRole, ImageRole = [Qt.UserRole + i + 1 for i in range(3)]
ItemRole, DataRole, ImageRole = [Qt.UserRole + ur + 1 for ur in range(3)]
class ModelItem:
@@ -172,7 +172,7 @@ class ModelItem:
for i, item in enumerate(items):
item._parent = self
item._row = next_row + i
item._row = next_row + i
self._children.append(item)
if self._model is not None:
@@ -221,11 +221,12 @@ class ModelItem:
def getColor(self):
return None
class RootModelItem(ModelItem):
def __init__(self, model, files):
ModelItem.__init__(self)
self._model = model
self._toload = []
self._toload = []
for f in files:
self._toload.append(f)
self._children.append(f)
@@ -251,9 +252,9 @@ class RootModelItem(ModelItem):
else:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
def appendChild(self, item):
def appendChild(self, item, signalModel=True):
if isinstance(item, FileModelItem):
ModelItem.appendChild(self, item)
ModelItem.appendChild(self, item, signalModel=signalModel)
else:
raise TypeError("Only FileModelItems can be attached to RootModelItem")
@@ -285,6 +286,7 @@ class RootModelItem(ModelItem):
return [child.getAnnotations() for child in self.children()
if hasattr(child, 'getAnnotations')]
class KeyValueModelItem(ModelItem, MutableMapping):
def __init__(self, hidden=None, properties=None):
ModelItem.__init__(self)
@@ -397,6 +399,7 @@ class KeyValueModelItem(ModelItem, MutableMapping):
del self['unconfirmed']
self._emitDataChanged('unconfirmed')
class FileModelItem(KeyValueModelItem):
def __init__(self, fileinfo, hidden=None):
if not hidden: hidden = ['filename']
@@ -422,6 +425,7 @@ class FileModelItem(KeyValueModelItem):
elif fileinfo['class'] == 'video':
return VideoFileModelItem(fileinfo)
class ImageModelItem(ModelItem):
def __init__(self, annotations):
ModelItem.__init__(self)
@@ -440,6 +444,7 @@ class ImageModelItem(ModelItem):
for ann in self.annotations():
ann.setUnconfirmed(False)
class ImageFileModelItem(FileModelItem, ImageModelItem):
def __init__(self, fileinfo):
self._annotation_data = fileinfo.get("annotations", [])
@@ -472,6 +477,7 @@ class ImageFileModelItem(FileModelItem, ImageModelItem):
if hasattr(child, 'getAnnotations')]
return fi
class VideoFileModelItem(FileModelItem):
def __init__(self, fileinfo):
frameinfos = fileinfo.get("frames", [])
@@ -488,6 +494,7 @@ class VideoFileModelItem(FileModelItem):
fi['frames'] = [child.getAnnotations() for child in self.children()]
return fi
class FrameModelItem(ImageModelItem, KeyValueModelItem):
def __init__(self, frameinfo):
annotations = frameinfo.get("annotations", [])
@@ -521,6 +528,7 @@ class FrameModelItem(ImageModelItem, KeyValueModelItem):
if hasattr(child, 'getAnnotations')]
return fi
class AnnotationModelItem(KeyValueModelItem):
def __init__(self, annotation):
KeyValueModelItem.__init__(self, properties=annotation)
@@ -547,6 +555,7 @@ class AnnotationModelItem(KeyValueModelItem):
return Qt.red
return None
class KeyValueRowModelItem(ModelItem):
def __init__(self, key, read_only=True):
ModelItem.__init__(self)
@@ -668,8 +677,10 @@ class AnnotationModel(QAbstractItemModel):
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
if section == 0: return "File/Type/Key"
elif section == 1: return "Value"
if section == 0:
return "File/Type/Key"
elif section == 1:
return "Value"
return None
# Own methods
+6
View File
@@ -3,8 +3,10 @@ from PyQt4.QtGui import *
from PyQt4.QtCore import *
from sloth.gui.floatinglayout import FloatingLayout
import logging
LOG = logging.getLogger(__name__)
def unique_list(seq):
seen = {}
result = []
@@ -14,6 +16,7 @@ def unique_list(seq):
result.append(item)
return result
class ButtonListWidget(QGroupBox):
selectionChanged = pyqtSignal(object)
@@ -196,8 +199,10 @@ class ButtonArea(QWidget):
if button is not None:
self.label_button_list.toggleChecked(button)
def main():
from conf import config
config.update("example_config")
app = QApplication(sys.argv)
@@ -206,6 +211,7 @@ def main():
return app.exec_()
if __name__ == '__main__':
sys.exit(main())