Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*- coding: utf-8 -*-
- import os
- import sys
- # Python versions before 3.0 do not use UTF-8 encoding
- # by default. To ensure that Unicode is handled properly
- # throughout the program, we will set the default encoding
- # ourselves to UTF-8.
- reload(sys)
- sys.setdefaultencoding('utf-8')
- from PyQt4 import QtGui
- from PyQt4 import QtCore
- from PyQt4 import uic
- class TransposeProxyModel(QtGui.QAbstractProxyModel):
- def __init__(self, *argv):
- super(TransposeProxyModel, self).__init__(*argv)
- def mapFromSource (self, sourceIndex):
- return self.index(sourceIndex.column(), sourceIndex.row())
- def mapToSource (self, proxyIndex):
- return self.sourceModel().index(proxyIndex.column(), proxyIndex.row())
- def index (self, row, column, parent=QtCore.QModelIndex()):
- index = self.createIndex(row, column)
- print index.isValid()
- return index
- def parent(self, childIndex):
- return QtCore.QModelIndex()
- # def flags(self, index):
- # return self.sourceModel().flags(self.mapToSource(index))
- def rowCount(self, parent=QtCore.QModelIndex()):
- return self.sourceModel().columnCount()
- def columnCount(self, parent=QtCore.QModelIndex()):
- return self.sourceModel().rowCount()
- def data(self, index, role):
- return self.sourceModel().data(self.mapToSource(index), role)
- class PyQtApp(QtGui.QApplication):
- def __init__(self, *argv):
- super(PyQtApp, self).__init__(*argv)
- self.ui = QtGui.QMainWindow()
- uic.loadUi('window.ui', self.ui)
- # models
- self.mBase = QtGui.QStandardItemModel()
- self.mTransponsed = TransposeProxyModel()
- # self.mTransponsed = QtGui.QSortFilterProxyModel()
- self.mTransponsed.setSourceModel(self.mBase)
- # widgets
- self.ui.baseView.setModel(self.mBase)
- self.ui.tableView.setModel(self.mBase)
- self.ui.transponsedView.setModel(self.mTransponsed)
- self.ui.loadButton.clicked.connect(self.on_loadButton_clicked)
- def run (self):
- self.ui.show()
- self.exec_()
- def on_loadButton_clicked(self):
- attributes = {'1st': '1val', '2nd': '2val'}
- for attr in attributes:
- item = QtGui.QStandardItem(attr)
- self.mBase.appendRow(item)
- if __name__ == '__main__':
- i = PyQtApp(sys.argv)
- i.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement