def main(): app = QtGui.QApplication(sys.argv) dialog = lambda: QtGui.QMessageBox.question(QtGui.QWidget(), 'First time', \ "It appears you've started the app for the first time. Do you want to load demo data?", QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) DBManager.init_dbmanager(dialog) main = Main() main.show() sys.exit(app.exec_())
def _fill_inbox(self): self._inbox.clear() projects = {project.id: None for project in DBManager.get_projects().values()} for action in DBManager.get_actions().values(): if action.project and not action.completed and action.sched.isValid(): if len(projects) > action.project.id: if not projects[action.project.id] or projects[action.project.id].sched < action.sched: projects[action.project.id] = action for action in projects.values(): if action: item = QtGui.QListWidgetItem(action.desc) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(action)) self._inbox.addItem(item)
def _fill_detail(self, date): self._detail_list.clear() for action in DBManager.get_actions().values(): if action.sched == date and not action.completed: item = QtGui.QListWidgetItem(action.desc) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(action)) self._detail_list.addItem(item)
def _fill_list(self): self._completed.clear() for action in DBManager.get_actions().values(): if action.completed: item = QtGui.QListWidgetItem(action.desc) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(action)) self._completed.addItem(item)
def _fill_inbox(self): self._inbox.clear() for action in DBManager.get_actions().values(): if not action.completed: item = QtGui.QListWidgetItem(action.desc) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(action)) self._inbox.addItem(item)
def _fill_inbox(self): self._inbox.clear() projects = { project.id: None for project in DBManager.get_projects().values() } for action in DBManager.get_actions().values(): if action.project and not action.completed and action.sched.isValid( ): if len(projects) > action.project.id: if not projects[action.project.id] or projects[ action.project.id].sched < action.sched: projects[action.project.id] = action for action in projects.values(): if action: item = QtGui.QListWidgetItem(action.desc) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(action)) self._inbox.addItem(item)
def _fill_tree(self): actions = self._get_actions() self._tree.clear() for context in DBManager.get_contexts().values(): item = self._get_context_item(context) for action in actions[context.id]: if not action.completed: child_item = self._get_action_item(action) item.addChild(child_item) self._tree.addTopLevelItem(item)
def _fill_tree(self): actions = self._get_actions() self._tree.clear() for project in DBManager.get_projects().values(): item = self._get_project_item(project) item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(project)) for action in actions[project.id]: if not action.completed: child_item = self._get_action_item(action) item.addChild(child_item) self._tree.addTopLevelItem(item)
def paintCell(self, painter, rect, date): QtGui.QCalendarWidget.paintCell(self, painter, rect, date) brush = QtGui.QBrush(QtGui.QColor("#FFF380")) white_brush = QtGui.QBrush(QtGui.QColor("#FFFFFF")) task_number = 0 for action in DBManager.get_actions().values(): if action.sched == date and not action.completed: task_number += 1 if task_number: label = ("%s task" if task_number == 1 else "%s tasks") % task_number painter.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.StyleItalic)) text_format = QtGui.QTextCharFormat(self.dateTextFormat(date)) text_format.setBackground(brush) self.setDateTextFormat(date, text_format) painter.drawText(rect, QtCore.Qt.AlignCenter + QtCore.Qt.AlignBottom, label) else: text_format = QtGui.QTextCharFormat(self.dateTextFormat(date)) text_format.setBackground(white_brush) self.setDateTextFormat(date, text_format)
def delete(self): DBManager.delete_project(self)
def save(self): if not self.id: DBManager.create_project(self) else: DBManager.update_project(self)
def _fill_cbx(self): self._context_cbx.clear() self._context_cbx.addItem("None", QtCore.QVariant()) for context in DBManager.get_contexts().values(): self._context_cbx.addItem(context.name, QtCore.QVariant(context))
def delete(self): DBManager.delete_context(self)
def delete(self): DBManager.delete_action(self)
def save(self): if not self.id: DBManager.create_action(self) else: DBManager.update_action(self)
def save(self): if not self.id: DBManager.create_context(self) else: DBManager.update_context(self)
def _get_actions(self): actions = defaultdict(list) for action in DBManager.get_actions().values(): if action.context: actions[action.context.id].append(action) return actions
def _fill_projects(self): self._project_cbx.clear() self._project_cbx.addItem("None", QtCore.QVariant()) for project in DBManager.get_projects().values(): self._project_cbx.addItem(project.name, QtCore.QVariant(project))