From 26bca526c3831c6d547fe0c0197c6cf74e45b03a Mon Sep 17 00:00:00 2001 From: Daniel Viegas Date: Sun, 30 Nov 2025 01:22:36 +0100 Subject: [PATCH] Refactor: Extract additional constants for better code clarity - Extract MOUSE_BUTTON_LEFT constant to replace magic number 1 - Extract ZOOM_PERCENTAGE_MULTIPLIER constant for zoom display - Extract HSV_HUE_MAX_DEGREES constant for color generation - Improve zoom display calculation readability These changes improve code maintainability by replacing magic numbers with named constants that clearly express their purpose. --- MyTimeline.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MyTimeline.py b/MyTimeline.py index 5185649..4a3ca3d 100644 --- a/MyTimeline.py +++ b/MyTimeline.py @@ -130,6 +130,10 @@ FONT_SIZE_LARGE = 24 MARKER_HOVER_SIZE_MULTIPLIER = 1.3 MARKER_SELECTED_SIZE_MULTIPLIER = 1.2 DEFAULT_EVENT_SHAPE = 'square' # Default shape for events without specific shape mapping + +# Mouse Button Constants +MOUSE_BUTTON_LEFT = 1 # Left mouse button +ZOOM_PERCENTAGE_MULTIPLIER = 100 # Multiplier to convert zoom level (0.0-1.0) to percentage GRADIENT_BRIGHTNESS_OFFSET = 0.2 GRADIENT_DARKNESS_OFFSET = 0.1 SHADOW_OFFSET_X = 1 @@ -157,6 +161,7 @@ CONNECTION_LINE_MIN_DISTANCE = EVENT_MARKER_SIZE * 2 # Minimum distance between PERSON_COLOR_SATURATION = 0.7 # High saturation for vibrant colors PERSON_COLOR_LIGHTNESS = 0.5 # Medium lightness for good visibility PERSON_COLOR_ALPHA = 0.75 # Semi-transparent +HSV_HUE_MAX_DEGREES = 360 # Maximum value for hue in HSV color space (degrees) # Marker State Colors SELECTED_MARKER_COLOR = (0.2, 0.4, 0.9) # Blue highlight for selected person's events @@ -2287,7 +2292,7 @@ class MyTimelineView(NavigationView): # Generate color using HSV: vary hue, keep saturation and lightness constant # Use hash of handle for consistent color even when selection order changes handle_hash = hash(person_handle) - hue = (abs(handle_hash) % 360) / 360.0 # 0-1 range + hue = (abs(handle_hash) % HSV_HUE_MAX_DEGREES) / float(HSV_HUE_MAX_DEGREES) # 0-1 range # Convert HSV to RGB (HSV is Hue, Saturation, Value) r, g, b = colorsys.hsv_to_rgb(hue, PERSON_COLOR_SATURATION, PERSON_COLOR_LIGHTNESS) @@ -2526,7 +2531,8 @@ class MyTimelineView(NavigationView): def update_zoom_display(self) -> None: """Update the zoom level display.""" if hasattr(self, 'zoom_label'): - self.zoom_label.set_text(f"{int(self.zoom_level * 100)}%") + zoom_percentage = int(self.zoom_level * ZOOM_PERCENTAGE_MULTIPLIER) + self.zoom_label.set_text(f"{zoom_percentage}%") def on_button_press(self, widget: Gtk.Widget, event: Gdk.Event) -> bool: """ @@ -2539,7 +2545,7 @@ class MyTimelineView(NavigationView): Returns: bool: False to allow other handlers to process the event. """ - if event.button == 1: # Left click + if event.button == MOUSE_BUTTON_LEFT: # Find which event was clicked clicked_index = self.find_event_at_position(event.x, event.y) if clicked_index is not None: