Skip to content

profiler

DataFrameModel (QAbstractTableModel)

Source code in src/controller/windows/window_electrodelist.py
class DataFrameModel(QtCore.QAbstractTableModel):
    DtypeRole = QtCore.Qt.UserRole + 1000
    ValueRole = QtCore.Qt.UserRole + 1001

    def __init__(self, df=pd.DataFrame(), parent=None):
        super(DataFrameModel, self).__init__(parent)
        self._dataframe = df

    def setDataFrame(self, dataframe):
        self.beginResetModel()
        self._dataframe = dataframe.copy()
        self.endResetModel()

    def dataFrame(self):
        return self._dataframe

    dataFrame = QtCore.pyqtProperty(pd.DataFrame, fget=dataFrame, fset=setDataFrame)

    @QtCore.pyqtSlot(int, QtCore.Qt.Orientation, result=str)
    def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role: int = QtCore.Qt.DisplayRole):
        if role == QtCore.Qt.DisplayRole:
            if orientation == QtCore.Qt.Horizontal:
                return self._dataframe.columns[section]
            else:
                return str(self._dataframe.index[section])
        return QtCore.QVariant()

    def rowCount(self, parent=QtCore.QModelIndex()):
        if parent.isValid():
            return 0
        return len(self._dataframe.index)

    def columnCount(self, parent=QtCore.QModelIndex()):
        if parent.isValid():
            return 0
        return self._dataframe.columns.size

    def data(self, index, role=QtCore.Qt.DisplayRole):
        if not index.isValid() or not (0 <= index.row() < self.rowCount() \
            and 0 <= index.column() < self.columnCount()):
            return QtCore.QVariant()
        row = self._dataframe.index[index.row()]
        col = self._dataframe.columns[index.column()]
        dt = self._dataframe[col].dtype

        val = self._dataframe.iloc[row][col]
        if role == QtCore.Qt.DisplayRole:
            return str(val)
        elif role == DataFrameModel.ValueRole:
            return val
        if role == DataFrameModel.DtypeRole:
            return dt
        return QtCore.QVariant()

    def roleNames(self):
        roles = {
            QtCore.Qt.DisplayRole: b'display',
            DataFrameModel.DtypeRole: b'dtype',
            DataFrameModel.ValueRole: b'value'
        }
        return roles
    # see MainWindow.update_theme() for how this is called
    def update_theme(self, current_theme, themes):

        pass

columnCount(self, parent=<PyQt5.QtCore.QModelIndex object at 0x7fa0ca69ded0>)

columnCount(self, parent: QModelIndex = QModelIndex()) -> int

Source code in src/controller/windows/window_electrodelist.py
def columnCount(self, parent=QtCore.QModelIndex()):
    if parent.isValid():
        return 0
    return self._dataframe.columns.size

data(self, index, role=0)

data(self, QModelIndex, role: int = Qt.ItemDataRole.DisplayRole) -> Any

Source code in src/controller/windows/window_electrodelist.py
def data(self, index, role=QtCore.Qt.DisplayRole):
    if not index.isValid() or not (0 <= index.row() < self.rowCount() \
        and 0 <= index.column() < self.columnCount()):
        return QtCore.QVariant()
    row = self._dataframe.index[index.row()]
    col = self._dataframe.columns[index.column()]
    dt = self._dataframe[col].dtype

    val = self._dataframe.iloc[row][col]
    if role == QtCore.Qt.DisplayRole:
        return str(val)
    elif role == DataFrameModel.ValueRole:
        return val
    if role == DataFrameModel.DtypeRole:
        return dt
    return QtCore.QVariant()

headerData(self, section, orientation, role=0)

headerData(self, int, Qt.Orientation, role: int = Qt.ItemDataRole.DisplayRole) -> Any

Source code in src/controller/windows/window_electrodelist.py
@QtCore.pyqtSlot(int, QtCore.Qt.Orientation, result=str)
def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role: int = QtCore.Qt.DisplayRole):
    if role == QtCore.Qt.DisplayRole:
        if orientation == QtCore.Qt.Horizontal:
            return self._dataframe.columns[section]
        else:
            return str(self._dataframe.index[section])
    return QtCore.QVariant()

roleNames(self)

roleNames(self) -> Dict[int, QByteArray]

Source code in src/controller/windows/window_electrodelist.py
def roleNames(self):
    roles = {
        QtCore.Qt.DisplayRole: b'display',
        DataFrameModel.DtypeRole: b'dtype',
        DataFrameModel.ValueRole: b'value'
    }
    return roles

rowCount(self, parent=<PyQt5.QtCore.QModelIndex object at 0x7fa0ca69de50>)

rowCount(self, parent: QModelIndex = QModelIndex()) -> int

Source code in src/controller/windows/window_electrodelist.py
def rowCount(self, parent=QtCore.QModelIndex()):
    if parent.isValid():
        return 0
    return len(self._dataframe.index)

ElectrodeListInformation (QWidget)

Source code in src/controller/windows/window_electrodelist.py
class ElectrodeListInformation(QWidget):

    app = None
    current_elec = 0
    current_row = 0
    current_col = 0
    model = None

    sortOption = None

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        uic.loadUi("./src/view/layouts/AllChannelsList.ui", self)

        self.sort_by = "row"
        self.chooseSortOption.activated.connect(self.setSortOption)

    def setSessionParent(self, session_parent):
        """

        Args:
            session_parent:

        Returns:

        """
        self.app = session_parent
        self.model = DataFrameModel(self.app.data.df)
        self.electrodeTable.setModel(self.model)
        self.setTheme()

    def update(self):
        """

        Returns:

        """
        self.model = DataFrameModel(self.app.data.df)
        self.model.sort(1)
        self.electrodeTable.setModel(self.model)

    def setSortOption(self):
        """

        Returns:

        """
        self.sortOption = self.chooseSortOption.currentText()
        print("SORT OPTION: " + self.sortOption)
        self.update()

    def setTheme(self):
        #background_color = self.settings[""]
        #self.electrodeTable.setBackground(background_color)
        # TODO set theme of electrode list
        pass

setSessionParent(self, session_parent)

Parameters:

Name Type Description Default
session_parent required
Source code in src/controller/windows/window_electrodelist.py
def setSessionParent(self, session_parent):
    """

    Args:
        session_parent:

    Returns:

    """
    self.app = session_parent
    self.model = DataFrameModel(self.app.data.df)
    self.electrodeTable.setModel(self.model)
    self.setTheme()

setSortOption(self)

Source code in src/controller/windows/window_electrodelist.py
def setSortOption(self):
    """

    Returns:

    """
    self.sortOption = self.chooseSortOption.currentText()
    print("SORT OPTION: " + self.sortOption)
    self.update()

update(self)

Source code in src/controller/windows/window_electrodelist.py
def update(self):
    """

    Returns:

    """
    self.model = DataFrameModel(self.app.data.df)
    self.model.sort(1)
    self.electrodeTable.setModel(self.model)