@@ -160,32 +160,79 @@ async def on_segment_setting_change(e):
160160 )
161161
162162 scheduled_recording = initial_values .get ("scheduled_recording" , False )
163- scheduled_start_time = initial_values .get ("scheduled_start_time" )
164- monitor_hours = initial_values .get ("monitor_hours" , 5 )
163+ scheduled_start_time = initial_values .get ("scheduled_start_time" , '' )
164+ monitor_hours = initial_values .get ("monitor_hours" , '5' )
165165 message_push_enabled = initial_values .get ('enabled_message_push' , True )
166166
167+ time_slots = 2
168+ time_inputs = []
169+ hour_inputs = []
170+ time_buttons = []
171+ time_picker_handlers = []
172+
173+ time_values = scheduled_start_time .split ("," )
174+ time_values = (time_values + ["" ] * time_slots )[:time_slots ]
175+
176+ hour_values = str (monitor_hours ).split ("," )
177+ hour_values = (hour_values + ["" ] * time_slots )[:time_slots ]
178+
179+ def create_time_picker_handler (index ):
180+ async def pick_time (_ ):
181+ async def handle_change (_ ):
182+ time_inputs [index ].value = time_picker .value
183+ time_inputs [index ].update ()
184+
185+ time_picker = ft .TimePicker (
186+ confirm_text = self ._ ['confirm' ],
187+ cancel_text = self ._ ['cancel' ],
188+ error_invalid_text = self ._ ['time_out_of_range' ],
189+ help_text = self ._ ['pick_time_slot' ],
190+ hour_label_text = self ._ ['hour_label_text' ],
191+ minute_label_text = self ._ ['minute_label_text' ],
192+ on_change = handle_change
193+ )
194+ self .page .open (time_picker )
195+ return pick_time
196+
197+ for i in range (time_slots ):
198+ time_input = ft .TextField (
199+ label = self ._ ["scheduled_start_time" ],
200+ hint_text = self ._ ["example" ] + ":18:30:00" ,
201+ border_radius = 5 ,
202+ filled = False ,
203+ value = time_values [i ],
204+ )
205+ time_inputs .append (time_input )
206+
207+ hour_input = ft .TextField (
208+ label = self ._ ["monitor_hours" ],
209+ hint_text = self ._ ["example" ] + ":5" ,
210+ border_radius = 5 ,
211+ filled = False ,
212+ value = hour_values [i ],
213+ keyboard_type = ft .KeyboardType .NUMBER ,
214+ visible = scheduled_recording ,
215+ )
216+ hour_inputs .append (hour_input )
217+
218+ handler = create_time_picker_handler (i )
219+ time_picker_handlers .append (handler )
220+
221+ button = ft .ElevatedButton (
222+ self ._ ['pick_time' ],
223+ icon = ft .Icons .TIME_TO_LEAVE ,
224+ on_click = handler ,
225+ tooltip = self ._ ['pick_time_tip' ]
226+ )
227+ time_buttons .append (button )
228+
167229 async def on_scheduled_setting_change (e ):
168230 selected_value = e .control .value
169- schedule_and_monitor_row .visible = selected_value == "true"
170- monitor_hours_input .visible = selected_value == "true"
231+ for i in range (time_slots ):
232+ time_rows [i ].visible = selected_value == "true"
233+ hour_inputs [i ].visible = selected_value == "true"
171234 self .page .update ()
172235
173- async def pick_time (_ ):
174- async def handle_change (_ ):
175- scheduled_start_time_input .value = time_picker .value
176- scheduled_start_time_input .update ()
177-
178- time_picker = ft .TimePicker (
179- confirm_text = self ._ ['confirm' ],
180- cancel_text = self ._ ['cancel' ],
181- error_invalid_text = self ._ ['time_out_of_range' ],
182- help_text = self ._ ['pick_time_slot' ],
183- hour_label_text = self ._ ['hour_label_text' ],
184- minute_label_text = self ._ ['minute_label_text' ],
185- on_change = handle_change
186- )
187- self .page .open (time_picker )
188-
189236 scheduled_setting_dropdown = ft .Dropdown (
190237 label = self ._ ["scheduled_recording" ],
191238 options = [
@@ -199,39 +246,18 @@ async def handle_change(_):
199246 width = 500 ,
200247 )
201248
202- scheduled_start_time_input = ft .TextField (
203- label = self ._ ["scheduled_start_time" ],
204- hint_text = self ._ ["example" ] + ":18:30:00" ,
205- border_radius = 5 ,
206- filled = False ,
207- value = scheduled_start_time ,
208- )
209-
210- time_picker_button = ft .ElevatedButton (
211- self ._ ['pick_time' ],
212- icon = ft .Icons .TIME_TO_LEAVE ,
213- on_click = pick_time ,
214- tooltip = self ._ ['pick_time_tip' ]
215- )
216-
217- schedule_and_monitor_row = ft .Row (
218- [
219- ft .Container (content = scheduled_start_time_input , expand = True ),
220- ft .Container (content = time_picker_button ),
221- ],
222- spacing = 10 ,
223- visible = scheduled_recording ,
224- )
225-
226- monitor_hours_input = ft .TextField (
227- label = self ._ ["monitor_hours" ],
228- hint_text = self ._ ["example" ] + ":5" ,
229- border_radius = 5 ,
230- filled = False ,
231- value = monitor_hours ,
232- keyboard_type = ft .KeyboardType .NUMBER ,
233- visible = scheduled_recording ,
234- )
249+ time_rows = []
250+ for i in range (time_slots ):
251+ row = ft .Row (
252+ [
253+ ft .Container (content = time_inputs [i ], expand = True ),
254+ ft .Container (content = hour_inputs [i ], expand = True ),
255+ ft .Container (content = time_buttons [i ]),
256+ ],
257+ spacing = 10 ,
258+ visible = scheduled_recording ,
259+ )
260+ time_rows .append (row )
235261
236262 message_push_dropdown = ft .Dropdown (
237263 label = self ._ ["enable_message_push" ],
@@ -301,8 +327,7 @@ async def handle_change(_):
301327 segment_setting_dropdown ,
302328 segment_input ,
303329 scheduled_setting_dropdown ,
304- schedule_and_monitor_row ,
305- monitor_hours_input ,
330+ * time_rows ,
306331 message_push_dropdown ,
307332 no_record_dropdown
308333 ],
@@ -363,9 +388,9 @@ async def on_confirm(e):
363388 "segment_time" : segment_input .value ,
364389 "monitor_status" : initial_values .get ("monitor_status" , True ),
365390 "display_title" : display_title ,
366- "scheduled_recording" : schedule_and_monitor_row . visible ,
367- "scheduled_start_time" : str (scheduled_start_time_input .value ),
368- "monitor_hours" : monitor_hours_input . value ,
391+ "scheduled_recording" : scheduled_setting_dropdown . value == 'true' ,
392+ "scheduled_start_time" : ',' . join ([ str (i .value ) for i in time_inputs ] ),
393+ "monitor_hours" : ',' . join ([ str ( i . value ) for i in hour_inputs ]) ,
369394 "recording_dir" : recording_dir_field .value ,
370395 "enabled_message_push" : message_push_dropdown .value == "true" ,
371396 "only_notify_no_record" : no_record_dropdown .value == "true" ,
0 commit comments