diff --git a/pixelocr/glyphdb.py b/pixelocr/glyphdb.py index 3026ae3..0a4c147 100644 --- a/pixelocr/glyphdb.py +++ b/pixelocr/glyphdb.py @@ -36,6 +36,15 @@ class GlyphDB(object): def __delitem__(self, key): return self.data.__delitem__(key) + def keys(self): + return self.data.keys() + + def items(self): + return self.data.items() + + def values(self): + return self.data.values() + def save(self): with open(self.filename, 'wb') as fileobj: pickle.dump(self.data, fileobj) diff --git a/pixelocr/gui/glypheditor.py b/pixelocr/gui/glypheditor.py new file mode 100644 index 0000000..2380e24 --- /dev/null +++ b/pixelocr/gui/glypheditor.py @@ -0,0 +1,64 @@ +# Copyright (C) 2014 Andrey Golovizin +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import sys + +from PyQt4.QtCore import ( + Qt, + QAbstractTableModel, +) + +from PyQt4.QtGui import ( + QApplication, + QTableView, +) + +from ..glyphdb import GlyphDB + + +class GlyphDBModel(QAbstractTableModel): + def __init__(self, glyphdb, parent=None): + super().__init__(parent) + self.glyphdb = glyphdb + self.keys = list(glyphdb.keys()) + + def rowCount(self, parent): + return len(self.keys) + + def columnCount(self, parent): + return 1 + + def data(self, index, role): + if index.column() == 0: + if role == Qt.DisplayRole: + return self.glyphdb[self.keys[index.row()]] + + +def main(argv): + dirname = argv[1] + + app = QApplication(argv) + glyphdb = GlyphDB(dirname) + view = QTableView() + model = GlyphDBModel(glyphdb, parent=view) + view.setModel(model) + view.resize(640, 480) + view.show() + sys.exit(app.exec_()) + + +if __name__ == '__main__': + main(sys.argv)