Example #1
0
 def expString(self):
     expString1 = self.makeString(self.root.expressions[self.var])
     numExpsString = self.makeString(self.root.getNumericalExpressions(self.var))
     if expString1 == numExpsString:
         return rewriteExpression(expString1,True)
     else:
         return "%s=%s"%(rewriteExpression(expString1,True),
                 rewriteExpression(numExpsString))
Example #2
0
 def expString(self):
     expString1 = self.makeString(self.root.expressions[self.var])
     numExpsString = self.makeString(
         self.root.getNumericalExpressions(self.var))
     if expString1 == numExpsString:
         return rewriteExpression(expString1, True)
     else:
         return "%s=%s" % (rewriteExpression(
             expString1, True), rewriteExpression(numExpsString))
Example #3
0
    def key(self, event):
        def similarity(list1, list2):
            return all(any(x in y for y in list2) for x in list1)

        # This bit is surely hackier than strictly necessary...
        if event.char.lower() in "qwertyuiopasdfghjklzxcvbnm":
            string = self.searchTextVar.get() + event.char
        elif event.char == '\x7f':
            string = self.searchTextVar.get()[:-1]
        else:
            string = self.searchTextVar.get()

        mylist = string.split()

        if self.text:
            self.delete(self.text)

        if mylist == []:
            return

        self.matches = [x for x in self.library if similarity(mylist, x[4])]

        matchesText  = "\n\n".join(unicodify(rewriteExpression(x[0]))
                                                 for x in self.matches)

        self.text = self.create_text(10, 10, text = matchesText,
                anchor="nw", font=(self.root.whiteboard.font, 24, "bold"), fill="#033",
                            tags="search")

        if event.char == '\r':
            if len(self.matches) > 0: # If they searched for something
                equation = self.matches[0]
                self.root.whiteboard.addGUIEquation(equation[1], equation[2],
                                                equation[3])
            else:
                try: # Maybe it's a number
                    val = float(string)
                    self.root.whiteboard.createNumber(val)
                    return
                except ValueError:
                    pass

                try: # Maybe it's a number with uncertainty
                    val, sigma = map(float,string.split("+-"))
                    self.root.whiteboard.createNumber(val,sigma)
                    return
                except Exception as e:
                    pass

                try: # Maybe it's a custom equation
                    lhs, rhs = string.split('=')
                    print "rptif", lhs,rhs
                    self.root.whiteboard.addGUIEquation(lhs, rhs, {})
                except Exception as e:
                    print e
                    self.root.whiteboard.write("Equation could not be parsed.")
Example #4
0
 def __init__(self,lhs,rhs):
     self.equation = s.S(lhs) - s.S(rhs)
     self.text = unicodify(rewriteExpression(lhs + "=" + rhs))
Example #5
0
    def key(self, event):
        def similarity(list1, list2):
            return all(any(x in y for y in list2) for x in list1)

        # This bit is surely hackier than strictly necessary...
        if event.char.lower() in "qwertyuiopasdfghjklzxcvbnm":
            string = self.searchTextVar.get() + event.char
        elif event.char == '\x7f':
            string = self.searchTextVar.get()[:-1]
        else:
            string = self.searchTextVar.get()

        mylist = string.split()

        if self.text:
            self.delete(self.text)

        if mylist == []:
            return

        self.matches = [x for x in self.library if similarity(mylist, x[4])]

        matchesText = "\n\n".join(
            unicodify(rewriteExpression(x[0])) for x in self.matches)

        self.text = self.create_text(10,
                                     10,
                                     text=matchesText,
                                     anchor="nw",
                                     font=(self.root.whiteboard.font, 24,
                                           "bold"),
                                     fill="#033",
                                     tags="search")

        if event.char == '\r':
            if len(self.matches) > 0:  # If they searched for something
                equation = self.matches[0]
                self.root.whiteboard.addGUIEquation(equation[1], equation[2],
                                                    equation[3])
            else:
                try:  # Maybe it's a number
                    val = float(string)
                    self.root.whiteboard.createNumber(val)
                    return
                except ValueError:
                    pass

                try:  # Maybe it's a number with uncertainty
                    val, sigma = map(float, string.split("+-"))
                    self.root.whiteboard.createNumber(val, sigma)
                    return
                except Exception as e:
                    pass

                try:  # Maybe it's a custom equation
                    lhs, rhs = string.split('=')
                    print "rptif", lhs, rhs
                    self.root.whiteboard.addGUIEquation(lhs, rhs, {})
                except Exception as e:
                    print e
                    self.root.whiteboard.write("Equation could not be parsed.")