Extract person handle comparison and fix remaining font constant

- Add _person_matches_handle() helper method to eliminate code duplication
- Replace 3 instances of 'person and person.get_handle() == handle' pattern
- Fix remaining hardcoded font string to use FONT_FAMILY constant
- Improve code consistency and maintainability

Benefits:
- Reduced code duplication
- Centralized person handle comparison logic
- All font strings now use constants
- More readable and maintainable code
This commit is contained in:
Daniel Viegas 2025-11-29 00:42:06 +01:00
parent 1e2c9617d5
commit 19f38a4c15

View File

@ -699,6 +699,19 @@ class MyTimelineView(NavigationView):
return (min_date, max_date, date_range)
def _person_matches_handle(self, person: Optional[Any], handle: str) -> bool:
"""
Check if a person's handle matches the given handle.
Args:
person: The person object (may be None).
handle: The handle to match against.
Returns:
bool: True if person exists and handle matches, False otherwise.
"""
return person is not None and person.get_handle() == handle
def _calculate_y_position(self, date_sort: int, min_date: int, date_range: int,
timeline_y_start: float, timeline_y_end: float) -> float:
"""
@ -761,7 +774,9 @@ class MyTimelineView(NavigationView):
# Create a temporary layout to measure text
layout = PangoCairo.create_layout(context)
layout.set_font_description(Pango.font_description_from_string("Sans 11"))
layout.set_font_description(
Pango.font_description_from_string(f"{FONT_FAMILY} {FONT_SIZE_NORMAL}")
)
adjusted_events = []
@ -1224,7 +1239,7 @@ class MyTimelineView(NavigationView):
# Find all events for this person
person_events = [
evt for evt in self.events
if evt.person and evt.person.get_handle() == person_handle
if self._person_matches_handle(evt.person, person_handle)
]
tooltip_text = self._format_person_tooltip(event_data.person, person_events)
@ -1338,8 +1353,7 @@ class MyTimelineView(NavigationView):
# Check if this event belongs to selected person
is_selected = (self.selected_person_handle is not None and
event_data.person and
event_data.person.get_handle() == self.selected_person_handle)
self._person_matches_handle(event_data.person, self.selected_person_handle))
# Draw event marker with modern styling
self.draw_event_marker(context, timeline_x, event_data.y_pos,
@ -1786,8 +1800,7 @@ class MyTimelineView(NavigationView):
# Find all events for the selected person
person_events = [
event_data for event_data in events_with_y_pos
if event_data.person and
event_data.person.get_handle() == self.selected_person_handle
if self._person_matches_handle(event_data.person, self.selected_person_handle)
]
if len(person_events) < 1: