TimeTracker/TimeTrackerEntryDialog.py

Tue, 23 Jun 2020 19:40:26 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 23 Jun 2020 19:40:26 +0200
changeset 87
4ac2329b36da
parent 84
427a7f8d662f
child 92
81b63c2dc40c
permissions
-rw-r--r--

Removed support for Python2.

# -*- coding: utf-8 -*-

# Copyright (c) 2012 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the time tracker edit dialog.
"""

from PyQt5.QtCore import pyqtSlot, QDateTime, QDate
from PyQt5.QtWidgets import QDialog, QDialogButtonBox

from .Ui_TimeTrackerEntryDialog import Ui_TimeTrackerEntryDialog


class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog):
    """
    Class implementing the time tracker edit dialog.
    """
    def __init__(self, tracker, entry, taskItems, commentItems, parent=None):
        """
        Constructor
        
        @param tracker reference to the time tracker (TimeTracker)
        @param entry reference to the time tracker entry (TimeTrackEntry)
        @param taskItems list of task item entries for the
            task combo box (list of strings)
        @param commentItems list of comment item entries for the
            comment combo box (list of strings)
        @param parent reference to the parent widget (QWidget)
        """
        super(TimeTrackerEntryDialog, self).__init__(parent)
        self.setupUi(self)
        
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
        
        self.taskCombo.addItems(taskItems)
        self.commentCombo.addItems(commentItems)
        
        # The allowed end time (i.e. start date and time plus duration must be
        # earlier or equal to the start date and time of the current entry.
        self.__endDateTime = QDateTime(
            tracker.getCurrentEntry().getStartDateTime())
        
        self.durationSpinBox.setMinimum(
            tracker.getPreferences("MinimumDuration"))
        
        if entry is None:
            self.setWindowTitle(self.tr("Add Tracker Entry"))
            self.startDateTimeEdit.setDate(QDate.currentDate())
        else:
            self.startDateTimeEdit.setDateTime(entry.getStartDateTime())
            self.durationSpinBox.setValue(entry.getDuration())
            self.taskCombo.setEditText(entry.getTask())
            self.commentCombo.setEditText(entry.getComment())
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    def __checkOk(self):
        """
        Private slot to set the enabled state of the OK button.
        """
        dt = self.startDateTimeEdit.dateTime()
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
            dt.addSecs(self.durationSpinBox.value() * 60) <=
            self.__endDateTime)
    
    @pyqtSlot(QDateTime)
    def on_startDateTimeEdit_dateTimeChanged(self, date):
        """
        Private slot handling a change of the start date and time.
        
        @param date start date and time (QDateTime)
        """
        self.__checkOk()
    
    @pyqtSlot(int)
    def on_durationSpinBox_valueChanged(self, value):
        """
        Private slot handling a change of the duration.
        
        @param value value of the duration spin box (integer)
        """
        self.__checkOk()
    
    def getData(self):
        """
        Public method to get the data.
        
        @return tuple with start date and time, duration, task description
            and comment (QDateTime, integer, string, string)
        """
        return (
            self.startDateTimeEdit.dateTime(),
            self.durationSpinBox.value(),
            self.taskCombo.currentText(),
            self.commentCombo.currentText(),
        )

eric ide

mercurial