def new_task_accepted(self): if self._task is None: self._task = Task() self._task.set_description(self.task_entry.text()) index = self.status_entry.currentIndex() self._task.set_status(self.status_entry.itemData(index)) index = self.priority_entry.currentIndex() self._task.set_priority(self.priority_entry.itemData(index)) index = self.category_entry.currentIndex() self._task.set_category(self.category_entry.itemData(index)) self._task.set_due_date(self.due_date_entry.date().toPyDate()) if self.expected_hours_entry.text().isdigit(): self._task.set_expected_hours(int(self.expected_hours_entry.text())) else: self._task.set_expected_hours(0) if self.expected_minutes_entry.text().isdigit(): self._task.set_expected_minutes(int(self.expected_minutes_entry.text())) else: self._task.set_expected_minutes(0) self.accept()
def get_task_list(self): checklist_count_dictionary = self.get_checklist_count_dictionary() cursor = self._connection.cursor() query = "SELECT TS_ID, " \ "TS_DESCRIPTION, " \ "ST_ID, " \ "TS_ENTRY_DATE, " \ "CT_ID, " \ "PR_ID, " \ "TS_DUE_DATE, "\ "TS_EXPECTED_HOURS, " \ "TS_EXPECTED_MINUTES " \ "FROM TASKS " \ "ORDER BY TS_DUE_DATE ASC, PR_ID DESC" status_dictionary = self.get_status_dictionary() category_dictionary = self._get_category_dictionary() priority_dictionary = self.get_priority_dictionary() cursor.execute(query) task_list = [] for (ts_id, ts_description, st_id, ts_entry_date, ct_id, pr_id, ts_due_date, ts_expected_hours, ts_expected_minutes) in cursor: task = Task(id_=ts_id, description=ts_description, status=status_dictionary[st_id], entry_date=ts_entry_date, priority = priority_dictionary[pr_id], expected_hours = ts_expected_hours, expected_minutes = ts_expected_minutes) if ts_due_date is not None: task.set_due_date(ts_due_date.date()) if ct_id is not None: task.set_category(category_dictionary[ct_id]) if ts_id in checklist_count_dictionary: task.set_checklist_count(checklist_count_dictionary[ts_id]) task_list.append(task) cursor.close() return task_list
class TaskEntryDialog(QDialog): def __init__(self, task_data, task=None, parent=None): QDialog.__init__(self, parent, Qt.WindowTitleHint) self._task = task self.setWindowTitle("Add New Task") self.task_data = task_data category_label = QLabel("Category") self.category_entry = QComboBox() task_label = QLabel("Task") self.task_entry = QLineEdit() self.task_entry.setMinimumWidth(500) status_label = QLabel("Status") self.status_entry = QComboBox() self.status_entry.setMaximumWidth(100) priority_label = QLabel("Priority") self.priority_entry = QComboBox() self.priority_entry.setMaximumWidth(100) entry_date_label = QLabel("Entry Date") self.entry_date_entry = QLineEdit() self.entry_date_entry.setMaximumWidth(100) self.entry_date_entry.setReadOnly(True) due_date_label = QLabel("Due Date") self.due_date_entry = QDateEdit() self.due_date_entry.setCalendarPopup(True) self.due_date_entry.setDate(datetime.datetime.now()) expected_effort_label = QLabel("Expected Effort") expected_hours_label = QLabel("Hours") self.expected_hours_entry = QLineEdit() self.expected_hours_entry.setMaximumWidth(50) expected_minutes_label = QLabel("Minutes") self.expected_minutes_entry = QLineEdit() self.expected_minutes_entry.setMaximumWidth(50) add_button = QPushButton("Add Task") cancel_button = QPushButton("Cancel") button_layout = QHBoxLayout() button_layout.addStretch(1) button_layout.addWidget(add_button) button_layout.addWidget(cancel_button) layout = QGridLayout() layout.addWidget(category_label, 0, 0) layout.addWidget(self.category_entry, 0, 1) layout.addWidget(task_label, 1, 0) layout.addWidget(self.task_entry, 1, 1, 1, 7) layout.addWidget(status_label, 2, 0) layout.addWidget(self.status_entry, 2, 1, 1, 1) layout.addWidget(priority_label, 3, 0) layout.addWidget(self.priority_entry, 3, 1, 1, 1) layout.addWidget(entry_date_label, 4, 0) layout.addWidget(self.entry_date_entry, 4, 1, 1, 1) layout.addWidget(due_date_label, 5, 0) layout.addWidget(self.due_date_entry, 5, 1, 1, 1) layout.addWidget(expected_effort_label, 5, 3, 1, 1) layout.addWidget(self.expected_hours_entry, 5, 4, 1, 1) layout.addWidget(expected_hours_label, 5, 5, 1, 1) layout.addWidget(self.expected_minutes_entry, 5, 6, 1, 1) layout.addWidget(expected_minutes_label, 5, 7, 1, 1) layout.addLayout(button_layout, 6, 0, 1, 8) self.setLayout(layout) status_list = task_data.get_status_list() for status in status_list: self.status_entry.addItem(status.get_description(), status) priority_list = task_data.get_priority_list() for priority in priority_list: self.priority_entry.addItem(priority.get_description(), priority) category_list = task_data.get_category_list() self.category_entry.addItem("", None) enabled_category_list = [category for category in category_list if category.get_enabled()] for category in enabled_category_list: self.category_entry.addItem(category.get_description(), category) if self._task is not None: self.task_entry.setText(self._task.get_description()) index = self.status_entry.findText(self._task.get_status().get_description()) self.status_entry.setCurrentIndex(index) index = self.priority_entry.findText(self._task.get_priority().get_description()) self.priority_entry.setCurrentIndex(index) if self._task.get_category() is not None: index = self.category_entry.findText(self._task.get_category().get_description()) self.category_entry.setCurrentIndex(index) self.expected_hours_entry.setText(str(self._task.get_expected_hours())) self.expected_minutes_entry.setText(str(self._task.get_expected_minutes())) self.setWindowTitle("Edit Task") add_button.setText("Edit Task") self.entry_date_entry.setText(self._task.get_entry_date().strftime("%Y-%m-%d")) if self._task.get_due_date() is not None: self.due_date_entry.setDate(self._task.get_due_date()) else: self.entry_date_entry.setText(datetime.datetime.now().strftime("%Y-%m-%d")) add_button.clicked.connect(self.new_task_accepted) cancel_button.clicked.connect(self.new_task_rejected) def new_task_accepted(self): if self._task is None: self._task = Task() self._task.set_description(self.task_entry.text()) index = self.status_entry.currentIndex() self._task.set_status(self.status_entry.itemData(index)) index = self.priority_entry.currentIndex() self._task.set_priority(self.priority_entry.itemData(index)) index = self.category_entry.currentIndex() self._task.set_category(self.category_entry.itemData(index)) self._task.set_due_date(self.due_date_entry.date().toPyDate()) if self.expected_hours_entry.text().isdigit(): self._task.set_expected_hours(int(self.expected_hours_entry.text())) else: self._task.set_expected_hours(0) if self.expected_minutes_entry.text().isdigit(): self._task.set_expected_minutes(int(self.expected_minutes_entry.text())) else: self._task.set_expected_minutes(0) self.accept() def new_task_rejected(self): self._task = None self.reject() def get_task(self): return self._task