Example #1
0
    def end_move(self, prev_id, new_which_id):
        """If prev_id == -1, then want to delete it.
        Returns True if all ok, False if want to delete but can't.
        If False, it puts it back in the pre-move spot,
        if True then it adds it into the 
        pass"""

        bric_id = self.move_id[0]
        bric = self.brics[bric_id]
        old_data = bric.bric_data
        name = bric.bric_name
        old_which_id = self.move_which_id

        if (prev_id == -1):
            if (self.remove_bric(self.move_id[0], old_which_id)):
                win_data.remove_bric_refs(name, old_data)
            else:
                self.move_id = []
                return False
        else:
            if (not self.remove_bric(
                    self.move_id[0], old_which_id, no_delete=True)):
                self.move_id = []
                return False
            else:
                self.insert_bric(self.move_id[0], prev_id, new_which_id)

        self.move_id = []
        win_data.update_dirty(True)
        #print "Moved bric", bric_id, "Prev:", prev_id
        #self.dump()

        return True
Example #2
0
    def end_move(self, prev_id, new_which_id):
        """If prev_id == -1, then want to delete it.
        Returns True if all ok, False if want to delete but can't.
        If False, it puts it back in the pre-move spot,
        if True then it adds it into the
        pass"""

        bric_id = self.move_id[0]
        bric = self.brics[bric_id]
        old_data = bric.bric_data
        name = bric.bric_name
        old_which_id = self.move_which_id

        if (prev_id == -1):
            if (self.remove_bric(self.move_id[0], old_which_id)):
                win_data.remove_bric_refs(name, old_data)
            else:
                self.move_id = []
                return False
        else:
            if (not self.remove_bric(self.move_id[0], old_which_id, no_delete=True)):
                self.move_id = []
                return False
            else:
                self.insert_bric(self.move_id[0], prev_id, new_which_id)

        self.move_id = []
        win_data.update_dirty(True)
        #print "Moved bric", bric_id, "Prev:", prev_id
        #self.dump()

        return True
Example #3
0
    def remove_bric(self, id, which_id, no_delete=False):
        #print "Remove",
        #self.brics[id].dump()

        prev_id = self.brics[id].prev_id[0]
        next_id = self.brics[id].next_id[0]

        # handle removing an event - it must already be the only icon in the stream
        if (prev_id == 0):
            # find which stream and remove it
            for i in range(len(self.streams)):
                if (self.streams[i] == id):
                    del self.streams[i]
                    break
            win_data.update_dirty(True)
            win_data.initialise_unused_events()

            # refresh the programming pallete
            win_data.force_redraw("ppallete")

            del self.brics[id]
            self.bric_count -= 1
            return True

        if (self.brics[id].bric_name in ('If', 'Loop')):
            # removing an EMPTY If or Loop
            # have to jump the end bit
            next_id = self.brics[next_id].next_id[0]

        if (prev_id >= 0):
            if (self.brics[prev_id].bric_name == 'If'):
                # previous bric is an if bric
                self.brics[prev_id].next_id[which_id] = next_id
            else:
                self.brics[prev_id].next_id[0] = next_id

        if (next_id >= 0):
            if (self.brics[next_id].bric_name.startswith("End")):
                # next bric is an End bric
                self.brics[next_id].prev_id[which_id] = prev_id
            else:
                self.brics[next_id].prev_id[0] = prev_id

        if (not no_delete):
            if (self.brics[id].bric_name in ('If', 'Loop')):
                del self.brics[id]
                del self.brics[id + 1]
                self.bric_count -= 2
            else:
                del self.brics[id]
                self.bric_count -= 1

        win_data.update_dirty(True)
        return True
Example #4
0
    def remove_bric(self, id, which_id, no_delete=False):
        #print "Remove",
        #self.brics[id].dump()

        prev_id = self.brics[id].prev_id[0]
        next_id = self.brics[id].next_id[0]

        # handle removing an event - it must already be the only icon in the stream
        if (prev_id == 0):
            # find which stream and remove it
            for i in range(len(self.streams)):
                if (self.streams[i] == id):
                    del self.streams[i]
                    break
            win_data.update_dirty(True)
            win_data.initialise_unused_events()

            # refresh the programming pallete
            win_data.force_redraw("ppallete")

            del self.brics[id]
            self.bric_count -= 1
            return True

        if (self.brics[id].bric_name in ('If', 'Loop')):
            # removing an EMPTY If or Loop
            # have to jump the end bit
            next_id = self.brics[next_id].next_id[0]

        if (prev_id >= 0):
            if (self.brics[prev_id].bric_name == 'If'):
                # previous bric is an if bric
                self.brics[prev_id].next_id[which_id] = next_id
            else:
                self.brics[prev_id].next_id[0] = next_id

        if (next_id >= 0):
            if (self.brics[next_id].bric_name.startswith("End")):
                # next bric is an End bric
                self.brics[next_id].prev_id[which_id] = prev_id
            else:
                self.brics[next_id].prev_id[0] = prev_id

        if (not no_delete):
            if (self.brics[id].bric_name in ('If', 'Loop')):
                del self.brics[id]
                del self.brics[id+1]
                self.bric_count -= 2
            else:
                del self.brics[id]
                self.bric_count -= 1

        win_data.update_dirty(True)
        return True
