Source code for ptrail.GUI.Table

"""
    This python module is the abstract definition of the Table view
    for viewing the dataframe inside the GUI.

    | Authors: Yaksh J Haranwala
"""

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt


[docs]class TableModel(QtCore.QAbstractTableModel):
[docs] def __init__(self, data): super(TableModel, self).__init__() self._data = data
[docs] def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): if role != QtCore.Qt.DisplayRole: return QtCore.QVariant() if orientation == QtCore.Qt.Horizontal: try: return self._data.columns.tolist()[section] except (IndexError,): return QtCore.QVariant() elif orientation == QtCore.Qt.Vertical: try: return self._data.index.tolist()[section] except (IndexError,): return QtCore.QVariant()
#
[docs] def data(self, index, role=Qt.DisplayRole): if index.isValid(): if role == Qt.DisplayRole: return str(self._data.iloc[index.row(), index.column()]) return None
[docs] def rowCount(self, parent=None): return self._data.shape[0]
[docs] def columnCount(self, parent=None): return self._data.shape[1]