Skip to content
Snippets Groups Projects
Commit 8ae81db9 authored by Marco Biasini's avatar Marco Biasini
Browse files

added GUI table class

parent 2f3da810
Branches
Tags
Loading
......@@ -85,6 +85,7 @@ set(OST_GUI_PYMOD_MODULES
init_splash.py
traj.py
helpwidget.py
table.py
)
set(OST_GUI_PYMOD_DNG_MODULES
......
from PyQt4.QtGui import *
from PyQt4.QtCore import *
__all__=('Table', )
class TableModel(QAbstractTableModel):
def __init__(self, table, parent=None):
QAbstractTableModel.__init__(self, parent)
self.table=table
def rowCount(self, index):
return len(self.table.rows)
def headerData(self, section, orientation, role):
if role!=Qt.DisplayRole or orientation!=Qt.Horizontal:
return QVariant()
return self.table.col_names[section]
def columnCount(self, index):
return len(self.table.col_names)
def sort(self, column, order):
o='+'
if order!=Qt.AscendingOrder:
o='-'
self.table.Sort(by=self.table.col_names[column], order=o)
self.reset()
def data(self, index, role):
if not index.isValid() or role!=Qt.DisplayRole:
return QVariant()
row=self.table.rows[index.row()]
return QVariant(row[index.column()])
class Table(QTableView):
def __init__(self, table):
QTableView.__init__(self)
self._model=TableModel(table)
self.setFrameShape(QFrame.NoFrame)
self.setAttribute(Qt.WA_MacSmallSize)
self.setShowGrid(False)
#self.horizontalHeader().setStretchLastSection(True)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
self.setSortingEnabled(True)
self.setModel(self._model)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment