예제 #1
0
파일: looper.py 프로젝트: frmdstryr/enamlx
    def refresh_items(self):
        """ Refresh the items of the pattern.

        This method destroys the old items and creates and initializes
        the new items.

        """
        old_items = self.items[:]# if self._dirty else []
        old_iter_data = self._iter_data# if self._dirty else {}
        iterable = self.windowed_iterable
        pattern_nodes = self.pattern_nodes
        new_iter_data = sortedmap()
        new_items = []

        if iterable is not None and len(pattern_nodes) > 0:
            for loop_index, loop_item in enumerate(iterable):
                iteration = old_iter_data.get(loop_item)
                if iteration is not None:
                    new_iter_data[loop_item] = iteration
                    new_items.append(iteration)
                    old_items.remove(iteration)
                    continue
                iteration = []
                new_iter_data[loop_item] = iteration
                new_items.append(iteration)
                for nodes, key, f_locals in pattern_nodes:
                    with new_scope(key, f_locals) as f_locals:
                        f_locals['loop_index'] = loop_index
                        f_locals['loop_item'] = loop_item
                        for node in nodes:
                            child = node(None)
                            if isinstance(child, list):
                                iteration.extend(child)
                            else:
                                iteration.append(child)
        
        # Add to old items list
        #self.old_items.extend(old_items)
        
        #if self._dirty:
        for iteration in old_items:
            for old in iteration:
                if not old.is_destroyed:
                    old.destroy()

        if len(new_items) > 0:
            expanded = []
            recursive_expand(sum(new_items, []), expanded)
            self.parent.insert_children(self, expanded)

        self.items = new_items# if self._dirty else new_items+old_items
        self._iter_data = new_iter_data
예제 #2
0
파일: looper.py 프로젝트: Tillsten/enamlx
    def refresh_items(self):
        """ Refresh the items of the pattern.

        This method destroys the old items and creates and initializes
        the new items.

        """
        old_items = self.items[:]  # if self._dirty else []
        old_iter_data = self._iter_data  # if self._dirty else {}
        iterable = self.windowed_iterable
        pattern_nodes = self.pattern_nodes
        new_iter_data = sortedmap()
        new_items = []

        if iterable is not None and len(pattern_nodes) > 0:
            for loop_index, loop_item in enumerate(iterable):
                iteration = old_iter_data.get(loop_item)
                if iteration is not None:
                    new_iter_data[loop_item] = iteration
                    new_items.append(iteration)
                    old_items.remove(iteration)
                    continue
                iteration = []
                new_iter_data[loop_item] = iteration
                new_items.append(iteration)
                for nodes, key, f_locals in pattern_nodes:
                    with new_scope(key, f_locals) as f_locals:
                        f_locals['loop_index'] = loop_index
                        f_locals['loop_item'] = loop_item
                        for node in nodes:
                            child = node(None)
                            if isinstance(child, list):
                                iteration.extend(child)
                            else:
                                iteration.append(child)

        # Add to old items list
        #self.old_items.extend(old_items)

        #if self._dirty:
        for iteration in old_items:
            for old in iteration:
                if not old.is_destroyed:
                    old.destroy()

        if len(new_items) > 0:
            expanded = []
            recursive_expand(sum(new_items, []), expanded)
            self.parent.insert_children(self, expanded)

        self.items = new_items  # if self._dirty else new_items+old_items
        self._iter_data = new_iter_data
예제 #3
0
파일: looper.py 프로젝트: frmdstryr/enamlx
 def insert_item(self,loop_index,loop_item):
     
     iteration = []
     self._iter_data[loop_item] = iteration
     for nodes, key, f_locals in self.pattern_nodes:
         with new_scope(key, f_locals) as f_locals:
             f_locals['loop_index'] = loop_index
             f_locals['loop_item'] = loop_item
             for node in nodes:
                 child = node(None)
                 if isinstance(child, list):
                     iteration.extend(child)
                 else:
                     iteration.append(child)
     
     expanded = []
     recursive_expand(sum([iteration], []), expanded)
     # Where do I insert it!
     self.parent.insert_children(self, expanded)
     
     self.items.insert(loop_index,iteration)
예제 #4
0
파일: looper.py 프로젝트: Tillsten/enamlx
    def insert_item(self, loop_index, loop_item):

        iteration = []
        self._iter_data[loop_item] = iteration
        for nodes, key, f_locals in self.pattern_nodes:
            with new_scope(key, f_locals) as f_locals:
                f_locals['loop_index'] = loop_index
                f_locals['loop_item'] = loop_item
                for node in nodes:
                    child = node(None)
                    if isinstance(child, list):
                        iteration.extend(child)
                    else:
                        iteration.append(child)

        expanded = []
        recursive_expand(sum([iteration], []), expanded)
        # Where do I insert it!
        self.parent.insert_children(self, expanded)

        self.items.insert(loop_index, iteration)