Add GLyphDBEditor (actually a viewer for now).

This commit is contained in:
Andrey Golovizin 2014-08-21 22:47:57 +02:00
parent 182a49b359
commit c32415d843
2 changed files with 73 additions and 0 deletions

View file

@ -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)

View file

@ -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 <http://www.gnu.org/licenses/>.
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)