Beispiel #1
0
    def set_input(self) -> None:
        """Handler for the input button."""
        try:
            dialog = QFileDialog()
            dialog.setFileMode(QFileDialog.ExistingFile)
            dialog.setNameFilters(["GEDCOM files (*.ged)"])
            if not dialog.exec():
                return

            files = dialog.selectedFiles()
            assert len(files) == 1
            ged_path = files[0]
            self.input_value.setText(ged_path)

            import_config = {
                'input': ged_path,
            }
            ged_import = ged2dot.GedcomImport()
            graph = ged_import.load(import_config)
            self.rootfamily_value.clear()
            for node in graph:
                if not isinstance(node, ged2dot.Family):
                    continue
                help_string = ""
                if node.husb and node.husb.get_surname():
                    help_string += node.husb.get_surname()
                help_string += "-"
                if node.wife and node.wife.get_surname():
                    help_string += node.wife.get_surname()
                key = "%s (%s)" % (node.get_identifier(), help_string)
                self.rootfamily_value.addItem(key, node.get_identifier())
            self.update_status()
        except Exception:  # pylint: disable=broad-except
            self.print_traceback()
Beispiel #2
0
 def __to_dot(config: Dict[str, str]) -> io.BytesIO:
     dot = io.BytesIO()
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     root_node = ged2dot.graph_find(graph, config["rootfamily"])
     assert root_node
     subgraph = ged2dot.bfs(root_node, config)
     exporter = ged2dot.DotExport()
     exporter.store_to_stream(subgraph, dot, config)
     return dot
Beispiel #3
0
 def test_str(self) -> None:
     """Tests __str()__."""
     config = {
         "input": "tests/hello.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.tokenize(config)
     family = ged2dot.graph_find(graph, "F1")
     # Make sure that this doesn't loop.
     self.assertNotEqual(str(family), "")
Beispiel #4
0
 def test_big_endian_name(self) -> None:
     """Tests the case when the name starts with the family name."""
     config = {
         "input": "tests/hello.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.tokenize(config)
     individual = ged2dot.graph_find(graph, "P1")
     assert individual
     assert isinstance(individual, ged2dot.Individual)
     self.assertIn("A<br/>Alice", individual.get_label(image_dir="", name_order="big"))
Beispiel #5
0
 def test_level3(self) -> None:
     """Tests that we just ignore a 3rd level (only 0..2 is valid)."""
     config = {
         "familydepth": "0",
         "input": "tests/level3.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     root_family = ged2dot.graph_find(graph, "F1")
     assert root_family
     subgraph = ged2dot.bfs(root_family, config)
     self.assertEqual(len(subgraph), 3)
Beispiel #6
0
 def test_multiline_note(self) -> None:
     """Tests multiline notes."""
     config = {
         "familydepth": "4",
         "input": "tests/multiline-note.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     person = ged2dot.graph_find(graph, "P2")
     assert person
     assert isinstance(person, ged2dot.Individual)
     self.assertEqual(person.get_config().get_note(), "This is a note with\n3\nlines")
Beispiel #7
0
 def test_unexpected_date(self) -> None:
     """Tests that we just ignore a date which is not birth/death."""
     config = {
         "familydepth": "0",
         "input": "tests/unexpected_date.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     root_family = ged2dot.graph_find(graph, "F1")
     assert root_family
     subgraph = ged2dot.bfs(root_family, config)
     self.assertEqual(len(subgraph), 3)
Beispiel #8
0
 def test_no_surname(self) -> None:
     """Tests the no surname case."""
     config = {
         "familydepth": "4",
         "input": "tests/no_surname.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.tokenize(config)
     individual = ged2dot.graph_find(graph, "P1")
     assert individual
     assert isinstance(individual, ged2dot.Individual)
     self.assertEqual(individual.get_surname(), "")
     self.assertEqual(individual.get_forename(), "Alice")
Beispiel #9
0
 def test_family_depth(self) -> None:
     """Tests handling of the familydepth parameter."""
     config = {
         "familydepth": "0",
         "input": "tests/happy.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     root_family = ged2dot.graph_find(graph, "F1")
     assert root_family
     subgraph = ged2dot.bfs(root_family, config)
     # Just 3 nodes: wife, husband and the family node.
     self.assertEqual(len(subgraph), 3)
Beispiel #10
0
 def test_nosex(self) -> None:
     """Tests the no sex case."""
     config = {
         "familydepth": "4",
         "input": "tests/nosex.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.tokenize(config)
     individual = ged2dot.graph_find(graph, "P3")
     assert individual
     assert isinstance(individual, ged2dot.Individual)
     self.assertIn("placeholder-u", individual.get_label("tests/images", "little"))
     self.assertEqual(individual.get_color(), "black")
Beispiel #11
0
 def __extract_families(self) -> None:
     ged = unohelper.fileUrlToSystemPath(self.props['URL'])
     config = {
         'input': ged,
     }
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     self.family_dict = {}
     for node in graph:
         if not isinstance(node, ged2dot.Family):
             continue
         help_string = ""
         if node.husb and node.husb.get_surname():
             help_string += node.husb.get_surname()
         help_string += "-"
         if node.wife and node.wife.get_surname():
             help_string += node.wife.get_surname()
         key = f"{node.get_identifier()} ({help_string})"
         self.family_dict[key] = node
Beispiel #12
0
    def test_no_husband(self) -> None:
        """Tests handling of no husband in a family."""
        config = {
            "familydepth": "0",
            "input": "tests/no_husband.ged",
            "output": "tests/no_husband.dot",
        }
        importer = ged2dot.GedcomImport()
        graph = importer.load(config)
        root_family = ged2dot.graph_find(graph, "F1")
        assert root_family
        neighbours = root_family.get_neighbours()
        # Just 1 node: wife.
        self.assertEqual(len(neighbours), 1)
        self.assertEqual(neighbours[0].get_identifier(), "P1")

        # Test export of a no-husband model.
        subgraph = ged2dot.bfs(root_family, config)
        exporter = ged2dot.DotExport()
        exporter.store(subgraph, config)
Beispiel #13
0
 def test_cousins_marrying(self) -> None:
     """Tests cousins marrying."""
     config = {
         "familydepth": "4",
         "input": "tests/cousins-marrying.ged",
     }
     importer = ged2dot.GedcomImport()
     graph = importer.load(config)
     root_family = ged2dot.graph_find(graph, "F1")
     assert root_family
     subgraph = ged2dot.bfs(root_family, config)
     # 8 nodes:
     # 1) A
     # 2) B
     # 3) family in which A and B are kids
     # 4) A's family
     # 5) B's family
     # 6) A's kid: C
     # 7) B's kid: D
     # 8) C and D's family
     self.assertEqual(len(subgraph), 8)