Пример #1
0
 def draw(self):
     self.varsString, self.opsString = splitStrings(self.text)
     if self.varsTextID is not None:
         self.root.delete(self.varsTextID)
         self.root.delete(self.opsTextID)
     self.varsTextID = self.root.create_text((self.x,self.y),
         text =unicodify(self.varsString),
              fill = "#066",
                 font = (self.root.font, self.root.textSize+2, "bold"))
     self.opsTextID = self.root.create_text((self.x,self.y),
         text =unicodify(self.opsString), tags = ("Draggable", "Equation",
             self.tagString),
                 font = (self.root.font, self.root.textSize+2, "normal"))
Пример #2
0
 def draw(self):
     self.varsString, self.opsString = splitStrings(self.text)
     if self.varsTextID is not None:
         self.root.delete(self.varsTextID)
         self.root.delete(self.opsTextID)
     self.varsTextID = self.root.create_text(
         (self.x, self.y),
         text=unicodify(self.varsString),
         fill="#066",
         font=(self.root.font, self.root.textSize + 2, "bold"))
     self.opsTextID = self.root.create_text(
         (self.x, self.y),
         text=unicodify(self.opsString),
         tags=("Draggable", "Equation", self.tagString),
         font=(self.root.font, self.root.textSize + 2, "normal"))
Пример #3
0
 def draw(self):
     if self.textID is None:
         self.textID = self.root.create_text(
             (self.x, self.y),
             text=unicodify(self.valString),
             fill="#C00633",
             tags="Draggable",
             font=(self.root.font, self.root.textSize - 4, "bold"))
Пример #4
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.")
Пример #5
0
    def draw(self):
        if self.varsTextID:
            self.root.delete(self.varsTextID)
            self.root.delete(self.opsTextID)

        self.text = self.var+"="+self.expString()
        self.text = unicodify(self.text,False)

        varsString, opsString = splitStrings(self.text)

        self.varsTextID = self.root.create_text((self.x,self.y),
            text = varsString,
                fill = "#CC6633", tags = "Draggable",
                    font = (self.root.font, self.root.textSize-2, "bold"))

        self.opsTextID = self.root.create_text((self.x,self.y),
            text = opsString,
                fill = "#000", tags = ("Draggable",self.tagString),
                    font = (self.root.font, self.root.textSize-2, "normal"))
Пример #6
0
    def draw(self):
        if self.varsTextID:
            self.root.delete(self.varsTextID)
            self.root.delete(self.opsTextID)

        self.text = self.var + "=" + self.expString()
        self.text = unicodify(self.text, False)

        varsString, opsString = splitStrings(self.text)

        self.varsTextID = self.root.create_text(
            (self.x, self.y),
            text=varsString,
            fill="#CC6633",
            tags="Draggable",
            font=(self.root.font, self.root.textSize - 2, "bold"))

        self.opsTextID = self.root.create_text(
            (self.x, self.y),
            text=opsString,
            fill="#000",
            tags=("Draggable", self.tagString),
            font=(self.root.font, self.root.textSize - 2, "normal"))
Пример #7
0
 def draw(self):
     if self.textID is None:
         self.textID = self.root.create_text((self.x,self.y),
             text = unicodify(self.valString),
                 fill = "#C00633", tags = "Draggable",
                     font = (self.root.font, self.root.textSize-4, "bold"))
Пример #8
0
 def __init__(self,lhs,rhs):
     self.equation = s.S(lhs) - s.S(rhs)
     self.text = unicodify(rewriteExpression(lhs + "=" + rhs))
Пример #9
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.")