Skip to content

Commit

Permalink
Merge pull request #488 from OpenTrafficCam/bug/4709-activation-of-fi…
Browse files Browse the repository at this point in the history
…lter-by-date-is-broken

bug/4709-activation-of-filter-by-date-is-broken
  • Loading branch information
briemla authored Mar 25, 2024
2 parents 1d7e09d + b14acfd commit bf3e668
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
9 changes: 8 additions & 1 deletion OTAnalytics/application/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

DEFAULT_WIDTH = 800
DEFAULT_HEIGHT = 600
DEFAULT_FILTER_DATE_ACTIVE = False
DEFAULT_SKIP_TIME = SkipTime(1, 1)


class TrackState(TrackListObserver):
Expand Down Expand Up @@ -184,12 +186,15 @@ def __init__(self) -> None:
self.filter_element = ObservableProperty[FilterElement](
FilterElement(DateRange(None, None), None)
)
self.filter_date_active = ObservableProperty[bool](
default=DEFAULT_FILTER_DATE_ACTIVE
)
self.view_width = ObservableProperty[int](default=DEFAULT_WIDTH)
self.view_height = ObservableProperty[int](default=DEFAULT_HEIGHT)
self.selected_videos: ObservableProperty[list[Video]] = ObservableProperty[
list[Video]
](default=[])
self.skip_time = ObservableProperty[SkipTime](SkipTime(1, 1))
self.skip_time = ObservableProperty[SkipTime](DEFAULT_SKIP_TIME)

def reset(self) -> None:
"""Reset to default settings."""
Expand All @@ -198,7 +203,9 @@ def reset(self) -> None:
self.view_width.set(DEFAULT_WIDTH)
self.view_height.set(DEFAULT_HEIGHT)
self.filter_element.set(FilterElement(DateRange(None, None), None))
self.filter_date_active.set(DEFAULT_FILTER_DATE_ACTIVE)
self.track_offset.set(DEFAULT_TRACK_OFFSET)
self.skip_time.set(DEFAULT_SKIP_TIME)


class TrackPropertiesUpdater:
Expand Down
1 change: 1 addition & 0 deletions OTAnalytics/application/use_cases/filter_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create(self) -> None:
new_filter = self.__create_new_filter_element(video_start)
self._enable_filter_track_by_date.enable()
self._state.filter_element.set(new_filter)
self._state.filter_date_active.set(True)

def __create_new_filter_element(self, video_start: datetime) -> FilterElement:
filter_element = self._state.filter_element.get()
Expand Down
15 changes: 12 additions & 3 deletions OTAnalytics/plugin_ui/customtkinter_gui/dummy_viewmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def _update_date_range(self, filter_element: FilterElement) -> None:
self._frame_filter.update_date_range(
{"start_date": start_date, "end_date": end_date}
)
self.__enable_filter_track_by_date_button()

def update_quick_save_button(self, _: Any) -> None:
if self._button_quick_save_config is None:
Expand Down Expand Up @@ -1502,6 +1501,12 @@ def get_filter_tracks_by_date_setting(self) -> DateRange:
filter_element = self._application.track_view_state.filter_element.get()
return filter_element.date_range

def change_filter_date_active(self, current: bool) -> None:
if current:
self.__enable_filter_track_by_date_button()
else:
self.__disable_filter_track_by_date_button()

def enable_filter_track_by_date(self) -> None:
self._application.enable_filter_track_by_date()

Expand All @@ -1510,10 +1515,11 @@ def enable_filter_track_by_date(self) -> None:
def __enable_filter_track_by_date_button(self) -> None:
if self._frame_filter is None:
raise MissingInjectedInstanceError(AbstractFrameFilter.__name__)
self._frame_filter.enable_filter_by_date_button()
current_date_range = (
self._application.track_view_state.filter_element.get().date_range
)
self._application.track_view_state.filter_date_active.set(True)
self._frame_filter.enable_filter_by_date_button()
if current_date_range != DateRange(None, None):
self._frame_filter.set_active_color_on_filter_by_date_button()
else:
Expand All @@ -1522,9 +1528,12 @@ def __enable_filter_track_by_date_button(self) -> None:
def disable_filter_track_by_date(self) -> None:
self._application.disable_filter_track_by_date()

self.__disable_filter_track_by_date_button()

def __disable_filter_track_by_date_button(self) -> None:
if self._frame_filter is None:
raise MissingInjectedInstanceError(AbstractFrameFilter.__name__)

self._application.track_view_state.filter_date_active.set(False)
self._frame_filter.disable_filter_by_date_button()

def switch_to_prev_date_range(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions OTAnalytics/plugin_ui/customtkinter_gui/frame_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def enable_button(self) -> None:
self.button.configure(state=STATE_NORMAL)

def disable_button(self) -> None:
self._check_var.set(0)
self.button.configure(state=STATE_DISABLED, fg_color=COLOR_GRAY)


Expand Down
3 changes: 3 additions & 0 deletions OTAnalytics/plugin_ui/main_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ def start_gui(self, run_config: RunConfiguration) -> None:
application.action_state.action_running.register(
dummy_viewmodel._notify_action_running_state
)
track_view_state.filter_date_active.register(
dummy_viewmodel.change_filter_date_active
)
# TODO: Refactor observers - move registering to subjects happening in
# constructor dummy_viewmodel
# cut_tracks_intersecting_section.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_create_default_filter_range(
) -> None:
enable_filter_track_by_date = Mock(spec=EnableFilterTrackByDate)
filter_element = create_filter_element(start_date=start_date, end_date=end_date)
track_view_state = create_track_view_state(filter_element)
track_view_state = create_track_view_state(filter_element, True)
derived_filter_element = Mock(spec=FilterElement)
filter_element.derive_date.return_value = derived_filter_element
use_case = CreateDefaultFilterRange(
Expand All @@ -62,12 +62,13 @@ def test_create_default_filter_range(
track_view_state.filter_element.set.assert_called_once_with(
derived_filter_element
)
track_view_state.filter_date_active.set.assert_called_once_with(True)
enable_filter_track_by_date.enable.assert_called_once()

def test_do_nothing_if_filter_is_already_set(self, videos_metadata: Mock) -> None:
enable_filter_track_by_date = Mock(spec=EnableFilterTrackByDate)
filter_element = create_filter_element(start_date=START_DATE, end_date=END_DATE)
track_view_state = create_track_view_state(filter_element)
track_view_state = create_track_view_state(filter_element, True)
use_case = CreateDefaultFilterRange(
track_view_state,
videos_metadata=videos_metadata,
Expand All @@ -79,4 +80,5 @@ def test_do_nothing_if_filter_is_already_set(self, videos_metadata: Mock) -> Non

filter_element.derive_date.assert_not_called()
track_view_state.filter_element.set.assert_called_once_with(filter_element)
track_view_state.filter_date_active.set.assert_called_once_with(True)
enable_filter_track_by_date.enable.assert_called_once()
5 changes: 4 additions & 1 deletion tests/utils/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def create_filter_element(
return filter_element


def create_track_view_state(filter_element: FilterElement) -> Mock:
def create_track_view_state(
filter_element: FilterElement, filter_date_active: bool
) -> Mock:
state = Mock(spec=TrackViewState)
state.filter_element = observable(filter_element)
state.filter_date_active = observable(filter_date_active)
return state

0 comments on commit bf3e668

Please sign in to comment.