eric7/Tasks/TaskPropertiesDialog.py

Sat, 22 May 2021 19:58:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 22 May 2021 19:58:24 +0200
branch
eric7
changeset 8358
144a6b854f70
parent 8356
68ec9c3d4de5
child 8881
54e42bc2437a
permissions
-rw-r--r--

Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).

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

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

"""
Module implementing the task properties dialog.
"""

import time

from PyQt6.QtWidgets import QDialog

from EricWidgets.EricCompleters import EricFileCompleter

from .Ui_TaskPropertiesDialog import Ui_TaskPropertiesDialog

from .Task import TaskType, TaskPriority


class TaskPropertiesDialog(QDialog, Ui_TaskPropertiesDialog):
    """
    Class implementing the task properties dialog.
    """
    def __init__(self, task=None, parent=None, projectOpen=False):
        """
        Constructor
        
        @param task the task object to be shown
        @type Task
        @param parent the parent widget
        @type QWidget
        @param projectOpen flag indicating status of the project
        @type bool
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.filenameCompleter = EricFileCompleter(self.filenameEdit)
        
        self.typeCombo.addItem(self.tr("Bugfix"), TaskType.FIXME)
        self.typeCombo.addItem(self.tr("Warning"), TaskType.WARNING)
        self.typeCombo.addItem(self.tr("ToDo"), TaskType.TODO)
        self.typeCombo.addItem(self.tr("Note"), TaskType.NOTE)
        self.typeCombo.addItem(self.tr("Test"), TaskType.TEST)
        self.typeCombo.addItem(self.tr("Documentation"), TaskType.DOCU)
        
        if task is not None:
            self.summaryEdit.setText(task.summary)
            self.descriptionEdit.setText(task.description)
            self.creationLabel.setText(
                time.strftime("%Y-%m-%d, %H:%M:%S",
                              time.localtime(task.created)))
            self.priorityCombo.setCurrentIndex(task.priority.value)
            self.projectCheckBox.setChecked(task._isProjectTask)
            self.completedCheckBox.setChecked(task.completed)
            self.filenameEdit.setText(task.filename)
            if task.lineno:
                self.linenoEdit.setText(str(task.lineno))
            index = self.typeCombo.findData(task.taskType)
            self.typeCombo.setCurrentIndex(index)
            self.__setMode(bool(task.filename), projectOpen)
        else:
            self.projectCheckBox.setChecked(projectOpen)
            self.typeCombo.setCurrentIndex(2)   # TaskType.TODO
            self.__setMode(False, projectOpen)
    
    def __setMode(self, isFileTask, projectOpen):
        """
        Private method to show or hide dialog elements depending on the task
        kind.
        
        @param isFileTask flag indicating a file task (i.e. extracted task)
        @type bool
        @param projectOpen flag indicating status of the project
        @type bool
        """
        self.__isFileTaskMode = isFileTask
        if self.__isFileTaskMode:
            self.descriptionEdit.hide()
            self.descriptionLabel.hide()
            self.manualTaskFrame.hide()
            
            msh = self.minimumSizeHint()
            self.resize(max(self.width(), msh.width()), msh.height())
        else:
            self.fileTaskFrame.hide()
        
        self.summaryEdit.setReadOnly(isFileTask)
        self.projectCheckBox.setEnabled(projectOpen and not isFileTask)
    
    def isManualTaskMode(self):
        """
        Public method to check, if the dialog is in manual task mode.
        
        @return flag indicating manual task mode
        @rtype bool
        """
        return not self.__isFileTaskMode
    
    def setSubTaskMode(self, projectTask):
        """
        Public slot to set the sub-task mode.
        
        @param projectTask flag indicating a project related task (boolean)
        """
        self.projectCheckBox.setChecked(projectTask)
        self.projectCheckBox.setEnabled(False)
    
    def getData(self):
        """
        Public method to retrieve the dialogs data.
        
        @return tuple of description, priority, type, completion flag,
                project flag and long text
        @rtype tuple of (str, TaskPriority, TaskType, bool, bool, str)
        """
        return (self.summaryEdit.text(),
                TaskPriority(self.priorityCombo.currentIndex()),
                TaskType(self.typeCombo.currentData()),
                self.completedCheckBox.isChecked(),
                self.projectCheckBox.isChecked(),
                self.descriptionEdit.toPlainText())

eric ide

mercurial