Exemplo n.º 1
0
        def __init__(self, screen, card_type, card_set, index):
            # Initialize widget
            super().__init__()
            self.ui = Ui_FlashcardEditLine()
            self.ui.setupUi(self)

            # Get the main screen (FlashcardSetEdit)
            self.screen = screen

            # Get the set information
            self.type = card_type
            self.set = card_set
            self.index = index

            # Read the cards
            cards = read_cards()
            # Get the problem and answer
            self.problem = cards[self.type][self.set][self.index]['Problem']
            self.answer = cards[self.type][self.set][self.index]['Answer']

            # Load the images
            load_svg(self.ui.question_image, to_svg(to_latex(self.problem), 0))
            load_svg(self.ui.answer_image, to_svg(to_latex(self.answer), 0))

            # Edit buttons
            self.ui.edit_question_button.clicked.connect(
                lambda: self.edit('problem'))
            self.ui.edit_answer_button.clicked.connect(
                lambda: self.edit('answer'))
            # Remove button
            self.ui.remove_button.clicked.connect(self.remove)
Exemplo n.º 2
0
 def update_graph(self):
     """Update the graph"""
     # Get the text
     text = self.ui.function_entry.text()
     # Graph
     try:
         if len(text) == 0:
             # Blank graph
             load_svg(self.ui.graph, to_graph('0', None, self.window_size))
         else:
             # Get the checked boxes
             args = []
             if self.ui.check_zeroes.isChecked():
                 args.append('Zeroes')
             if self.ui.check_extrema.isChecked():
                 args.append('Extrema')
             if self.ui.check_inflection.isChecked():
                 args.append('Inflection')
             if self.ui.check_derivative.isChecked():
                 args.append('Derivative')
             if self.ui.check_integral.isChecked():
                 args.append('Integral')
             # Graph the function
             load_svg(self.ui.graph, to_graph(text, args, self.window_size))
     # Lots of things can go wrong with bad inputs; check for all of them
     except SympifyError:
         pass
     except TypeError:
         pass
     except ValueError:
         pass
     except IndexError:
         pass
Exemplo n.º 3
0
 def update_image(self):
     """Updates the screen's flashcard image"""
     # Get the current card
     card = self.set[self.index]
     # Setup the card if it's blank
     if card.show() is None:
         card.setup()
     # Load the image
     load_svg(self.ui.flashcard, card.show())
Exemplo n.º 4
0
    def new_problem(self):
        """Generates a new problem"""
        # Get the problem
        self.problem, self.answer = generate('Series', self.parameters, None)
        # Add the special text for series
        # Problem is in the format (problem, initial value)
        self.problem = f'sum_(n={self.problem[1]})^infty {self.problem[0]}'

        # Update image
        try:
            load_svg(self.ui.problem, to_svg(to_latex(self.problem)))
        except ValueError:
            # Since we're dealing with computer-generated problems, it's good to catch unforeseen problems
            self.new_problem()
Exemplo n.º 5
0
 def update_text(self):
     """Called whenever the text is updated"""
     # Get the text
     text = self.ui.text_entry.text()
     try:
         # Blank input
         if len(text) == 0:
             load_svg(self.ui.answer, to_svg(BLANK))
         # Not blank input
         else:
             load_svg(self.ui.answer, to_svg(to_latex(text)))
     except ValueError:
         # If there's an input error
         pass
Exemplo n.º 6
0
 def edit(self, which):
     """Edits the problem or answer for a card"""
     # Read the cards
     cards = read_cards()
     # Continue until the user inputs something valid or cancels
     while True:
         try:
             if which == 'problem':
                 # Show a dialog for the user to input a new expression
                 text, okay = Qtw.QInputDialog.getText(
                     self, 'Edit', 'Enter a new problem: ',
                     Qtw.QLineEdit.Normal, self.problem)
                 # Return if the user clicks cancel
                 if not okay:
                     return
                 # Load the image
                 load_svg(self.ui.question_image,
                          to_svg(to_latex(text), 0))
                 # Set the new problem
                 self.problem = text
                 cards[self.type][self.set][
                     self.index]['Problem'] = text
             elif which == 'answer':
                 # Show a dialog for the user to input a new expression
                 text, okay = Qtw.QInputDialog.getText(
                     self, 'Edit', 'Enter a new problem: ',
                     Qtw.QLineEdit.Normal, self.answer)
                 # Return if the user clicks cancel
                 if not okay:
                     return
                 # Load the image
                 load_svg(self.ui.answer_image,
                          to_svg(to_latex(text), 0))
                 # Set the new answer
                 self.answer = text
                 cards[self.type][self.set][self.index]['Answer'] = text
             # Save the changes to the cards
             save_cards(cards)
             break
         # If the user inputs an invalid expression
         except ValueError:
             pass
Exemplo n.º 7
0
    def new_problem(self):
        """Generates a new problem"""
        # Generate the problem
        self.problem, self.answer = generate(self.problem_type,
                                             self.parameters, self.complexity)
        # Add d/dx of int for the appropriate problem types
        if self.problem_type == 'Derivative':
            self.problem = f'd/dx ({self.problem})'
        elif self.problem_type == 'Integral':
            self.problem = f'int {self.problem} dx'

        # Update the image
        try:
            load_svg(self.ui.problem, to_svg(to_latex(self.problem)))
        except ValueError:
            # Since we're dealing with computer-generated problems, it's good to catch unforeseen problems
            self.new_problem()

        # Reset text input
        self.ui.text_entry.clear()
Exemplo n.º 8
0
 def update_text(self):
     """Called whenever the text is updated"""
     # Blank value for answer
     answer = ''
     # Get the text
     # Get the variable (and start value if applicable)
     # Get the answer
     # Give the text the extra d/dx, int, or sum
     if self.mode == 'Derivative':
         text = self.ui.text_entry_d.text()
         if len(text) > 0:
             variable = self.ui.variable_d.currentText()
             answer = calculate(self.mode, text, variable)
             text = f'd/d{variable} ({text})'
     elif self.mode == 'Integral':
         text = self.ui.text_entry_i.text()
         if len(text) > 0:
             variable = self.ui.variable_i.currentText()
             answer = calculate(self.mode,
                                text,
                                variable,
                                start=self.ui.lower_bound.text(),
                                end=self.ui.upper_bound.text())
             text = f'int {text}d{variable}'
     else:
         text = self.ui.text_entry_s.text()
         if len(text) > 0:
             variable = self.ui.variable_s.currentText()
             value = self.ui.value_s.text()
             answer = calculate(self.mode,
                                text,
                                variable,
                                value=value,
                                do_it=self.ui.button_value.isChecked())
             text = fr'sum_({variable}={value})^infty {text}'
     try:
         # Blank input
         if len(text) == 0:
             load_svg(self.ui.input, to_svg(BLANK))
             load_svg(self.ui.output, to_svg(BLANK))
         # Not blank input
         else:
             load_svg(self.ui.input, to_svg(to_latex(text)))
             load_svg(self.ui.output, to_svg(to_latex(answer)))
     except ValueError:
         # If there's an input error
         pass