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:
parent
1e2c9617d5
commit
19f38a4c15
@ -699,6 +699,19 @@ class MyTimelineView(NavigationView):
|
|||||||
|
|
||||||
return (min_date, max_date, date_range)
|
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,
|
def _calculate_y_position(self, date_sort: int, min_date: int, date_range: int,
|
||||||
timeline_y_start: float, timeline_y_end: float) -> float:
|
timeline_y_start: float, timeline_y_end: float) -> float:
|
||||||
"""
|
"""
|
||||||
@ -761,7 +774,9 @@ class MyTimelineView(NavigationView):
|
|||||||
|
|
||||||
# Create a temporary layout to measure text
|
# Create a temporary layout to measure text
|
||||||
layout = PangoCairo.create_layout(context)
|
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 = []
|
adjusted_events = []
|
||||||
|
|
||||||
@ -1224,7 +1239,7 @@ class MyTimelineView(NavigationView):
|
|||||||
# Find all events for this person
|
# Find all events for this person
|
||||||
person_events = [
|
person_events = [
|
||||||
evt for evt in self.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)
|
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
|
# Check if this event belongs to selected person
|
||||||
is_selected = (self.selected_person_handle is not None and
|
is_selected = (self.selected_person_handle is not None and
|
||||||
event_data.person and
|
self._person_matches_handle(event_data.person, self.selected_person_handle))
|
||||||
event_data.person.get_handle() == self.selected_person_handle)
|
|
||||||
|
|
||||||
# Draw event marker with modern styling
|
# Draw event marker with modern styling
|
||||||
self.draw_event_marker(context, timeline_x, event_data.y_pos,
|
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
|
# Find all events for the selected person
|
||||||
person_events = [
|
person_events = [
|
||||||
event_data for event_data in events_with_y_pos
|
event_data for event_data in events_with_y_pos
|
||||||
if event_data.person and
|
if self._person_matches_handle(event_data.person, self.selected_person_handle)
|
||||||
event_data.person.get_handle() == self.selected_person_handle
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(person_events) < 1:
|
if len(person_events) < 1:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user