Exemplo n.º 1
0
    def feed_mousedown(
        self, mouse_absolute
    ):  #returns if this ui expression was selected by the click
        mouse_rel = (mouse_absolute[0] - self.rect.topleft[0],
                     mouse_absolute[1] - self.rect.topleft[1])
        if not self.rect.collidepoint(mouse_absolute):
            self.is_active = False
            return False

        xtstr.clearCursor(self.exp)
        smallestDist = 99999999999999999
        smallestExp = None
        xcoorCenter = -1
        for hb in self.surf.hitboxes:
            [irect, orect], hbExp, op_depth = hb

            acceptable_hitbox = (type(hbExp) == xp.NoOpExpression)
            ''' this cannot be implemented yet
            if type(hbExp) == xp.Expression:
                if hbExp.op.strRep == "/":
                    acceptable_hitbox = True
            '''

            if acceptable_hitbox:
                dpr = distPointRect(mouse_rel, irect)
                if dpr < smallestDist:
                    smallestDist = dpr
                    smallestExp = hbExp
                    xcoorCenter = irect.centerx

        if not smallestExp == None:
            smallestExp.cursor = True
            if mouse_rel[0] < xcoorCenter:
                smallestExp.cursor_idx = 0
            else:
                smallestExp.cursor_idx = len(
                    smallestExp.strRep
                )  #this needs to become more sophisticated later

        self.text = xtstr.expToStr(self.exp)
        self.index = self.text.index("|")
        self.text = self.text.replace("|", "")
        self.is_active = True
        return True
Exemplo n.º 2
0
 def raise_to(self, ponent):
     newexp = xp.Expression('^', [copy.copy(self.exp), ponent])
     self.exp = newexp
     self.exp.assign_parents()
     self.text = xtstr.expToStr(self.exp)
     self.text = self.text.replace("|", "")
Exemplo n.º 3
0
 def sub_from_this(self, negative):
     newexp = xp.Expression('-', [copy.copy(self.exp), negative])
     self.exp = newexp
     self.exp.assign_parents()
     self.text = xtstr.expToStr(self.exp)
     self.text = self.text.replace("|", "")
Exemplo n.º 4
0
 def sub_this_from(self, positive):
     newexp = xp.Expression('-', [positive, copy.copy(self.exp)])
     self.exp = newexp
     self.exp.assign_parents()
     self.text = xtstr.expToStr(self.exp)
     self.text = self.text.replace("|", "")
Exemplo n.º 5
0
 def add_to(self, toadd):
     newexp = xp.Expression('+', [copy.copy(self.exp), toadd])
     self.exp = newexp
     self.exp.assign_parents()
     self.text = xtstr.expToStr(self.exp)
     self.text = self.text.replace("|", "")
Exemplo n.º 6
0
 def mult_by(self, factor):
     newexp = xp.Expression('\u00B7', [copy.copy(self.exp), factor])
     self.exp = newexp
     self.exp.assign_parents()
     self.text = xtstr.expToStr(self.exp)
     self.text = self.text.replace("|", "")