Example #5
0
    def insert_bric(self, new_id, prev_id, which_id):
        #print "Insert", new_id, prev_id, which_id
        if (new_id > 1):
            win_data.update_dirty(True)

        new_bric = self.brics[new_id]
        new_bric.prev_id[0] = prev_id

        # Handle starting a new stream
        if (prev_id <= 0):
            self.streams.append(new_id)
            new_bric.next_id[0] = -1

        else:
            if (new_bric.bric_name in ['If', 'Loop']):
                # Special processing for if and loop
                end_id = new_id + 1

                if (self.brics[prev_id].bric_name == "If"):
                    # previous bric is an if bric
                    next_id = self.brics[prev_id].next_id[which_id]
                    self.brics[prev_id].next_id[which_id] = new_id
                else:
                    next_id = self.brics[prev_id].next_id[0]
                    self.brics[prev_id].next_id[0] = new_id

                if (next_id >= 0):
                    if (self.brics[next_id].bric_name.startswith("End")):
                        # next bric is an end
                        self.brics[next_id].prev_id[which_id] = end_id
                    else:
                        self.brics[next_id].prev_id[0] = end_id

                self.brics[end_id].next_id[0] = next_id

            else:

                if (self.brics[prev_id].bric_name == "If"):
                    # previous bric is an if bric
                    next_id = self.brics[prev_id].next_id[which_id]
                    self.brics[prev_id].next_id[which_id] = new_id
                else:
                    next_id = self.brics[prev_id].next_id[0]
                    self.brics[prev_id].next_id[0] = new_id

                if (next_id >= 0):
                    if (self.brics[next_id].bric_name.startswith("End")):
                        # next bric is an end
                        self.brics[next_id].prev_id[which_id] = new_id
                    else:
                        self.brics[next_id].prev_id[0] = new_id

                new_bric.next_id[0] = next_id
Example #6
0
    def insert_bric(self, new_id, prev_id, which_id):
        #print "Insert", new_id, prev_id, which_id
        if (new_id > 1):
            win_data.update_dirty(True)

        new_bric = self.brics[new_id]
        new_bric.prev_id[0] = prev_id

        # Handle starting a new stream
        if (prev_id <= 0):
            self.streams.append(new_id)
            new_bric.next_id[0] = -1

        else:
            if (new_bric.bric_name in ['If', 'Loop']):
                # Special processing for if and loop
                end_id = new_id + 1

                if (self.brics[prev_id].bric_name == "If"):
                    # previous bric is an if bric
                    next_id = self.brics[prev_id].next_id[which_id]
                    self.brics[prev_id].next_id[which_id] = new_id
                else:
                    next_id = self.brics[prev_id].next_id[0]
                    self.brics[prev_id].next_id[0] = new_id

                if (next_id >= 0):
                    if (self.brics[next_id].bric_name.startswith("End")):
                        # next bric is an end
                        self.brics[next_id].prev_id[which_id] = end_id
                    else:
                        self.brics[next_id].prev_id[0] = end_id

                self.brics[end_id].next_id[0] = next_id

            else:

                if (self.brics[prev_id].bric_name == "If"):
                    # previous bric is an if bric
                    next_id = self.brics[prev_id].next_id[which_id]
                    self.brics[prev_id].next_id[which_id] = new_id
                else:
                    next_id = self.brics[prev_id].next_id[0]
                    self.brics[prev_id].next_id[0] = new_id

                if (next_id >= 0):
                    if (self.brics[next_id].bric_name.startswith("End")):
                        # next bric is an end
                        self.brics[next_id].prev_id[which_id] = new_id
                    else:
                        self.brics[next_id].prev_id[0] = new_id

                new_bric.next_id[0] = next_id