コード例 #1
0
    def test_gather_group(self):
        """
        The tree for this test looks like:
            root
                child-1
                    grandchild-1
                child-2
            root-sibling
        utils.gather_group() should return root and all its children and
        not return root-sibling.
        """
        store = storage.MappedTreeStore({'name': str})
        root_iter = store.add_map(None, {'name': 'root'})
        store.add_map(None, {'name': 'root-sibling'})
        child_1_iter = store.add_map(root_iter, {'name': 'child-1'})
        store.add_map(root_iter, {'name': 'child-2'})
        store.add_map(child_1_iter, {'name': 'grandchild-1'})

        refs = utils.gather_group(store, root_iter, [])
        names = set()
        for r in refs:
            m = r.get_model()
            names.add(m.get_value(m.get_iter(r.get_path()), 0))
        self.assertEqual(names,
                         set(['root', 'child-1', 'child-2', 'grandchild-1']))
コード例 #2
0
    def _stripe_rows(self, column, store):
        """
        This method repaints the row stripes when the rows are re-arranged
        due to the user sorting a column
        """
        if 'background' in store:
            iter = store.get_iter_first()
            i = 0
            rows = []

            # Making changes to a TreeModel while you are iterating over it can lead
            # to weird behavior so we save all the rows that need to be recolored as
            # TreeRowReferences and set the color on them after the iteration is finished.
            while iter:
                bg_color = utils.get_cell_background_color(i)
                rows += [(ref, bg_color) for ref in utils.gather_group(store, iter, [])]
                i += 1
                iter = store.iter_next(iter)

            for r in rows:
                model = r[0].get_model()
                iter = model.get_iter(r[0].get_path())
                model.set_value(iter, model['background'], r[1])
コード例 #3
0
ファイル: widgets.py プロジェクト: Lorquas/rhsm
    def _stripe_rows(self, column, store):
        """
        This method repaints the row stripes when the rows are re-arranged
        due to the user sorting a column
        """
        if 'background' in store:
            iter = store.get_iter_first()
            i = 0
            rows = []

            # Making changes to a TreeModel while you are iterating over it can lead
            # to weird behavior so we save all the rows that need to be recolored as
            # TreeRowReferences and set the color on them after the iteration is finished.
            while iter:
                bg_color = utils.get_cell_background_color(i)
                rows += [(ref, bg_color) for ref in utils.gather_group(store, iter, [])]
                i += 1
                iter = store.iter_next(iter)

            for r in rows:
                model = r[0].get_model()
                iter = model.get_iter(r[0].get_path())
                model.set_value(iter, model['background'], r[1])
コード例 #4
0
    def test_gather_group(self):
        """
        The tree for this test looks like:
            root
                child-1
                    grandchild-1
                child-2
            root-sibling
        utils.gather_group() should return root and all its children and
        not return root-sibling.
        """
        store = storage.MappedTreeStore({'name': str})
        root_iter = store.add_map(None, {'name': 'root'})
        store.add_map(None, {'name': 'root-sibling'})
        child_1_iter = store.add_map(root_iter, {'name': 'child-1'})
        store.add_map(root_iter, {'name': 'child-2'})
        store.add_map(child_1_iter, {'name': 'grandchild-1'})

        refs = utils.gather_group(store, root_iter, [])
        names = set()
        for r in refs:
            m = r.get_model()
            names.add(m.get_value(m.get_iter(r.get_path()), 0))
        self.assertEqual(names, set(['root', 'child-1', 'child-2', 'grandchild-1']))