def fail(): """ Failure pop-up for reminder """ dialog_rem_error = DialogBuilder(self.app, "Error") dialog_rem_error.setTitleText("Failed to remove reminder") dialog_buttons = QDialogButtonBox(QDialogButtonBox.Ok) dialog_rem_error.addButtonBox(dialog_buttons) dialog_rem_error.show()
def deleteReminder(key): """ Delete pop-up for reminder """ if key not in self.app.reminders.rem_list: logging.error("%s not in reminders list", key) fail() return title = self.app.reminders.rem_list[key]['title'] dialog = DialogBuilder(self.app, "Delete Reminder") dialog.setTitleText("Remove '" + title + "'?") dialog.setMsgText("This will permanently remove it from your reminders list.") dialog_but = QDialogButtonBox(QDialogButtonBox.Cancel | QDialogButtonBox.Yes) dialog.addButtonBox(dialog_but) if dialog.exec(): if not self.app.reminders.deleteReminder(key): logging.error("Could not remove reminder key %s", key) fail() else: logging.info("User chose to not delete the reminder")
def showDialog(self, block, show_calendar: bool = True, date: QDate = None): """ this will show the user a dialog of the the reminders :param block: Element to block by dialog :param show_calendar: Whether to include calendar or not :param date: Pre-defined date if calendar is not shown """ logging.info("showDialog: displays reminders dialog") # Set the default date format format_date_def: str = "yyyy-MM-dd" # ------------------------------# input_title = QLineEdit() input_title.setPlaceholderText("Title") # ------------------------------# # ------------------------------# # QPlain text edit allows text on multiple lines input_description = QPlainTextEdit() input_description.setMaximumHeight(120) def limitCharCount(): """ Limits the maximum number of characters allowed in description box """ # Limits the number of characters in input_description box text_content = input_description.toPlainText() length = len(text_content) max_length = 150 if length > max_length: logging.info("Description too long!") # Get the cursor and position cursor = input_description.textCursor() position = cursor.position() # Strip the text and set new_text = text_content[:max_length] input_description.setPlainText(new_text) # Restore cursor position cursor.setPosition(position - 1) input_description.setTextCursor(cursor) # Assign text limit listener input_description.textChanged.connect(limitCharCount) input_description.setPlaceholderText("Description") # ------------------------------# # ------------------------------# input_calendar = CalendarWidget() input_time = QTimeEdit() def updateTitle(): """ Updates title of the dialog box to selected date and time """ new_date: QDate = input_calendar.selectedDate() formatted_date = new_date.toString(format_date_def) new_time: QTime = input_time.time() formatted_time = new_time.toString("h:mm ap") new_title = formatted_date + " at " + formatted_time logging.debug("Update input_title %s", new_title) dialog.setTitleText(new_title) input_calendar.setFixedHeight(300) input_calendar.selectionChanged.connect(updateTitle) input_time.timeChanged.connect(updateTitle) # initial update of title with default values # ------------------------------# dialog = DialogBuilder(block, "Add reminder") dialog.addWidget(input_title) dialog.addWidget(input_description) # Determine whether to use calendar in dialog or not if show_calendar is True or date is None: dialog.addWidget(input_calendar) else: input_calendar.setSelectedDate(date) dialog.addWidget(input_time) updateTitle() button_box = QDialogButtonBox(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) dialog.addButtonBox(button_box) # Set size constrains for looks dialog.setFixedWidth(input_calendar.sizeHint().width()) dialog.setFixedHeight(dialog.sizeHint().height()) if dialog.exec(): if len(input_title.text()) != 0: if date is None: date = input_calendar.selectedDate() self.addReminder(date, input_time.text(), input_title.text(), input_description.toPlainText()) else: dialog_rem_error = DialogBuilder(block, "Error") dialog_rem_error.setTitleText( "This reminder does not have a title") dialog_rem_error.setMsgText("Reminder must contain a title.") dialog_buttons = QDialogButtonBox(QDialogButtonBox.Ok) dialog_rem_error.addButtonBox(dialog_buttons) # dialog_rem_error.show() if dialog_rem_error.exec(): self.showDialog(None, None, None) else: logging.info("Clicked cancel")