@@ -116,8 +116,50 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
116
116
self .handle_run_process ()
117
117
118
118
119
+ def _validate_output_file (self ) -> bool :
120
+ """Validate and fix output file extension"""
121
+ output_file = self .query_one ("#output-file" ).value
122
+ if output_file and not output_file .endswith ('.bag' ):
123
+ output_file += '.bag'
124
+ self .set_output_file (output_file )
125
+ self .app .notify (
126
+ "output file must end with .bag, added for you. :)" ,
127
+ title = "Info" ,
128
+ severity = "information"
129
+ )
130
+ return False
131
+ return True
132
+
133
+ def _validate_time_range (self ) -> bool :
134
+ """Validate that the time range is within the bag's initial range"""
135
+ if self .bags .get_bag_numbers () != 1 :
136
+ return True
137
+
138
+ bag = self .bags .get_single_bag ()
139
+ start_time , end_time = self .get_time_range ()
140
+
141
+ try :
142
+ input_start = Operation .from_datetime (start_time )
143
+ input_end = Operation .from_datetime (end_time )
144
+ bag_start , bag_end = bag .info .init_time_range
145
+
146
+ print (f"input_start: { input_start } , input_end: { input_end } , bag_start: { bag_start } , bag_end: { bag_end } " )
147
+ if input_start [0 ] < bag_start [0 ] or input_end [0 ] > bag_end [0 ]:
148
+ # Reset to initial time range
149
+ self .set_time_range (bag .info .init_time_range_str )
150
+ self .app .notify (
151
+ f"Time range reset to { bag .info .init_time_range_str [0 ]} - { bag .info .init_time_range_str [1 ]} " ,
152
+ title = "Invalid Time Range" ,
153
+ severity = "warning"
154
+ )
155
+ return False
156
+ return True
157
+ except ValueError as e :
158
+ self .logger .warning (f"Invalid time format: { str (e )} " )
159
+ return False
160
+
119
161
def handle_run_process (self ) -> None :
120
- """Handle Run button press with time range validation"""
162
+ """Handle Run button press with validation"""
121
163
if self .bags .get_bag_numbers () == 0 :
122
164
self .app .notify ("Please select at least one bag file" , title = "Error" , severity = "error" )
123
165
return
@@ -126,40 +168,13 @@ def handle_run_process(self) -> None:
126
168
self .app .notify ("Please select at least one topic" , title = "Error" , severity = "error" )
127
169
return
128
170
129
- # Validate and fix output file extension
130
- output_file = self .query_one ("#output-file" ).value
131
- if output_file and not output_file .endswith ('.bag' ):
132
- output_file += '.bag'
133
- self .set_output_file (output_file )
134
- self .app .notify (
135
- "Added .bag extension to output file name" ,
136
- title = "Info" ,
137
- severity = "information"
138
- )
171
+ # Validate output file
172
+ if not self ._validate_output_file ():
173
+ return
139
174
140
175
# Validate time range
141
- if self .bags .get_bag_numbers () == 1 :
142
- bag = self .bags .get_single_bag ()
143
- start_time , end_time = self .get_time_range ()
144
-
145
- try :
146
- input_start = Operation .from_datetime (start_time )
147
- input_end = Operation .from_datetime (end_time )
148
- bag_start , bag_end = bag .info .init_time_range
149
-
150
- print (f"input_start: { input_start } , input_end: { input_end } , bag_start: { bag_start } , bag_end: { bag_end } " )
151
- if input_start [0 ] < bag_start [0 ] or input_end [0 ] > bag_end [0 ]:
152
- # Reset to initial time range
153
- self .set_time_range (bag .info .init_time_range_str )
154
- self .app .notify (
155
- f"Time range reset to { bag .info .init_time_range_str [0 ]} - { bag .info .init_time_range_str [1 ]} " ,
156
- title = "Invalid Time Range" ,
157
- severity = "warning"
158
- )
159
- return
160
- except ValueError as e :
161
- self .logger .warning (f"Invalid time format: { str (e )} " )
162
- return
176
+ if not self ._validate_time_range ():
177
+ return
163
178
164
179
try :
165
180
for bag_path , bag in self .bags .bags .items ():
0 commit comments