Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions ged2dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(self) -> None:
self.__note = ""
self.__birth = ""
self.__death = ""
self.__occupation = ""

def set_note(self, note: str) -> None:
"""Sets a note."""
Expand All @@ -174,6 +175,14 @@ def get_death(self) -> str:
"""Gets the death date."""
return self.__death

def set_occupation(self, occupation: str) -> None:
"""Sets the occupation."""
self.__occupation = occupation

def get_occupation(self) -> str:
"""Gets the occupation."""
return self.__occupation


class Individual(Node):
"""An individual is always a child in a family, and is an adult in 0..* families."""
Expand Down Expand Up @@ -261,8 +270,8 @@ def get_famc_id(self) -> str:
"""Gets the child family ID."""
return self.__dict["famc_id"]

def get_label(self, image_dir: str, name_order: str, birth_format: str, basepath: str) -> str:
"""Gets the graphviz label."""
def __get_image_path(self, image_dir: str, basepath: str) -> str:
"""Gets the path to the image."""
image_path = os.path.join(image_dir, self.get_forename() + " " + self.get_surname())
for suffix in [".jpg", ".jpeg", ".png", ".JPG", ".PNG"]:
image_path += " " + self.get_config().get_birth() + suffix
Expand All @@ -279,6 +288,11 @@ def get_label(self, image_dir: str, name_order: str, birth_format: str, basepath
image_path = get_abspath(f"placeholder-{sex}.svg")
if basepath:
image_path = os.path.relpath(image_path, basepath)
return image_path

def get_label(self, image_dir: str, name_order: str, birth_format: str, basepath: str) -> str:
"""Gets the graphviz label."""
image_path = self.__get_image_path(image_dir, basepath)
label = "<table border=\"0\" cellborder=\"0\"><tr><td>"
label += "<img scale=\"true\" src=\"" + image_path + "\"/>"
# State the font face explicitly to help correct centering.
Expand All @@ -297,6 +311,9 @@ def get_label(self, image_dir: str, name_order: str, birth_format: str, basepath
label += "† " + self.get_config().get_death()
else:
label += self.get_config().get_birth() + "-" + self.get_config().get_death()
occupation = self.get_config().get_occupation()
if occupation:
label += "<br/>" + occupation
label += "</font></td></tr></table>"
return label

Expand Down Expand Up @@ -473,6 +490,8 @@ def __handle_individual_config(self, line: str) -> None:
self.in_deat = True
elif line_lead_token == "NOTE" and self.individual:
self.individual.get_config().set_note(line[5:])
elif line_lead_token == "OCCU" and self.individual:
self.individual.get_config().set_occupation(line[5:])

def load(self, config: Dict[str, str]) -> List[Node]:
"""Tokenizes and resolves a gedcom file into a graph."""
Expand Down
4 changes: 4 additions & 0 deletions guide/src/news.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Version descriptions

## master

- If provided, occupation is listed after the birth and dead year

## 25.8

- For people whose names have a suffix (like Richard III, or Sam Jr) extract that and keep it as part of the name (Gregory Dudek)
Expand Down
9 changes: 0 additions & 9 deletions guide/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ C:/Users/John/Application Data/LibreOffice/4/user/Scripts/python/log.txt
- For Linux, start LibreOffice from a terminal, the log is printed to the
standard error.

- For Mac, start LibreOffice from Terminal:

```
cd /Applications/LibreOffice.app/Contents/program
./soffice --nologo /path/to/test.ged
```

then the log is printed to the standard error as well.

## Icons

Icons are from
Expand Down
14 changes: 14 additions & 0 deletions tests/occupation.ged
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
0 HEAD
0 @P1@ INDI
1 NAME Alice /A/
1 SEX F
1 FAMS @F1@
1 OCCU myoccupation
0 @P2@ INDI
1 NAME Bob /B/
1 SEX M
1 FAMS @F1@
0 @F1@ FAM
1 HUSB @P2@
1 WIFE @P1@
0 TRLR
13 changes: 13 additions & 0 deletions tests/test_ged2dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def test_name_suffix(self) -> None:
label = individual.get_label(image_dir="", name_order="little", birth_format="{}-", basepath="")
self.assertIn("Alice<br/>A Suffix", label)

def test_occupation(self) -> None:
"""Tests the case when the occupation is provided."""
config = {
"input": "tests/occupation.ged",
}
importer = ged2dot.GedcomImport()
graph = importer.tokenize(config)
individual = ged2dot.graph_find(graph, "P1")
assert individual
assert isinstance(individual, ged2dot.Individual)
label = individual.get_label(image_dir="", name_order="little", birth_format="{}-", basepath="")
self.assertIn("Alice<br/>A<br/>-<br/>myoccupation", label)

def test_str(self) -> None:
"""Tests __str()__."""
config = {
Expand Down