diff --git a/MyTimeline.py b/MyTimeline.py index 803ea27..28e86fb 100644 --- a/MyTimeline.py +++ b/MyTimeline.py @@ -88,6 +88,12 @@ TOOLTIP_MAX_WIDTH = 500 LABEL_BACKGROUND_PADDING = 8 LABEL_BACKGROUND_RADIUS = 5 +# Font Constants +FONT_FAMILY = "Sans" +FONT_SIZE_NORMAL = 11 +FONT_SIZE_SMALL = 9 +FONT_SIZE_LARGE = 24 + # Visual Effect Constants MARKER_HOVER_SIZE_MULTIPLIER = 1.3 MARKER_SELECTED_SIZE_MULTIPLIER = 1.2 @@ -272,6 +278,15 @@ class MyTimelineView(NavigationView): """ def __init__(self, pdata, dbstate, uistate, nav_group=0): + """ + Initialize the MyTimeline view. + + Args: + pdata: Plugin data object. + dbstate: Database state object. + uistate: UI state object. + nav_group: Navigation group identifier. + """ NavigationView.__init__( self, _("MyTimeline"), pdata, dbstate, uistate, FamilyBookmarks, nav_group ) @@ -307,6 +322,9 @@ class MyTimelineView(NavigationView): self._cached_date_range: Optional[int] = None self._cached_min_date: Optional[int] = None self._cached_max_date: Optional[int] = None + + # Initialize temporary surface for text measurement (used in find_event_at_position) + self._temp_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1) # Connect to database changes self.dbstate.connect("database-changed", self.change_db) @@ -1074,10 +1092,8 @@ class MyTimelineView(NavigationView): timeline_y_start = TIMELINE_MARGIN_TOP timeline_y_end = height - TIMELINE_MARGIN_BOTTOM - # Get adjusted events using cache (create temporary context if needed) + # Get adjusted events using cache (create temporary context for text measurement) # For click detection, we need a context for text measurement - if not hasattr(self, '_temp_surface') or self._temp_surface is None: - self._temp_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1) temp_context = cairo.Context(self._temp_surface) adjusted_events = self._get_adjusted_events(temp_context, timeline_y_start, timeline_y_end) @@ -1271,8 +1287,8 @@ class MyTimelineView(NavigationView): height: Widget height. """ context.set_source_rgb(0.6, 0.6, 0.6) - context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) - context.set_font_size(24) + context.select_font_face(FONT_FAMILY, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) + context.set_font_size(FONT_SIZE_LARGE) text = _("No events found") (x_bearing, y_bearing, text_width, text_height, x_advance, y_advance) = context.text_extents(text) context.move_to((width - text_width) / 2, height / 2) @@ -1583,7 +1599,7 @@ class MyTimelineView(NavigationView): layout = PangoCairo.create_layout(context) # Use modern font - font_desc = Pango.font_description_from_string("Sans 11") + font_desc = Pango.font_description_from_string(f"{FONT_FAMILY} {FONT_SIZE_NORMAL}") if is_hovered: font_desc.set_weight(Pango.Weight.BOLD) layout.set_font_description(font_desc) @@ -1698,7 +1714,7 @@ class MyTimelineView(NavigationView): # Draw year label layout = PangoCairo.create_layout(context) layout.set_font_description( - Pango.font_description_from_string("Sans 9") + Pango.font_description_from_string(f"{FONT_FAMILY} {FONT_SIZE_SMALL}") ) layout.set_text(str(year), -1)