Example #1
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 #2
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 #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 __open_current_cell_color_dialog(self):
        """Update the current cell color setting."""
        color = QColorDialog.getColor(self.current_cell_color, self,
                                      self.tr('Select current cell color'),
                                      QColorDialog.DontUseNativeDialog)
        if color.isValid():
            SettingModel.set_current_cell_color(color)
            self.logger.info('Write current cell color: %s', color.name())

        self.__update_colors()
        self.__update_buttons_colors()
Example #5
0
 def __init_current_cell_color(table):
     """Initialize current cell color."""
     palette = table.palette()
     current_cell_color = SettingModel.current_cell_color()
     current_text_color = contrast_color(current_cell_color.name())
     palette.setBrush(QPalette.Highlight,
                      QBrush(QColor(current_cell_color)))
     palette.setBrush(QPalette.HighlightedText,
                      QBrush(QColor(current_text_color)))
     table.setPalette(palette)
Example #6
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)
Example #7
0
 def __init__(self, year, week_number, parent=None):
     """Construct a week wrapper object."""
     self.logger = logging.getLogger(__name__)
     self.parent = parent
     # get the default work time, to use it as this week value
     default_time = SettingModel.default_week_time()
     self.logger.info('Default time for new week: %s', default_time)
     self._week = Week.get_or_create(
         year=year,
         week_number=week_number,
         defaults={'minutes_to_work': default_time})[0]
     self.logger.debug('Week: %s', self._week)
     self.__create_days()
Example #8
0
 def __update_settings(self):
     """Update user interface with new settings."""
     self.__init_current_cell_color(self.task_view)
     self.__init_current_cell_color(self.result_view)
     self.__update_time()
     self.man_day_edit.setTime(SettingModel.default_man_day_time())
Example #9
0
    def __init_layout(self):
        """Initialize the central widget layout."""
        main_widget = QWidget(self)
        self.setCentralWidget(main_widget)

        main_layout = QGridLayout()
        main_layout.setRowStretch(0, 1)
        main_layout.setRowStretch(1, 1)
        main_layout.setRowStretch(2, 20)
        main_layout.setRowStretch(3, 1)
        main_layout.setColumnStretch(0, 1)
        main_layout.setColumnStretch(1, 1)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        header_layout = FlowLayout()

        self.year_edit = QSpinBox(self)
        self.year_edit.setMinimum(2010)
        self.year_edit.setMaximum(2050)
        self.year_edit.setValue(datetime.datetime.now().year)

        year_widget = QWidget(self)
        year_layout = QHBoxLayout()
        year_widget.setLayout(year_layout)
        year_label = QLabel(self.tr('Year'), self)
        year_layout.addWidget(year_label)
        year_layout.addWidget(self.year_edit)

        self.week_edit = QSpinBox(self)
        self.week_edit.setMinimum(1)
        self.__update_week_edit(self.year_edit.value())
        self.week_edit.setValue(datetime.date.today().isocalendar()[1])

        week_widget = QWidget(self)
        week_layout = QHBoxLayout()
        week_widget.setLayout(week_layout)
        week_label = QLabel(self.tr('Week'), self)
        week_layout.addWidget(week_label)
        week_layout.addWidget(self.week_edit)

        self.week_edit.valueChanged.connect(self.__week_changed)
        self.year_edit.valueChanged.connect(self.__year_changed)

        self.week_time_edit = DurationEdit(parent=self, hour_length=2)

        week_time_widget = QWidget(self)
        week_time_layout = QHBoxLayout()
        week_time_widget.setLayout(week_time_layout)
        week_time_label = QLabel(self.tr('Week time'), self)
        week_time_layout.addWidget(week_time_label)
        week_time_layout.addWidget(self.week_time_edit)

        self.week_time_edit.valueChanged.connect(self.__week_time_changed)

        self.man_day_edit = QTimeEdit(SettingModel.default_man_day_time(),
                                      self)

        man_day_widget = QWidget(self)
        man_day_layout = QHBoxLayout()
        man_day_widget.setLayout(man_day_layout)
        man_day_label = QLabel(self.tr('Man day time'), self)
        man_day_layout.addWidget(man_day_label)
        man_day_layout.addWidget(self.man_day_edit)

        self.man_day_edit.timeChanged.connect(self.__update_week_summary)

        header_layout.addWidget(year_widget)
        header_layout.addWidget(week_widget)
        header_layout.addWidget(week_time_widget)
        header_layout.addWidget(man_day_widget)

        main_layout.addLayout(header_layout, 0, 0, 1, 2)

        self.current_day_label = self.__build_title_label('')
        summary_label = self.__build_title_label(self.tr('Week summary'))

        main_layout.addWidget(self.current_day_label, 1, 0)
        main_layout.addWidget(summary_label, 1, 1)

        main_layout.addWidget(self.task_view, 2, 0)
        main_layout.addWidget(self.result_view, 2, 1)

        week_time_label = QLabel(self.tr('Week time'), self)
        self.week_time_lcd = self.__build_lcd_number_widget()

        remaining_week_label = QLabel(self.tr('Remaining week time'), self)
        self.remaining_week_time_lcd = self.__build_lcd_number_widget()

        day_label = QLabel(self.tr('Day time'), self)
        self.day_time_lcd = self.__build_lcd_number_widget()
        self.__change_day_color(QColor('#0000ff'))

        catch_up_label = QLabel(self.tr('Catch-up time'), self)
        self.catch_up_lcd = self.__build_lcd_number_widget()

        total_annual_label = QLabel(self.tr('Total annual time'), self)
        self.total_annual_lcd = self.__build_lcd_number_widget()

        footer_layout = QGridLayout()
        footer_layout.addWidget(day_label, 0, 0, Qt.AlignHCenter)
        footer_layout.addWidget(week_time_label, 0, 1, Qt.AlignHCenter)
        footer_layout.addWidget(remaining_week_label, 0, 2, Qt.AlignCenter)
        footer_layout.addWidget(catch_up_label, 0, 3, Qt.AlignCenter)
        footer_layout.addWidget(total_annual_label, 0, 4, Qt.AlignCenter)
        footer_layout.addWidget(self.day_time_lcd, 1, 0)
        footer_layout.addWidget(self.week_time_lcd, 1, 1)
        footer_layout.addWidget(self.remaining_week_time_lcd, 1, 2)
        footer_layout.addWidget(self.catch_up_lcd, 1, 3)
        footer_layout.addWidget(self.total_annual_lcd, 1, 4)

        main_layout.addLayout(footer_layout, 3, 0, 1, 2)

        main_widget.setLayout(main_layout)
