Esempio n. 1
0
    def data(self, index, role):
        """
        Set data
        """
        result = None
        if index.isValid():
            if role == Qt.DisplayRole:
                if index.column() == COL_NUM:
                    if int(self.stored_data[index.row()]["ihm_id"]) > 1:
                        result = str(
                            (int(self.stored_data[index.row()]["ihm_id"]) - 1))
                    else:
                        result = self.stored_data[index.row()]['row-pos']
                if index.column() == COL_TIMESTAMP:
                    result = self.stored_data[index.row()]['timestamp']
                if index.column() == COL_EVENT:
                    result = self.stored_data[index.row()]['level'].upper()
                if index.column() == COL_FROM:
                    result = self.stored_data[index.row()]['from-component']
                if index.column() == COL_TEXT:
                    short_msg = self.stored_data[index.row()]['short-msg']
                    if sys.version_info > (3, ):  # python 3 support
                        try:
                            result = short_msg.splitlines()[0]
                        except Exception as e:
                            print(
                                'error, resume view: unable to split result: %s'
                                % e)
                            result = ''
                    else:
                        try:
                            if len(short_msg):
                                result = short_msg.decode(
                                    'utf8').splitlines()[0]
                            else:
                                result = ''
                        except UnicodeDecodeError as e:
                            result = short_msg.splitlines()[0]
                        except Exception as e:
                            print(
                                'error, resume view: failed to split result: %s'
                                % str(e))
                            result = ''

            elif role == Qt.ForegroundRole:
                if not 'color-text' in self.stored_data[index.row()]:
                    return None
                data_col = self.stored_data[index.row()]['color-text']
                result = QColor(0, 0, 0)
                result.setNamedColor(data_col)

            elif role == Qt.BackgroundColorRole:
                if not 'color' in self.stored_data[index.row()]:
                    return None
                data_col = self.stored_data[index.row()]['color']
                result = QColor(0, 0, 0)
                result.setNamedColor(data_col)

            elif role == Qt.FontRole:
                if index.column() == COL_TEXT:
                    result = QFont()
                    if 'bold' in self.stored_data[index.row()]:
                        data_col = self.stored_data[index.row()]['bold']
                        result.setBold(data_col)
                    if 'italic' in self.stored_data[index.row()]:
                        data_col = self.stored_data[index.row()]['italic']
                        result.setItalic(data_col)

            elif role == Qt.DecorationRole:
                if index.column() == COL_TEXT:
                    if not 'level' in self.stored_data[index.row()]:
                        return None
                    data_col = self.stored_data[index.row()]['level']
                    if data_col == 'timer-started':
                        result = QIcon(":/timer.png")
                    if data_col == 'timer-stopped':
                        result = QIcon(":/timer_ok.png")
                    if data_col == 'timer-exceeded':
                        result = QIcon(":/timer_ko.png")
                    if data_col == 'received':
                        result = QIcon(":/arrow_left.png")
                    if data_col == 'send':
                        result = QIcon(":/arrow_right.png")
                    if data_col == 'step-failed':
                        result = QIcon(":/steps.png")
        return result
Esempio n. 2
0
    def data(self, index, role):
        """
        Handle data
        """
        result = None
        if index.isValid():
            if role == Qt.DisplayRole:
                if index.column() == COL_NUM:
                    if self.stored_data[index.row()]['ihm_id'] > 0:
                        result = str(self.stored_data[index.row()]['ihm_id'] -
                                     1)
                    else:
                        result = str(index.row())

                if index.column() == COL_TIMESTAMP:
                    result = self.stored_data[index.row()]['timestamp']
                if index.column() == COL_EVENT:
                    result = self.stored_data[index.row()]['level'].upper()
                if index.column() == COL_FROM:
                    result = self.stored_data[index.row()]['from-component']
                if index.column() == COL_FROM_LEVEL:
                    result = self.stored_data[index.row()]['from-level']
                if index.column() == COL_TO_LEVEL:
                    result = self.stored_data[index.row()]['to-level']
                if index.column() == COL_TEXT:
                    short_msg = self.stored_data[index.row()]['short-msg']
                    multiline = False
                    if 'multiline' in self.stored_data[index.row()]:
                        multiline = self.stored_data[index.row()]['multiline']
                    if multiline:
                        if sys.version_info > (3, ):  # py3 support
                            result = short_msg
                        else:
                            try:
                                result = short_msg.decode('utf8')
                            except Exception as e:
                                result = short_msg
                    else:
                        if not len(short_msg):
                            result = ''
                        else:
                            if sys.version_info > (3, ):  # py3 support
                                result = short_msg.splitlines()[0]
                            else:
                                try:
                                    result = short_msg.decode(
                                        'utf8').splitlines()[0]
                                except Exception as e:
                                    result = short_msg.splitlines()[0]

            elif role == Qt.ForegroundRole:
                if not 'color-text' in self.stored_data[index.row()]:
                    return None
                data_col = self.stored_data[index.row()]['color-text']
                result = QColor(0, 0, 0)
                result.setNamedColor(data_col)
            elif role == Qt.BackgroundColorRole:
                if not 'color' in self.stored_data[index.row()]:
                    return None
                data_col = self.stored_data[index.row()]['color']
                result = QColor(0, 0, 0)
                result.setNamedColor(data_col)
            elif role == Qt.FontRole:
                if index.column() == COL_TEXT:
                    result = QFont()
                    if 'bold' in self.stored_data[index.row()]:
                        data_col = self.stored_data[index.row()]['bold']
                        if isinstance(data_col, bool):
                            result.setBold(data_col)
                    if 'italic' in self.stored_data[index.row()]:
                        data_col = self.stored_data[index.row()]['italic']
                        if isinstance(data_col, bool):
                            result.setItalic(data_col)
            elif role == Qt.DecorationRole:
                if index.column() == COL_TEXT:
                    if not 'level' in self.stored_data[index.row()]:
                        return None
                    data_col = self.stored_data[index.row()]['level']
                    if data_col == 'timer-started':
                        result = QIcon(":/timer.png")
                    if data_col == 'timer-stopped':
                        result = QIcon(":/timer_ok.png")
                    if data_col == 'timer-exceeded':
                        result = QIcon(":/timer_ko.png")
                    if data_col == 'received':
                        result = QIcon(":/arrow_left.png")
                    if data_col == 'send':
                        result = QIcon(":/arrow_right.png")
                    if data_col == 'step-failed':
                        result = QIcon(":/steps.png")
        return result