def test_remove_selected_with_filter(self):
        dicts = [{"key1_1": "val1_1", "key1_2": "val1_2", "key1_3": "val1_3"},
                 {"key1_1": "val2_1", "key1_2": "val2_2", "key1_3": "val2_3"},
                 {"key1_1": "val3_1", "key1_2": "val3_2", "key1_3": "val3_3"},
                 {"key1_1": "val4_1", "key1_2": "val4_2", "key1_3": "val4_3"},
                 {"key1_1": "val5_1", "key1_2": "val5_2", "key1_3": "val5_3"}]
        grid = DictionaryGrid(dicts)
        grid_filter = GridFilter(grid)
        filter_row = grid_filter.rows[0]
        filter_combo = filter_row.get_children()[1].get_children()[0].get_children()[0]
        filter_combo.set_active(1)
        entry = filter_row.get_children()[1].get_children()[0].get_children()[1]
        entry.set_text("val5_1")
                
        selection = grid.get_selection()
        selection.select_path((1,))
        selection.select_path((2,))

        grid.remove_selected_rows()

        self.assertEqual(len(grid.get_model()),2)
Пример #2
0
    def test_remove_selected_rows(self):
        dicts = [{
            "key1_1": "val1_1",
            "key1_2": "val1_2",
            "key1_3": "val1_3"
        }, {
            "key1_1": "val2_1",
            "key1_2": "val2_2",
            "key1_3": "val2_3"
        }, {
            "key1_1": "val3_1",
            "key1_2": "val3_2",
            "key1_3": "val3_3"
        }, {
            "key1_1": "val4_1",
            "key1_2": "val4_2",
            "key1_3": "val4_3"
        }, {
            "key1_1": "val5_1",
            "key1_2": "val5_2",
            "key1_3": "val5_3"
        }]

        grid = DictionaryGrid(dicts)
        selection = grid.get_selection()
        grid.remove_selected_rows()

        #select the last row and remove it
        selection.select_path((4, ))
        grid.remove_selected_rows()

        #the last row should then be selected and there should be 4 rows now
        self.assertEqual(len(grid.get_model()), 4)
        self.assertEqual(len(grid.selected_rows), 1)
        self.assertEqual(grid.selected_rows[0]["key1_1"], "val4_1")

        #select the first and third rows and remove them
        selection = grid.get_selection()
        selection.unselect_all()
        selection.select_path((0, ))
        selection.select_path((2, ))
        grid.remove_selected_rows()

        #make sure the now last row is selected, and there are 2 rows left
        self.assertEqual(len(grid.get_model()), 2)
        self.assertEqual(len(grid.selected_rows), 1)
        self.assertEqual(grid.selected_rows[0]["key1_2"], "val4_2")
Пример #3
0
 def remove_selected_rows(self, delete=False):
     rows_to_delete = self.selected_rows
     if delete:
         for r in rows_to_delete:
             self.database.delete_record(r["__desktopcouch_id"])
     DictionaryGrid.remove_selected_rows(self)