Exemplo n.º 1
0
    def isClicked(self, xy):        
        ## first things first, we need to change the xy point from a coordinate on the entire screen
        # to a coordinate relative to the top left of the scrollable window box

        x,y = xy
        y -= self.rect.top
        xy = x,y
        
        for sprite in self.allElements:
            if sprite.getRect().collidepoint(xy):
                # each "element" will be equipped with collidePoint
                buttonClicked = sprite.collideButtons(xy)
                #print "Relative Position is: ", xy                
                
                if buttonClicked == None:
                    return
                else:
                    # a list of the ID values in sprite
                    # if identity is delete it will also have a number
                    # seperated by a space, of the reference to be deleted
                    parseID = buttonClicked.getIdentity().split()
            
                    # if the parseID is just 1, then the button is for a change
                    # in state, and we need to return immediately and tell the main program
                    # this information
                    if len(parseID) == 1:
                        return parseID
                    
                    else:
                        # state contains a reference number , meaning we have
                        # to do something within this state
    
                        ### need to enforce strict discipline on names                        
                        command = parseID[0].split("@")
                            
                        recipeID = command[1]
                        for i in range(1,len(parseID)):
                            recipeID += " " + parseID[i]

                        ## if we are expanding the button, we need to also send
                        # the recipe information so it can be put on the screen
                        recipeInfo = None
                        if command[0] == "expand":
                            command[1] = recipeID
                            return command
                        elif command[0] == "unExpand":
                            self.removeElement(recipeID, "textBlock")
                            return None
                        elif command[0] == "addToGroceryList" or command[0] == "removeFromGroceryList":
                            command[1] = recipeID
                            sprite.toggleButton("groceryButton")
                            self.redrawAll()
                            return command

        # default behavior for this, returns None if no buttons were hit or w.e
        return None        
Exemplo n.º 2
0
    def addTextBlock(self, name, data):
        ## name is the name of recipe this textBlock refers to
        # should be able to find that name within the list of allElements

        # first we find the row that has the name of the recipe data we are adding
        for i,sprite in enumerate(self.allElements):
            if sprite.getName() == name:
                sprite.toggleButton( "expand")
                i += 1
                break

        # add the recipe data textBlock right after that row,@ sprite.rect. bottom
        newTextBlock = TextBlock(name, data, self.theFont,
                                 sprite.getRect().bottom + self.CURSOR_BORDER_INCREMENT)

        for counter in range(i,len(self.allElements)):
            #print self.allElements[counter], " @ ", self.allElements[counter].getRect().top,
            self.allElements[counter].updateY(newTextBlock.get_height() + self.CURSOR_BORDER_INCREMENT)

        self.allElements.insert(i, newTextBlock)
        self.redrawAll()