Display glyph images in the glyph editor.
This commit is contained in:
parent
08e4382b66
commit
cf8575152e
1 changed files with 19 additions and 1 deletions
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
from PyQt4.QtCore import (
|
||||
Qt,
|
||||
|
|
@ -27,6 +28,7 @@ from PyQt4.QtGui import (
|
|||
)
|
||||
|
||||
from ..glyphdb import GlyphDB
|
||||
from ..image import Image
|
||||
|
||||
|
||||
class GlyphDBModel(QAbstractTableModel):
|
||||
|
|
@ -34,6 +36,7 @@ class GlyphDBModel(QAbstractTableModel):
|
|||
super().__init__(parent)
|
||||
self.glyphdb = glyphdb
|
||||
self.keys = list(glyphdb.keys())
|
||||
self.images = {}
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self.keys)
|
||||
|
|
@ -41,10 +44,25 @@ class GlyphDBModel(QAbstractTableModel):
|
|||
def columnCount(self, parent):
|
||||
return 1
|
||||
|
||||
def _deserialize_image(self, key):
|
||||
elevation_, serialized_image = key
|
||||
return Image.deserialize(serialized_image).toqimage()
|
||||
|
||||
def get_image(self, key):
|
||||
try:
|
||||
image = self.images[key]
|
||||
except KeyError:
|
||||
image = self._deserialize_image(key)
|
||||
self.images[key] = image
|
||||
return image
|
||||
|
||||
def data(self, index, role):
|
||||
if index.column() == 0:
|
||||
key = self.keys[index.row()]
|
||||
if role == Qt.DisplayRole:
|
||||
return self.glyphdb[self.keys[index.row()]]
|
||||
return self.glyphdb[key]
|
||||
elif role == Qt.DecorationRole:
|
||||
return self.get_image(key)
|
||||
|
||||
|
||||
def main(argv):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue