Refactor: Extract constant and optimize set operations
- Extract YEAR_MARKER_STEP_DIVISOR constant for year marker calculation - Remove redundant year_step == 0 check (max() already ensures >= 1) - Optimize set creation by removing unnecessary .keys() calls These changes improve code clarity and follow Python best practices.
This commit is contained in:
parent
f720789c95
commit
b9c9951487
@ -87,6 +87,7 @@ CLICKABLE_AREA_HEIGHT = 30
|
|||||||
|
|
||||||
# UI Constants
|
# UI Constants
|
||||||
YEAR_LABEL_WIDTH = 100
|
YEAR_LABEL_WIDTH = 100
|
||||||
|
YEAR_MARKER_STEP_DIVISOR = 10 # Divisor for calculating year marker step (every Nth year)
|
||||||
TOOLTIP_DELAY = 500 # milliseconds
|
TOOLTIP_DELAY = 500 # milliseconds
|
||||||
TOOLTIP_MAX_WIDTH = 500
|
TOOLTIP_MAX_WIDTH = 500
|
||||||
LABEL_BACKGROUND_PADDING = 8
|
LABEL_BACKGROUND_PADDING = 8
|
||||||
@ -1373,7 +1374,7 @@ class MyTimelineView(NavigationView):
|
|||||||
for category, checkbox in self._filter_widgets['category_checkboxes'].items():
|
for category, checkbox in self._filter_widgets['category_checkboxes'].items():
|
||||||
if checkbox.get_active():
|
if checkbox.get_active():
|
||||||
active_categories.add(category)
|
active_categories.add(category)
|
||||||
all_categories = set(self._filter_widgets['category_checkboxes'].keys())
|
all_categories = set(self._filter_widgets['category_checkboxes'])
|
||||||
self.category_filter = active_categories if active_categories != all_categories else None
|
self.category_filter = active_categories if active_categories != all_categories else None
|
||||||
|
|
||||||
# Update person filter
|
# Update person filter
|
||||||
@ -1382,7 +1383,7 @@ class MyTimelineView(NavigationView):
|
|||||||
for person_handle, checkbox in self._filter_widgets['person_checkboxes'].items():
|
for person_handle, checkbox in self._filter_widgets['person_checkboxes'].items():
|
||||||
if checkbox.get_active():
|
if checkbox.get_active():
|
||||||
active_persons.add(person_handle)
|
active_persons.add(person_handle)
|
||||||
all_persons = set(self._filter_widgets['person_checkboxes'].keys())
|
all_persons = set(self._filter_widgets['person_checkboxes'])
|
||||||
self.person_filter = active_persons if active_persons != all_persons else None
|
self.person_filter = active_persons if active_persons != all_persons else None
|
||||||
|
|
||||||
# Update date range filter from calendar widgets
|
# Update date range filter from calendar widgets
|
||||||
@ -3393,10 +3394,9 @@ class MyTimelineView(NavigationView):
|
|||||||
context.restore()
|
context.restore()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Draw markers for major years (every 10 years or so)
|
# Draw markers for major years (every Nth year based on range)
|
||||||
year_step = max(1, (max_year - min_year) // 10)
|
# Ensure year_step is at least 1 to avoid division by zero issues
|
||||||
if year_step == 0:
|
year_step = max(1, (max_year - min_year) // YEAR_MARKER_STEP_DIVISOR)
|
||||||
year_step = 1
|
|
||||||
|
|
||||||
for year in range(min_year, max_year + 1, year_step):
|
for year in range(min_year, max_year + 1, year_step):
|
||||||
# Calculate Y position
|
# Calculate Y position
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user