def test_request_update_without_loaded_file_hides_lists() -> None: view = MockView() presenter = MainPresenter(view) assert view.hide_lists_calls == 0 presenter.request_update() assert view.hide_lists_calls == 1 assert view.update_tasks_calls == []
def test_load_from_file() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("jabra")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("load_path")) assert view.update_tasks_calls == [[Task("jabra")]] assert view.window_title == "load_path" assert serializer_wrapper.path == Path("load_path")
def test_redo() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("new")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path()) presenter.add_task(Task("adaptive")) presenter.undo() presenter.redo() assert view.update_tasks_calls[-1] == [Task("new"), Task("adaptive")] assert serializer_wrapper.tasks == [Task("new"), Task("adaptive")] assert view.undoable assert not view.redoable
def test_add_task_saves_tasks() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("lamp")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("")) presenter.add_task(Task("clock")) assert serializer_wrapper.tasks == [Task("lamp"), Task("clock")]
def test_add_task_updates_tasks() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("curry")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("load_path")) presenter.add_task(Task("asos")) assert view.update_tasks_calls[-1] == [Task("curry"), Task("asos")]
def test_request_update_update_tasks_when_file_is_loaded() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("dill")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("load_path")) view.update_tasks_calls = [] presenter.request_update() assert view.update_tasks_calls == [[Task("dill")]]
def test_set_task_snooze() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("know")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("")) presenter.set_task_snooze(Task("know"), date(1, 2, 3)) assert view.update_tasks_calls[-1] == [Task("know", snooze=date(1, 2, 3))] assert serializer_wrapper.tasks == [Task("know", snooze=date(1, 2, 3))]
def test_rename_task() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("wind")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path()) presenter.rename_task(Task("wind"), "imo") assert view.update_tasks_calls[-1] == [Task("imo")] assert serializer_wrapper.tasks == [Task("imo")]
def test_delete_task() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("doc")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("")) presenter.delete_task(Task("doc")) assert view.update_tasks_calls[-1] == [] assert serializer_wrapper.tasks == []
def test_complete_task() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("bind")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path("")) presenter.complete_task(Task("bind")) assert view.update_tasks_calls[-1] \ == [Task("bind", completed=date.today())] assert serializer_wrapper.tasks == [Task("bind", completed=date.today())]
def test_set_importance() -> None: view = MockView() serializer_wrapper = MockSerializerWrapper([Task("range")]) presenter = MainPresenter(view, serializer_wrapper.serializer) presenter.load_from_file(Path()) presenter.set_importance(Task("range"), Importance.Important) assert view.update_tasks_calls[-1] \ == [Task("range", importance=Importance.Important)] assert serializer_wrapper.tasks == \ [Task("range", importance=Importance.Important)]
def __init__(self) -> None: super().__init__() self._presenter = MainPresenter(self) self.showMaximized() self.setWindowTitle("Eisenhower") self.setAcceptDrops(True) palette = self.palette() palette.setColor(QtGui.QPalette.Window, QtGui.QColor(50, 54, 76)) self.setPalette(palette) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self._undo_button = QtWidgets.QPushButton("Undo") self._redo_button = QtWidgets.QPushButton("Redo") self._add_task_button = QtWidgets.QPushButton("Add Task") self._show_archive_button = QtWidgets.QPushButton("Show Archive") self._priority_button = QtWidgets.QPushButton("Priority Mode") self._priority_button.setCheckable(True) _style_button(self._undo_button) _style_button(self._redo_button) _style_button(self._add_task_button) _style_button(self._show_archive_button) _style_button(self._priority_button) button_layout = QtWidgets.QVBoxLayout() layout.addLayout(button_layout) button_layout.addWidget(self._add_task_button) button_layout.addWidget(self._undo_button) button_layout.addWidget(self._redo_button) button_layout.addWidget(self._show_archive_button) button_layout.addWidget(self._priority_button) button_layout.addStretch() self._do_list = DividedTasksView("Do", QtGui.QColor(240, 98, 146), self) self._decide_list = DividedTasksView("Decide", QtGui.QColor(255, 149, 157), self) self._delegate_list = DividedTasksView("Delegate", QtGui.QColor(255, 215, 140), self) self._drop_list = DividedTasksView("Drop", QtGui.QColor(128, 222, 234), self) task_layout = QtWidgets.QHBoxLayout() task_layout.setContentsMargins(0, 0, 0, 0) task_layout.setSpacing(5) layout.addLayout(task_layout) for task_list in (self._do_list, self._decide_list, self._delegate_list, self._drop_list): task_layout.addWidget(task_list) task_list.complete_task_requested.connect( self._presenter.complete_task) task_list.delete_task_requested.connect( self._presenter.delete_task) task_list.rename_task_requested.connect( self._presenter.rename_task) task_list.schedule_task_requested.connect( self._presenter.set_task_due) task_list.snooze_task_requested.connect( self._presenter.set_task_snooze) task_list.add_task_requested.connect(self._add_task) task_list.remove_due_requested.connect( lambda task: self._presenter.set_task_due(task, None)) task_list.remove_snooze_requested.connect( lambda task: self._presenter.set_task_snooze(task, None)) task_list.set_important_requested.connect( lambda task: self._presenter.set_importance( task, Importance.Important)) task_list.set_unimportant_requested.connect( lambda task: self._presenter.set_importance( task, Importance.Unimportant)) self._undo_button.clicked.connect(self._presenter.undo) self._redo_button.clicked.connect(self._presenter.redo) self._add_task_button.clicked.connect(self._add_task) self._show_archive_button.clicked.connect(self._show_archive) self._priority_button.toggled.connect(self._toggle_priority) self._archive_view = TasksView((Column.Name, Column.Archived), QtGui.QColor(255, 255, 255), self) self._archive_view.setWindowFlag(QtGui.Qt.Window) self._archive_view.setWindowTitle("Task Archive") self._archive_view.sortByColumn(1, QtCore.Qt.SortOrder.DescendingOrder) self._archive_view.hide() self._archive_view.delete_task_requested.connect( self._presenter.delete_task) self._archive_view.unarchive_task_requested.connect( lambda task: self._presenter.complete_task(task, False)) self._presenter.request_update()
class MainWindowQt(QtWidgets.QWidget): def __init__(self) -> None: super().__init__() self._presenter = MainPresenter(self) self.showMaximized() self.setWindowTitle("Eisenhower") self.setAcceptDrops(True) palette = self.palette() palette.setColor(QtGui.QPalette.Window, QtGui.QColor(50, 54, 76)) self.setPalette(palette) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self._undo_button = QtWidgets.QPushButton("Undo") self._redo_button = QtWidgets.QPushButton("Redo") self._add_task_button = QtWidgets.QPushButton("Add Task") self._show_archive_button = QtWidgets.QPushButton("Show Archive") self._priority_button = QtWidgets.QPushButton("Priority Mode") self._priority_button.setCheckable(True) _style_button(self._undo_button) _style_button(self._redo_button) _style_button(self._add_task_button) _style_button(self._show_archive_button) _style_button(self._priority_button) button_layout = QtWidgets.QVBoxLayout() layout.addLayout(button_layout) button_layout.addWidget(self._add_task_button) button_layout.addWidget(self._undo_button) button_layout.addWidget(self._redo_button) button_layout.addWidget(self._show_archive_button) button_layout.addWidget(self._priority_button) button_layout.addStretch() self._do_list = DividedTasksView("Do", QtGui.QColor(240, 98, 146), self) self._decide_list = DividedTasksView("Decide", QtGui.QColor(255, 149, 157), self) self._delegate_list = DividedTasksView("Delegate", QtGui.QColor(255, 215, 140), self) self._drop_list = DividedTasksView("Drop", QtGui.QColor(128, 222, 234), self) task_layout = QtWidgets.QHBoxLayout() task_layout.setContentsMargins(0, 0, 0, 0) task_layout.setSpacing(5) layout.addLayout(task_layout) for task_list in (self._do_list, self._decide_list, self._delegate_list, self._drop_list): task_layout.addWidget(task_list) task_list.complete_task_requested.connect( self._presenter.complete_task) task_list.delete_task_requested.connect( self._presenter.delete_task) task_list.rename_task_requested.connect( self._presenter.rename_task) task_list.schedule_task_requested.connect( self._presenter.set_task_due) task_list.snooze_task_requested.connect( self._presenter.set_task_snooze) task_list.add_task_requested.connect(self._add_task) task_list.remove_due_requested.connect( lambda task: self._presenter.set_task_due(task, None)) task_list.remove_snooze_requested.connect( lambda task: self._presenter.set_task_snooze(task, None)) task_list.set_important_requested.connect( lambda task: self._presenter.set_importance( task, Importance.Important)) task_list.set_unimportant_requested.connect( lambda task: self._presenter.set_importance( task, Importance.Unimportant)) self._undo_button.clicked.connect(self._presenter.undo) self._redo_button.clicked.connect(self._presenter.redo) self._add_task_button.clicked.connect(self._add_task) self._show_archive_button.clicked.connect(self._show_archive) self._priority_button.toggled.connect(self._toggle_priority) self._archive_view = TasksView((Column.Name, Column.Archived), QtGui.QColor(255, 255, 255), self) self._archive_view.setWindowFlag(QtGui.Qt.Window) self._archive_view.setWindowTitle("Task Archive") self._archive_view.sortByColumn(1, QtCore.Qt.SortOrder.DescendingOrder) self._archive_view.hide() self._archive_view.delete_task_requested.connect( self._presenter.delete_task) self._archive_view.unarchive_task_requested.connect( lambda task: self._presenter.complete_task(task, False)) self._presenter.request_update() def load_from_file(self, path: Path) -> None: self._presenter.load_from_file(path) def dragEnterEvent(self, event: QtGui.QDragEnterEvent) -> None: mime_data = event.mimeData() if mime_data.hasUrls(): event.acceptProposedAction() def dropEvent(self, event: QtGui.QDropEvent) -> None: path = event.mimeData().urls()[0] task_manager_path = Path(path.toLocalFile()) self.load_from_file(task_manager_path) def hide_lists(self) -> None: self._do_list.hide() self._decide_list.hide() self._delegate_list.hide() self._drop_list.hide() self._undo_button.hide() self._redo_button.hide() self._show_archive_button.hide() def update_tasks(self, tasks: Sequence[Task]) -> None: non_archived_tasks = list(filterfalse(is_completed, tasks)) archived_tasks = filter(is_completed, tasks) for filter_func, task_list in ((_is_do_task, self._do_list), (_is_decide_task, self._decide_list), (_is_delegate_task, self._delegate_list), (_is_drop_task, self._drop_list)): task_list.show() task_list_tasks = list(filter(filter_func, non_archived_tasks)) task_list.add_tasks(task_list_tasks) archive_model = build_tree_view_model(self._archive_view.columns(), archived_tasks) self._archive_view.setModel(archive_model) self._undo_button.show() self._redo_button.show() self._show_archive_button.show() def set_undoable(self, undoable: bool) -> None: self._undo_button.setEnabled(undoable) def set_redoable(self, redoable: bool) -> None: self._redo_button.setEnabled(redoable) def _add_task(self) -> None: task = TaskCreatorDialogQt.ask_new_task(self) if task is not None: self._presenter.add_task(task) def _show_archive(self) -> None: self._archive_view.show() def _toggle_priority(self, is_toggled: bool) -> None: self._do_list.show_snoozed_tasks(not is_toggled) for task_list in (self._decide_list, self._delegate_list, self._drop_list): task_list.setHidden(is_toggled)