def __init__(self, parent: QWidget=None): super().__init__( parent ) self.parentWidget = parent self.domainModel = Manager() self.undoStack = QUndoStack(self)
def test_getNextDeadline_None(self): manager = Manager() manager.addTask(Task("task1")) manager.addTask(Task("task2")) deadlineTask = manager.getNextDeadline() self.assertEqual(deadlineTask, None)
def test_getTaskOccurrencesForDate_recurrent_completed(self): manager = Manager() task = manager.addTask() todayDate = datetime.datetime.today() dueDate = todayDate.replace(day=1, hour=12) task.dueDateTime = dueDate task.recurrence = Recurrent() task.recurrence.setWeekly() task.setCompleted() ## mark first occurrence completed tasksList = manager.getTaskOccurrencesForDate(dueDate.date()) self.assertEqual(len(tasksList), 1)
def test_getTasksAll(self): manager = Manager() task1 = manager.addTask(Task("task1")) task2 = manager.addTask(Task("task2")) subtask = task2.addSubItem(Task("subtask1")) subtask2 = subtask.addSubItem(Task("subtask2")) allTasks = manager.getTasksAll() self.assertEqual(len(allTasks), 4) self.assertEqual(allTasks[0], task1) self.assertEqual(allTasks[1], task2) self.assertEqual(allTasks[2], subtask) self.assertEqual(allTasks[3], subtask2) allTasks.clear() self.assertEqual(len(manager.getTasksAll()), 4)
def test_getNextDeadline(self): manager = Manager() taskDate = datetime.datetime.today() manager.addNewTaskDateTime(taskDate + timedelta(seconds=5), "task1") manager.addNewTaskDateTime(taskDate, "task2") deadlineTask = manager.getNextDeadline() self.assertEqual(deadlineTask.title, "task2")
def test_removeTask(self): manager = Manager() taskDate1 = datetime.date(2020, 5, 17) task1 = manager.addNewTask(taskDate1, "task1") taskDate2 = datetime.date(2020, 5, 18) manager.addNewTask(taskDate2, "task2") tasks = manager.getTasks() self.assertEqual(len(tasks), 2) manager.removeTask(task1) tasks = manager.getTasks() self.assertEqual(len(tasks), 1) self.assertEqual(tasks[0].title, "task2")
def test_getTasks(self): manager = Manager() manager.addNewTask(datetime.date.today(), "task1") manager.addNewTask(datetime.date.today(), "task2") self.assertEqual(len(manager.getTasks()), 2) tasksList = manager.getTasks() tasksList.clear() self.assertEqual(len(manager.getTasks()), 2)
def test_getToDos(self): manager = Manager() manager.addToDo() manager.addToDo() self.assertEqual(len(manager.getToDos()), 2) tasksList = manager.getToDos() tasksList.clear() self.assertEqual(len(manager.getToDos()), 2)
def test_getNotificationList(self): manager = Manager() taskDate1 = datetime.datetime.today() + datetime.timedelta(seconds=60) manager.addNewDeadlineDateTime(taskDate1, "task1") taskDate2 = datetime.datetime.today() + datetime.timedelta(seconds=30) manager.addNewDeadlineDateTime(taskDate2, "task2") tasks = manager.getTasks() self.assertEqual(len(tasks), 2) notifications = manager.getNotificationList() self.assertEqual(len(notifications), 2) self.assertEqual(notifications[0].task.title, "task2") self.assertEqual(notifications[1].task.title, "task1")
def test_replaceTask(self): manager = Manager() taskDate1 = datetime.date(2020, 5, 17) task1 = manager.addNewTask(taskDate1, "task1") task2 = Task() task2.title = "new task" tasks = manager.getTasks() self.assertEqual(len(tasks), 1) manager.replaceTask(task1, task2) tasks = manager.getTasks() self.assertEqual(len(tasks), 1) self.assertEqual(tasks[0].title, "new task")
class DataObject( QObject ): ## added, modified or removed tasksChanged = pyqtSignal() ## added, modified or removed todosChanged = pyqtSignal() ## added, modified or removed notesChanged = pyqtSignal() def __init__(self, parent: QWidget=None): super().__init__( parent ) self.parentWidget = parent self.domainModel = Manager() self.undoStack = QUndoStack(self) def getManager(self): return self.domainModel def load( self, inputDir ): self.domainModel.load( inputDir ) def store( self, inputDir ): return self.domainModel.store( inputDir ) def getTaskOccurrences(self, taskDate: date, includeCompleted=True): return self.domainModel.getTaskOccurrencesForDate( taskDate, includeCompleted ) ## ============================================================== def addNewTask( self, newTaskDate: QDate = None ): task = self._createTask( newTaskDate ) if task is None: return self.addTask( task ) def addNewSubTask( self, parent: Task ): if parent is None: self.addNewTask() return task = self._createTask() if task is None: return self.undoStack.push( AddSubTaskCommand( self, parent, task ) ) def addTask(self, task: Task = None ) -> Task: if task is None: task = Task() self.undoStack.push( AddTaskCommand( self, task ) ) return task def editTask(self, task: Task ): if task is None: return taskDialog = TaskDialog( task, self.parentWidget ) taskDialog.setModal( True ) dialogCode = taskDialog.exec_() if dialogCode == QDialog.Rejected: return self.undoStack.push( EditTaskCommand( self, task, taskDialog.task ) ) def removeTask(self, task: Task ): self.undoStack.push( RemoveTaskCommand( self, task ) ) def markTaskCompleted(self, task: Task ): self.undoStack.push( MarkTaskCompletedCommand( self, task ) ) def moveTask(self, taskCoords, parentTask, targetIndex): self.undoStack.push( MoveTaskCommand( self, taskCoords, parentTask, targetIndex ) ) ## ============================================================== def addNewToDo( self, content=None ): todo = self._createToDo( content ) self.addToDo( todo ) def addToDo(self, todo: ToDo = None ) -> ToDo: if todo is None: todo = ToDo() self.undoStack.push( AddToDoCommand( self, todo ) ) return todo def addNewSubToDo( self, parent: ToDo ): if parent is None: self.addNewToDo() return todo = self._createToDo() if todo is None: return self.undoStack.push( AddSubToDoCommand( self, parent, todo ) ) def editToDo(self, todo: ToDo ): todoDialog = ToDoDialog( todo, self.parentWidget ) todoDialog.setModal( True ) dialogCode = todoDialog.exec_() if dialogCode == QDialog.Rejected: return self.undoStack.push( EditToDoCommand( self, todo, todoDialog.todo ) ) def removeToDo(self, todo: ToDo ): self.undoStack.push( RemoveToDoCommand( self, todo ) ) def convertToDoToTask(self, todo: ToDo ): task = Task() task.title = todo.title task.description = todo.description task.completed = todo.completed task.priority = todo.priority taskDialog = TaskDialog( task, self.parentWidget ) taskDialog.setModal( True ) dialogCode = taskDialog.exec_() if dialogCode == QDialog.Rejected: return self.undoStack.push( ConvertToDoToTaskCommand( self, todo, taskDialog.task ) ) def markToDoCompleted(self, todo: ToDo ): self.undoStack.push( MarkToDoCompletedCommand( self, todo ) ) def moveToDo(self, todoCoords, parentToDo, targetIndex): self.undoStack.push( MoveToDoCommand( self, todoCoords, parentToDo, targetIndex ) ) def _createTask( self, newTaskDate: QDate = None ): task = Task() if newTaskDate is not None: startDate = newTaskDate.toPyDate() task.setDefaultDate( startDate ) taskDialog = TaskDialog( task, self.parentWidget ) taskDialog.setModal( True ) dialogCode = taskDialog.exec_() if dialogCode == QDialog.Rejected: return None return taskDialog.task def _createToDo( self, content=None ): todo = ToDo() if content is not None: todo.description = content todoDialog = ToDoDialog( todo, self.parentWidget ) todoDialog.setModal( True ) dialogCode = todoDialog.exec_() if dialogCode == QDialog.Rejected: return None return todoDialog.todo ## ============================================================== def addNote(self, title): self.undoStack.push( AddNoteCommand( self, title ) ) def renameNote(self, fromTitle, toTitle): self.undoStack.push( RenameNoteCommand( self, fromTitle, toTitle ) ) def removeNote(self, title): self.undoStack.push( RemoveNoteCommand( self, title ) ) def importXfceNotes(self): newNotes = import_xfce_notes() if not newNotes: return self.undoStack.push( ImportXfceNotesCommand( self, newNotes ) )
def prepare_example_data(dataManager: Manager): taskDate = datetime.today() - timedelta(seconds=5) task1 = dataManager.addNewTaskDateTime( datetime.today() + timedelta(days=1), "task 1") task1.completed = 50 task1.description = ( "<a href=\"http://www.google.com\">xxx</a> <br> " "<a href=\"file:///media/E/bluetooth.txt\">yyy</a> <br> " "<a href=\"file:///media/E/Pani1.jpg\">zzz</a>") task1.addSubItem(Task("Subtask")) completedTask = dataManager.addNewTaskDateTime( taskDate + timedelta(days=7), "completed task") completedTask.setCompleted() ## add far task dataManager.addNewTaskDateTime(datetime.today() + timedelta(days=360), "far task") recurrentDate = taskDate.replace(day=20, hour=12) recurrentTask = dataManager.addNewTaskDateTime(recurrentDate, "recurrent task 1") recurrentTask.recurrence = Recurrent() recurrentTask.recurrence.setDaily() recurrentTask.recurrence.endDate = recurrentDate.date() + timedelta(days=2) reminder = recurrentTask.addReminder() reminder.setDays(1) task2 = dataManager.addNewTaskDateTime( recurrentTask.occurrenceStart.replace(hour=11), "task 2") task2.dueDateTime = task2.occurrenceDue.replace(hour=20) task3 = dataManager.addTask() task3.title = "task 3" task3.dueDateTime = taskDate.replace(hour=20) + timedelta(days=90) task3.startDateTime = task3.dueDateTime - timedelta(days=1) subtask1 = task3.addSubTask() subtask1.title = "subtask 1" subtask1.startDateTime = task3.startDateTime - timedelta(days=50) subtask1.dueDateTime = task3.dueDateTime - timedelta(days=40) completedTask = dataManager.addNewTaskDateTime( task2.occurrenceStart - timedelta(hours=3), "completed task 2") completedTask.setCompleted() recurrentDate2 = datetime.today().replace(day=15) + timedelta(days=30) recurrentTask2 = dataManager.addNewTaskDateTime(recurrentDate2, "recurrent task 2") recurrentTask2.setDeadline() recurrentTask2.recurrence = Recurrent() recurrentTask2.recurrence.setMonthly() recurrentSub = recurrentTask2.addSubTask() recurrentSub.title = "recurrent subtask 1" recurrentSub.setDeadline() recurrentSub.dueDateTime = recurrentTask2.dueDateTime - timedelta(days=1) recurrentSub.recurrence = Recurrent() recurrentSub.recurrence.setMonthly() deadlineDate = datetime.today() + timedelta(seconds=10) deadlineTaks = dataManager.addNewDeadlineDateTime(deadlineDate, "expired task 1") reminder = deadlineTaks.addReminder() reminder.setMillis(5000) remindedTask = dataManager.addNewTaskDateTime( datetime.today() + timedelta(hours=2), "reminded task 1") reminder = remindedTask.addReminder() reminder.setDays(30) todo1 = dataManager.addNewToDo("ToDo example A") todo1.description = "a description" todo1.priority = 3 todo1.completed = 33 todo1 = dataManager.addNewToDo("ToDo example B") todo1.description = "a description" todo1.priority = 3 todo1.completed = 33 todo1 = dataManager.addNewToDo("ToDo example C") todo1.description = "a description" todo1.priority = 3 todo1.completed = 33 todo2 = dataManager.addNewToDo("ToDo example 2") todo2.description = "a description" todo2.priority = 5 todo2.completed = 20 todo2 = dataManager.addNewToDo("ToDo example 3") todo2.description = "a description" todo2.priority = 1 todo2.completed = 0 todoCompleted = dataManager.addNewToDo("completed ToDo 1") todoCompleted.description = "a description" todoCompleted.priority = 1 todoCompleted.completed = 100 dataManager.addNote("note 2", "note content")