99 CurrentExportConfigState ,
1010 CurrentStaticAnalysisConfigState ,
1111)
12+ from OTAnalytics .domain .observer import OBSERVER , Subject
13+
14+
15+ class StaticAnalysisConfigChanged :
16+ """Notify observers that a value of the static analysis config was changed.
17+
18+ Only changes made by the user are published. Loading a project replaces the
19+ whole configuration without passing this notifier, so a load does not look
20+ like an unsaved change.
21+ """
22+
23+ def __init__ (self ) -> None :
24+ self ._subject = Subject [None ]()
25+
26+ def register (self , observer : OBSERVER [None ]) -> None :
27+ """Listen to changes of the static analysis config.
28+
29+ Args:
30+ observer (OBSERVER[None]): the observer to be registered.
31+ """
32+ self ._subject .register (observer )
33+
34+ def notify (self ) -> None :
35+ """Notify all observers about a changed static analysis config."""
36+ self ._subject .notify (None )
1237
1338
1439class GetDoEventsOfCurrentAnalysisConfig :
@@ -37,10 +62,17 @@ class SetDoEventsInCurrentAnalysisConfig:
3762 Args:
3863 state (CurrentStaticAnalysisConfigState): the state holding the analysis
3964 settings.
65+ config_changed (StaticAnalysisConfigChanged): notifies observers about
66+ the change.
4067 """
4168
42- def __init__ (self , state : CurrentStaticAnalysisConfigState ) -> None :
69+ def __init__ (
70+ self ,
71+ state : CurrentStaticAnalysisConfigState ,
72+ config_changed : StaticAnalysisConfigChanged ,
73+ ) -> None :
4374 self ._state = state
75+ self ._config_changed = config_changed
4476
4577 def set (self , do_events : bool ) -> None :
4678 """Set whether events are to be detected.
@@ -49,6 +81,7 @@ def set(self, do_events: bool) -> None:
4981 do_events (bool): True if events are to be detected.
5082 """
5183 self ._state .do_events = do_events
84+ self ._config_changed .notify ()
5285
5386
5487class GetDoCountingOfCurrentAnalysisConfig :
@@ -77,10 +110,17 @@ class SetDoCountingInCurrentAnalysisConfig:
77110 Args:
78111 state (CurrentStaticAnalysisConfigState): the state holding the analysis
79112 settings.
113+ config_changed (StaticAnalysisConfigChanged): notifies observers about
114+ the change.
80115 """
81116
82- def __init__ (self , state : CurrentStaticAnalysisConfigState ) -> None :
117+ def __init__ (
118+ self ,
119+ state : CurrentStaticAnalysisConfigState ,
120+ config_changed : StaticAnalysisConfigChanged ,
121+ ) -> None :
83122 self ._state = state
123+ self ._config_changed = config_changed
84124
85125 def set (self , do_counting : bool ) -> None :
86126 """Set whether counts are to be created.
@@ -89,6 +129,7 @@ def set(self, do_counting: bool) -> None:
89129 do_counting (bool): True if counts are to be created.
90130 """
91131 self ._state .do_counting = do_counting
132+ self ._config_changed .notify ()
92133
93134
94135class GetNumProcessesOfCurrentAnalysisConfig :
@@ -117,10 +158,17 @@ class SetNumProcessesInCurrentAnalysisConfig:
117158 Args:
118159 state (CurrentStaticAnalysisConfigState): the state holding the analysis
119160 settings.
161+ config_changed (StaticAnalysisConfigChanged): notifies observers about
162+ the change.
120163 """
121164
122- def __init__ (self , state : CurrentStaticAnalysisConfigState ) -> None :
165+ def __init__ (
166+ self ,
167+ state : CurrentStaticAnalysisConfigState ,
168+ config_changed : StaticAnalysisConfigChanged ,
169+ ) -> None :
123170 self ._state = state
171+ self ._config_changed = config_changed
124172
125173 def set (self , num_processes : int ) -> None :
126174 """Set the number of processes to be used for the analysis.
@@ -129,6 +177,7 @@ def set(self, num_processes: int) -> None:
129177 num_processes (int): the number of processes.
130178 """
131179 self ._state .num_processes = num_processes
180+ self ._config_changed .notify ()
132181
133182
134183class GetLogfileOfCurrentAnalysisConfig :
@@ -157,10 +206,17 @@ class SetLogfileInCurrentAnalysisConfig:
157206 Args:
158207 state (CurrentStaticAnalysisConfigState): the state holding the analysis
159208 settings.
209+ config_changed (StaticAnalysisConfigChanged): notifies observers about
210+ the change.
160211 """
161212
162- def __init__ (self , state : CurrentStaticAnalysisConfigState ) -> None :
213+ def __init__ (
214+ self ,
215+ state : CurrentStaticAnalysisConfigState ,
216+ config_changed : StaticAnalysisConfigChanged ,
217+ ) -> None :
163218 self ._state = state
219+ self ._config_changed = config_changed
164220
165221 def set (self , logfile : Path ) -> None :
166222 """Set the logfile the analysis log is written to.
@@ -169,6 +225,7 @@ def set(self, logfile: Path) -> None:
169225 logfile (Path): the logfile.
170226 """
171227 self ._state .logfile = logfile
228+ self ._config_changed .notify ()
172229
173230
174231class GetSaveNameOfCurrentAnalysisConfig :
@@ -195,10 +252,17 @@ class SetSaveNameInCurrentAnalysisConfig:
195252
196253 Args:
197254 state (CurrentExportConfigState): the state holding the export settings.
255+ config_changed (StaticAnalysisConfigChanged): notifies observers about
256+ the change.
198257 """
199258
200- def __init__ (self , state : CurrentExportConfigState ) -> None :
259+ def __init__ (
260+ self ,
261+ state : CurrentExportConfigState ,
262+ config_changed : StaticAnalysisConfigChanged ,
263+ ) -> None :
201264 self ._state = state
265+ self ._config_changed = config_changed
202266
203267 def set (self , save_name : str ) -> None :
204268 """Set the name used to save analysis results.
@@ -207,6 +271,7 @@ def set(self, save_name: str) -> None:
207271 save_name (str): the save name.
208272 """
209273 self ._state .save_name = save_name
274+ self ._config_changed .notify ()
210275
211276
212277class GetSaveSuffixOfCurrentAnalysisConfig :
@@ -233,10 +298,17 @@ class SetSaveSuffixInCurrentAnalysisConfig:
233298
234299 Args:
235300 state (CurrentExportConfigState): the state holding the export settings.
301+ config_changed (StaticAnalysisConfigChanged): notifies observers about
302+ the change.
236303 """
237304
238- def __init__ (self , state : CurrentExportConfigState ) -> None :
305+ def __init__ (
306+ self ,
307+ state : CurrentExportConfigState ,
308+ config_changed : StaticAnalysisConfigChanged ,
309+ ) -> None :
239310 self ._state = state
311+ self ._config_changed = config_changed
240312
241313 def set (self , save_suffix : str ) -> None :
242314 """Set the suffix appended to the save name.
@@ -245,6 +317,7 @@ def set(self, save_suffix: str) -> None:
245317 save_suffix (str): the save suffix.
246318 """
247319 self ._state .save_suffix = save_suffix
320+ self ._config_changed .notify ()
248321
249322
250323class GetEventFormatsOfCurrentAnalysisConfig :
@@ -271,10 +344,17 @@ class SetEventFormatsInCurrentAnalysisConfig:
271344
272345 Args:
273346 state (CurrentExportConfigState): the state holding the export settings.
347+ config_changed (StaticAnalysisConfigChanged): notifies observers about
348+ the change.
274349 """
275350
276- def __init__ (self , state : CurrentExportConfigState ) -> None :
351+ def __init__ (
352+ self ,
353+ state : CurrentExportConfigState ,
354+ config_changed : StaticAnalysisConfigChanged ,
355+ ) -> None :
277356 self ._state = state
357+ self ._config_changed = config_changed
278358
279359 def set (self , event_formats : set [str ]) -> None :
280360 """Set the formats the event list is exported to.
@@ -283,6 +363,7 @@ def set(self, event_formats: set[str]) -> None:
283363 event_formats (set[str]): the event formats.
284364 """
285365 self ._state .event_formats = event_formats
366+ self ._config_changed .notify ()
286367
287368
288369class GetCountIntervalsOfCurrentAnalysisConfig :
@@ -309,10 +390,17 @@ class SetCountIntervalsInCurrentAnalysisConfig:
309390
310391 Args:
311392 state (CurrentExportConfigState): the state holding the export settings.
393+ config_changed (StaticAnalysisConfigChanged): notifies observers about
394+ the change.
312395 """
313396
314- def __init__ (self , state : CurrentExportConfigState ) -> None :
397+ def __init__ (
398+ self ,
399+ state : CurrentExportConfigState ,
400+ config_changed : StaticAnalysisConfigChanged ,
401+ ) -> None :
315402 self ._state = state
403+ self ._config_changed = config_changed
316404
317405 def set (self , count_intervals : set [int ]) -> None :
318406 """Set the count intervals in minutes.
@@ -321,6 +409,7 @@ def set(self, count_intervals: set[int]) -> None:
321409 count_intervals (set[int]): the count intervals in minutes.
322410 """
323411 self ._state .count_intervals = count_intervals
412+ self ._config_changed .notify ()
324413
325414
326415class GetCountingEventOfCurrentAnalysisConfig :
@@ -347,10 +436,17 @@ class SetCountingEventInCurrentAnalysisConfig:
347436
348437 Args:
349438 state (CurrentExportConfigState): the state holding the export settings.
439+ config_changed (StaticAnalysisConfigChanged): notifies observers about
440+ the change.
350441 """
351442
352- def __init__ (self , state : CurrentExportConfigState ) -> None :
443+ def __init__ (
444+ self ,
445+ state : CurrentExportConfigState ,
446+ config_changed : StaticAnalysisConfigChanged ,
447+ ) -> None :
353448 self ._state = state
449+ self ._config_changed = config_changed
354450
355451 def set (self , counting_event : CountingEvent ) -> None :
356452 """Set the event a road user is counted at.
@@ -359,3 +455,4 @@ def set(self, counting_event: CountingEvent) -> None:
359455 counting_event (CountingEvent): the counting event.
360456 """
361457 self ._state .counting_event = counting_event
458+ self ._config_changed .notify ()
0 commit comments