Exemple #1
0
    def showCalendar(self):
        """
        Shows a calendar with current date
        :return: CalendarWidget()
        """
        logging.debug("Showing calendar")
        header = self.app.layout_props.getDefaultHeaderColorLight()
        select = self.app.layout_props.getDefaultSelectColor()
        calendar = CalendarWidget(header, select)

        setting_hint = "hints/showCalendarReminderHint"
        should_show_hint = not self.settings.contains(
            setting_hint) or self.settings.value(setting_hint) is True
        logging.info("%s: %s", setting_hint, str(should_show_hint))
        if should_show_hint:
            hint = DialogBuilder(calendar, "Setting Reminders",
                                 "Hint: Select a date to create a Reminder!")
            hint.addButtonBox(QDialogButtonBox(QDialogButtonBox.Ok))
            hint.exec()
            self.settings.setValue(setting_hint, not should_show_hint)

        def onCalendarReminder():
            """
            Creates a calendar reminder
            """
            date: QDate = calendar.selectedDate()
            logging.info(date.toString("MM-dd-yyyy"))
            self.app.reminders.showDialog(calendar, False, date)

        calendar.selectionChanged.connect(onCalendarReminder)

        dialog = DialogBuilder()
        dialog.addWidget(calendar)
        dialog.layout().setContentsMargins(0, 0, 0, 0)
        dialog.setMinimumWidth(int(dialog.width() / 1.2))
        dialog.setMinimumHeight(int(dialog.height() / 1.2))
        dialog.exec()
Exemple #2
0
    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")
Exemple #3
0
class EquationEditorWidget(QWidget):
    """
    This is a widget is an interactive editor for the user to create and insert equations
    using latex
    """

    def __init__(self, document):
        """
        initializes the widgets
        :param document: reference to the the document
        :return: returns nothing
        """
        logging.debug("")
        super().__init__()

        # initialize variables
        self.document = document
        self.url = "https://latex.codecogs.com/gif.latex?\\dpi{200}"
        self.pixmap = None
        self.equation = None
        self.equation_bar = None
        self.user_query = ""

        # create the QDialog and fill it in
        self.dialog = DialogBuilder(document)
        self.initUI()
        self.dialog.exec()

    def initUI(self):
        """
        sets up the layout of the widget
        """
        # creates the label to show what the user is working on
        self.equation = QLabel()
        self.dialog.addWidget(self.equation)

        # creates the qlineedit the user types into
        self.equation_bar = QLineEdit()
        self.dialog.addWidget(self.equation_bar)

        # widget to contain buttons
        widget = QWidget()
        hbox = QHBoxLayout(widget)

        # button to quit dialogs
        cancel = QPushButton("Cancel")
        cancel.clicked.connect(self.dialog.close)
        hbox.addWidget(cancel)

        # button to refresh the equation
        generate = QPushButton("Generate")
        generate.clicked.connect(self.onGenerate)
        hbox.addWidget(generate)

        # button to insert equation into the document
        insert = QPushButton("Insert")
        insert.clicked.connect(self.onInsert)
        hbox.addWidget(insert)

        self.dialog.addWidget(widget)

    def onGenerate(self):
        """
        Generates the image from the users input.
        """
        logging.info("User Generated Equation")

        if self.user_query != self.equation_bar.text():
            self.user_query = self.equation_bar.text()
            # get the formatted equation from the web api
            req = requests.get(self.url + self.equation_bar.text())
            # convert the image to a pixmap and display it to the user through the qlabel
            img = QImage()
            img.loadFromData(req.content)
            self.pixmap = QPixmap(img)
            self.equation.setPixmap(self.pixmap)

    def onInsert(self):
        """
        When the user selects to insert the image.
        """
        # generate the image if it has not been yet
        self.onGenerate()

        # if the pixmap is not none insert it to the document
        if self.pixmap is not None:
            logging.info("Inserted Equation")
            cursor = self.document.textCursor()

            # scale the pixmap and get its image
            font_size = self.document.currentCharFormat().fontPointSize()
            self.pixmap = self.pixmap.scaledToHeight(font_size + 35, Qt.SmoothTransformation)
            img = self.pixmap.toImage()

            # add the image to the document and close the prompt
            cursor.insertImage(img)
            self.dialog.close()
        else:
            logging.warning("No Pixmap Found")