Example #1
0
 def DropTreeItem(self, event):
     """ Finish a drop-and-drop for the tree """
     self._drop_node = self.treebox.GetPyData(event.GetItem())
     # Can't drop onto a child of the self._drag_node (infinite loop)
     if cf.isDescendant(self._drag_node, self._drop_node):
         event.Veto()
     else:
         # Okay, move the word
         cf.moveWord(self._drag_node, self._drop_node)
         # Refresh the tree
         self.DisplayTree(self.search_root, self.search_words,
                          select=self._drop_node)
Example #2
0
    def testMoveWord(self):
        """ Test moving a word to a different location in the tree """
        db = self.getDB()
        # Here we move ross to be a child of hross
        # First get references to the words
        num_trees, matched_words = cf.searchDB(db, "ross")
        test_source = matched_words[0][1]
        test_source_parent = cf.loadWordParents(test_source)
        num_trees, matched_words = cf.searchDB(db, "hross")
        test_dest_parent = matched_words[0][1]
        self.assertEqual(cf.countWordChildren(test_dest_parent), 0)
        # Perform the move
        cf.moveWord(test_source, test_dest_parent)
        # Make sure it really happened
        self.assertEqual(cf.countWordChildren(test_dest_parent), 1)
        self.assertEqual(cf.countWordChildren(test_source_parent), 0)
        self.assertEqual(cf.loadWordParents(test_source), test_dest_parent)

        # Let's test for some bad inputs
        self.assertRaises(cf.EtymExceptWord, cf.moveWord, None, None)
        self.assertRaises(cf.EtymExceptWord, cf.moveWord, test_source, None)
        self.assertRaises(cf.EtymExceptWord, cf.moveWord, None, test_source)

        # Another test, this time make sure the children are maintained
        # We move fearh (which has a child and a grandchild) to be a child
        # of porcus (which has two children and a few further descendants)
        db = self.getDB()
        # First get references to the words
        num_trees, matched_words = cf.searchDB(db, "fearh")
        test_source = matched_words[0][1]
        test_source_parent = cf.loadWordParents(test_source)
        num_trees, matched_words = cf.searchDB(db, "porcus")
        test_dest_parent = matched_words[0][1]
        self.assertEqual(cf.countWordChildren(test_dest_parent), 2)
        self.assertEqual(cf.countWordChildren(test_source), 1)
        # Perform the move
        cf.moveWord(test_source, test_dest_parent)
        # Make sure it really happened
        self.assertEqual(cf.countWordChildren(test_dest_parent), 3)
        self.assertEqual(cf.countWordChildren(test_source_parent), 2)
        self.assertEqual(cf.loadWordParents(test_source), test_dest_parent)
        self.assertEqual(cf.countWordChildren(test_source), 1)
        num_trees, matched_words = cf.searchDB(db, "far")
        test_dest_child = matched_words[0][1]
        self.assertEqual(cf.loadWordParents(test_dest_child), test_source)