Example #10
0
 def __week_time_changed(self):
     """Update the week time setting."""
     SettingModel.set_default_week_time(self.week_time.minutes)
     self.logger.info('Write default week time minutes: %s',
                      self.week_time.minutes)
Example #11
0
    def __init__(self, parent=None):
        """Construct a settings dialog."""
        super().__init__(parent)
        self.logger = logging.getLogger(__name__)
        self.logger.info('Opening setting dialog')
        self.setWindowTitle(self.tr('Edit preferences'))
        self.center()

        self.invalid_color = None
        self.valid_color = None
        self.current_cell_color = None

        self.__update_colors()

        week_time_label = QLabel(self.tr('Default week time'), self)
        self.week_time = DurationEdit(parent=self, hour_length=2)
        self.week_time.minutes = SettingModel.default_week_time()
        self.logger.info('Read default week time minutes: %s',
                         SettingModel.default_week_time())
        self.week_time.valueChanged.connect(self.__week_time_changed)

        man_day_time_label = QLabel(self.tr('Default man day time'), self)
        self.man_day_time = QTimeEdit(SettingModel.default_man_day_time(),
                                      self)
        self.logger.info('Read default man day time: %s',
                         SettingModel.default_man_day_time().toString('hh:mm'))
        self.man_day_time.timeChanged.connect(self.__man_day_time_changed)

        invalid_color_label = QLabel(self.tr('Invalid color'), self)
        self.invalid_color_button = QPushButton(self.tr('Text'), self)
        self.invalid_color_button.clicked.connect(
            self.__open_invalid_color_dialog)

        valid_color_label = QLabel(self.tr('Valid color'), self)
        self.valid_color_button = QPushButton(self.tr('Text'), self)
        self.valid_color_button.clicked.connect(self.__open_valid_color_dialog)

        current_cell_color_label = QLabel(self.tr('Current cell color'), self)
        self.current_cell_color_button = QPushButton(self.tr('Text'), self)
        self.current_cell_color_button.clicked.connect(
            self.__open_current_cell_color_dialog)

        self.__update_buttons_colors()

        main_layout = QGridLayout()

        main_layout.addWidget(week_time_label, 0, 0)
        main_layout.addWidget(self.week_time, 0, 1)

        main_layout.addWidget(man_day_time_label, 1, 0)
        main_layout.addWidget(self.man_day_time, 1, 1)

        main_layout.addWidget(invalid_color_label, 2, 0)
        main_layout.addWidget(self.invalid_color_button, 2, 1)

        main_layout.addWidget(valid_color_label, 3, 0)
        main_layout.addWidget(self.valid_color_button, 3, 1)

        main_layout.addWidget(current_cell_color_label, 4, 0)
        main_layout.addWidget(self.current_cell_color_button, 4, 1)

        self.setLayout(main_layout)
Example #12
0
 def __man_day_time_changed(self):
     """Update the man day time setting."""
     SettingModel.set_default_man_day_time(self.man_day_time.time())
     self.logger.info('Write default man day time: %s',
                      self.man_day_time.time().toString('hh:mm'))