Example #1
0
    def data(self, index, role=None):
        """Return the data.

        Return the data stored under the given role for the item referred
        to by the index.
        """
        if not index.isValid():
            return QVariant()

        row = index.row()
        column = index.column()
        if role in (Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole):
            try:
                value = self._cached_data[row][TaskColumn(column)]
            except KeyError:
                return QVariant()
            else:
                if column == TaskColumn.Id.value:
                    return int(value)
                elif column == TaskColumn.Task.value:
                    if role == Qt.ToolTipRole:
                        # html text allows automatic word-wrapping on tooltip.
                        return '<html>{}</html>'.format(str(value))
                    else:
                        return str(value)
                elif column in (TaskColumn.Start_Time.value,
                                TaskColumn.End_Time.value):
                    try:
                        a_time = QTime(value.hour, value.minute, value.second)
                        return QVariant(a_time)
                    except AttributeError:
                        if role == Qt.EditRole:
                            return QVariant(QTime(0, 0))
                        else:
                            return QVariant()
        elif role in (Qt.BackgroundRole, Qt.ForegroundRole):
            try:
                start = self._cached_data[row][TaskColumn.Start_Time]
                end = self._cached_data[row][TaskColumn.End_Time]
                background_color = SettingModel.valid_color()
                if role == Qt.BackgroundRole:
                    if not start or not end or start >= end:
                        background_color = SettingModel.invalid_color()
                    return QBrush(background_color)
                elif role == Qt.ForegroundRole:
                    text_color = contrast_color(background_color.name())
                    return QBrush(QColor(text_color))
            except KeyError:
                pass

        elif role == Qt.TextAlignmentRole:
            if column == TaskColumn.Task.value:
                return Qt.AlignLeft | Qt.AlignVCenter
            else:
                return Qt.AlignCenter | Qt.AlignVCenter

        return QVariant()
Example #2
0
 def __update_colors(self):
     """Update the local colors values."""
     self.invalid_color = SettingModel.invalid_color()
     self.valid_color = SettingModel.valid_color()
     self.current_cell_color = SettingModel.current_cell_color()
     self.logger.info('Read invalid color: %s', self.invalid_color.name())
     self.logger.info('Read valid color: %s', self.valid_color.name())
     self.logger.info('Read current cell color: %s',
                      self.current_cell_color.name())
Example #3
0
    def __update_week_counter_color(self):
        """Update the week counter color depending on the time percentage."""
        percent = 1
        if self.week_wrapper.minutes_to_work:
            # denominator cannot be zero
            percent = (self.week_wrapper.minutes_of_week /
                       self.week_wrapper.minutes_to_work)

        color = color_between(SettingModel.invalid_color().name(),
                              SettingModel.valid_color().name(), percent)
        self.__change_week_color(QColor(color))
Example #4
0
    def __update_catch_up_time_counter(self):
        """Update the catch-up time counter."""
        to_work = self.week_wrapper.total_time_to_work
        worked = self.week_wrapper.total_time_worked

        catch_up_time = worked - to_work
        abs_time = abs(catch_up_time)
        time_str = minutes_to_time_str(abs_time)

        if catch_up_time >= 0:
            self.__change_catch_up_color(SettingModel.valid_color())
            self.catch_up_lcd.setToolTip('+' + time_str)
        else:
            self.__change_catch_up_color(SettingModel.invalid_color())
            self.catch_up_lcd.setToolTip('-' + time_str)

        if abs_time >= 6000:
            self.catch_up_lcd.display(abs_time // 60)
        else:
            self.catch_up_lcd.display(time_str)