TimeTracker/TimeTrackerEntryDialog.py

Fri, 04 Jun 2021 16:40:54 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Jun 2021 16:40:54 +0200
branch
eric7
changeset 98
693e42176007
parent 94
a3d936304e51
child 105
44bfd9e7e65e
permissions
-rw-r--r--

Ported the plug-in to PyQt6 for eric7.

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

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

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

from PyQt6.QtCore import pyqtSlot, QDateTime, QDate
from PyQt6.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
        @type TimeTracker
        @param entry reference to the time tracker entry
        @type TimeTrackEntry
        @param taskItems list of task item entries for the
            task combo box
        @type list of str
        @param commentItems list of comment item entries for the
            comment combo box
        @type list of str
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.buttonBox.button(
            QDialogButtonBox.StandardButton.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.durationSpinBox.setMaximum(
                entry.getStartDateTime().secsTo(self.__endDateTime) // 60)
            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.StandardButton.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
        @type 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
        @type int
        """
        self.__checkOk()
    
    def getData(self):
        """
        Public method to get the data.
        
        @return tuple with start date and time, duration, task description
            and comment
        @rtype tuple of (QDateTime, int, str, str)
        """
        return (
            self.startDateTimeEdit.dateTime(),
            self.durationSpinBox.value(),
            self.taskCombo.currentText(),
            self.commentCombo.currentText(),
        )

eric ide

mercurial