def __init__(self): QObject.__init__(self) self.manager = QOrganizerManager("memory") self._todos = [] # FIXME Use a model instead of a string list as model self._todo = None # Current todo being edited or created self.reload()
class TodoManager(QObject): def __init__(self): QObject.__init__(self) self.manager = QOrganizerManager("memory") self._todos = [] # FIXME Use a model instead of a string list as model self._todo = None # Current todo being edited or created self.reload() @Slot() def reload(self): self._todos = [] sortOrder = QOrganizerItemSortOrder() sortOrder.setDetailDefinitionName(QOrganizerTodoTime.DefinitionName, QOrganizerTodoTime.FieldDueDateTime) todoFilter = QOrganizerItemFilter() items = self.manager.items(todoFilter, [sortOrder]) todos = [] for item in items: if item.type() == QOrganizerItemType.TypeTodo: todo = QOrganizerTodo(item) display = todo.startDateTime().toString("yy/MM/dd hh:mm") +\ "-" + todo.dueDateTime().toString("yy/MM/dd hh:mm") +\ "\n" + todo.displayLabel() todos.append((display, todo)) self._todos = todos self.todosChanged.emit() @Slot() def deleteCurrent(self): self.manager.removeItem(self._todo.id()) self.reload() currentTodoChanged = Signal() @Slot() def editNewTodo(self): """Sets the current todo to a newly created todo""" newTodo = QOrganizerTodo() newTodo.setPriority(QOrganizerItemPriority.HighPriority) newTodo.setStatus(QOrganizerTodoProgress.StatusNotStarted) currentDateTime = QDateTime(QDate.currentDate(), QTime.currentTime()) newTodo.setStartDateTime(currentDateTime) newTodo.setDueDateTime(currentDateTime.addSecs(60 * 60)) self._todo = newTodo self._todo.isNewTodo = True self.currentTodoChanged.emit() @Property(bool, notify=currentTodoChanged) def isNewTodo(self): return self._todo.isNewTodo if self._todo else True @Slot(int) def editExistingTodo(self, index): self._todo = self._todos[index][1] self._todo.isNewTodo = False self.currentTodoChanged.emit() @Slot() def saveTodo(self): self.manager.saveItem(self._todo) self._todo = None self.reload() todosChanged = Signal() @Property("QStringList", notify=todosChanged) def todos(self): return [x[0] for x in self._todos] @todos.setter def setTodo(self, value): self._todos = value self.todosChanged.emit() # Subject currentTodoSubjectChanged = Signal() @Property(str, notify=currentTodoSubjectChanged) def todoSubject(self): return self._todo.displayLabel() @todoSubject.setter def setTodoSubject(self, value): self._todo.setDisplayLabel(value) self.currentTodoSubjectChanged.emit() # Dates and times def datetimeToStrList(self, datetime): date = datetime.date() time = datetime.time() return (("%02d " * 5) % (date.year(), date.month(), date.day(), time.hour(), time.minute())).split() # @Slot(result="QStringList") @Property("QStringList", notify=currentTodoChanged) def todoStartDateTime(self): return self.datetimeToStrList(self._todo.startDateTime()) @Slot(int, int, int) def setTodoStartDate(self, year, month, day): orig_time = self._todo.startDateTime().time() date = QDate(year, month, day) datetime = QDateTime(date, orig_time) self._todo.setStartDateTime(datetime) self.currentTodoChanged.emit() @Slot(int, int) def setTodoStartTime(self, hour, minute): orig_date = self._todo.startDateTime().date() time = QTime(hour, minute) datetime = QDateTime(orig_date, time) self._todo.setStartDateTime(datetime) self.currentTodoChanged.emit() @Property("QStringList", notify=currentTodoChanged) def todoDueDateTime(self): return self.datetimeToStrList(self._todo.dueDateTime()) @Slot(int, int, int) def setTodoDueDate(self, year, month, day): orig_time = self._todo.dueDateTime().time() date = QDate(year, month, day) datetime = QDateTime(date, orig_time) self._todo.setDueDateTime(datetime) self.currentTodoChanged.emit() @Slot(int, int) def setTodoDueTime(self, hour, minute): orig_date = self._todo.dueDateTime().date() time = QTime(hour, minute) datetime = QDateTime(orig_date, time) self._todo.setDueDateTime(datetime) self.currentTodoChanged.emit() # Status Status = [ QOrganizerTodoProgress.StatusNotStarted, QOrganizerTodoProgress.StatusInProgress, QOrganizerTodoProgress.StatusComplete, ] @Property(int, notify=currentTodoChanged) def todoStatus(self): status = self._todo.status() try: index = self.Status.index(status) return index except ValueError: return 0 @todoStatus.setter def setTodoStatus(self, value): try: self._todo.setStatus(self.Status[value]) self.currentTodoChanged.emit() except IndexError: pass # Fail silently... # Priority Priority = [ QOrganizerItemPriority.UnknownPriority, QOrganizerItemPriority.HighestPriority, QOrganizerItemPriority.ExtremelyHighPriority, QOrganizerItemPriority.VeryHighPriority, QOrganizerItemPriority.HighPriority, QOrganizerItemPriority.MediumPriority, QOrganizerItemPriority.LowPriority, QOrganizerItemPriority.VeryLowPriority, QOrganizerItemPriority.ExtremelyLowPriority, QOrganizerItemPriority.LowestPriority, ] @Property(int, notify=currentTodoChanged) def todoPriority(self): priority = self._todo.priority() try: index = self.Priority.index(priority) return index except ValueError: return 0 @todoPriority.setter def setTodoPriority(self, value): try: self._todo.setPriority(self.Priority[value]) self.currentTodoChanged.emit() except IndexError: pass # Fail silently...
class TodoManager(QObject): def __init__(self): QObject.__init__(self) self.manager = QOrganizerManager("memory") self._todos = [] # FIXME Use a model instead of a string list as model self._todo = None # Current todo being edited or created self.reload() @Slot() def reload(self): self._todos = [] sortOrder = QOrganizerItemSortOrder() sortOrder.setDetailDefinitionName(QOrganizerTodoTime.DefinitionName, QOrganizerTodoTime.FieldDueDateTime) todoFilter = QOrganizerItemFilter() items = self.manager.items(todoFilter, [sortOrder]) todos = [] for item in items: if item.type() == QOrganizerItemType.TypeTodo: todo = QOrganizerTodo(item) display = todo.startDateTime().toString("yy/MM/dd hh:mm") +\ "-" + todo.dueDateTime().toString("yy/MM/dd hh:mm") +\ "\n" + todo.displayLabel() todos.append((display, todo)) self._todos = todos self.todosChanged.emit() @Slot() def deleteCurrent(self): self.manager.removeItem(self._todo.id()) self.reload() currentTodoChanged = Signal() @Slot() def editNewTodo(self): """Sets the current todo to a newly created todo""" newTodo = QOrganizerTodo() newTodo.setPriority(QOrganizerItemPriority.HighPriority) newTodo.setStatus(QOrganizerTodoProgress.StatusNotStarted) currentDateTime = QDateTime(QDate.currentDate(), QTime.currentTime()) newTodo.setStartDateTime(currentDateTime) newTodo.setDueDateTime(currentDateTime.addSecs(60*60)) self._todo = newTodo self._todo.isNewTodo = True self.currentTodoChanged.emit() @Property(bool, notify=currentTodoChanged) def isNewTodo(self): return self._todo.isNewTodo if self._todo else True @Slot(int) def editExistingTodo(self, index): self._todo = self._todos[index][1] self._todo.isNewTodo = False self.currentTodoChanged.emit() @Slot() def saveTodo(self): self.manager.saveItem(self._todo) self._todo = None self.reload() todosChanged = Signal() @Property("QStringList", notify=todosChanged) def todos(self): return [x[0] for x in self._todos] @todos.setter def setTodo(self, value): self._todos = value self.todosChanged.emit() # Subject currentTodoSubjectChanged = Signal() @Property(str, notify=currentTodoSubjectChanged) def todoSubject(self): return self._todo.displayLabel() @todoSubject.setter def setTodoSubject(self, value): self._todo.setDisplayLabel(value) self.currentTodoSubjectChanged.emit() # Dates and times def datetimeToStrList(self, datetime): date = datetime.date() time = datetime.time() return (("%02d "*5) % (date.year(), date.month(), date.day(), time.hour(), time.minute())).split() # @Slot(result="QStringList") @Property("QStringList", notify=currentTodoChanged) def todoStartDateTime(self): return self.datetimeToStrList(self._todo.startDateTime()) @Slot(int, int, int) def setTodoStartDate(self, year, month, day): orig_time = self._todo.startDateTime().time() date = QDate(year, month, day) datetime = QDateTime(date, orig_time) self._todo.setStartDateTime(datetime) self.currentTodoChanged.emit() @Slot(int, int) def setTodoStartTime(self, hour, minute): orig_date = self._todo.startDateTime().date() time = QTime(hour, minute) datetime = QDateTime(orig_date, time) self._todo.setStartDateTime(datetime) self.currentTodoChanged.emit() @Property("QStringList", notify=currentTodoChanged) def todoDueDateTime(self): return self.datetimeToStrList(self._todo.dueDateTime()) @Slot(int, int, int) def setTodoDueDate(self, year, month, day): orig_time = self._todo.dueDateTime().time() date = QDate(year, month, day) datetime = QDateTime(date, orig_time) self._todo.setDueDateTime(datetime) self.currentTodoChanged.emit() @Slot(int, int) def setTodoDueTime(self, hour, minute): orig_date = self._todo.dueDateTime().date() time = QTime(hour, minute) datetime = QDateTime(orig_date, time) self._todo.setDueDateTime(datetime) self.currentTodoChanged.emit() # Status Status = [ QOrganizerTodoProgress.StatusNotStarted, QOrganizerTodoProgress.StatusInProgress, QOrganizerTodoProgress.StatusComplete, ] @Property(int, notify=currentTodoChanged) def todoStatus(self): status = self._todo.status() try: index = self.Status.index(status) return index except ValueError: return 0 @todoStatus.setter def setTodoStatus(self, value): try: self._todo.setStatus(self.Status[value]) self.currentTodoChanged.emit() except IndexError: pass # Fail silently... # Priority Priority = [ QOrganizerItemPriority.UnknownPriority, QOrganizerItemPriority.HighestPriority, QOrganizerItemPriority.ExtremelyHighPriority, QOrganizerItemPriority.VeryHighPriority, QOrganizerItemPriority.HighPriority, QOrganizerItemPriority.MediumPriority, QOrganizerItemPriority.LowPriority, QOrganizerItemPriority.VeryLowPriority, QOrganizerItemPriority.ExtremelyLowPriority, QOrganizerItemPriority.LowestPriority, ] @Property(int, notify=currentTodoChanged) def todoPriority(self): priority = self._todo.priority() try: index = self.Priority.index(priority) return index except ValueError: return 0 @todoPriority.setter def setTodoPriority(self, value): try: self._todo.setPriority(self.Priority[value]) self.currentTodoChanged.emit() except IndexError: pass # Fail silently...