@@ -372,6 +372,80 @@ def call(self):
372372 return None
373373 return dlg .GetValue ()
374374
375+ # memory of last dropdowns
376+ last_dropdown_selection = {}
377+ last_value_selection = {}
378+
379+ class MPMenuCallTextDropdownDialog (object ):
380+ '''used to create a value dialog with dropdown callback'''
381+ def __init__ (self , title = 'Enter Value' , default = '' , dropdown_options = None , dropdown_label = 'Select option' , settings = None ):
382+ self .title = title
383+ self .default = default
384+ self .dropdown_options = dropdown_options or []
385+ self .dropdown_label = dropdown_label
386+ self .settings = settings
387+
388+ def call (self ):
389+ '''show a value dialog with dropdown'''
390+ from MAVProxy .modules .lib .wx_loader import wx
391+
392+ # Create a custom dialog
393+ dlg = wx .Dialog (None , title = self .title , size = (400 , 150 ))
394+
395+ # Create a vertical box sizer for the dialog
396+ main_sizer = wx .BoxSizer (wx .VERTICAL )
397+
398+ # Create a horizontal sizer for the text entry and dropdown
399+ input_sizer = wx .BoxSizer (wx .HORIZONTAL )
400+
401+ # Text entry label and control
402+ text_label = wx .StaticText (dlg , label = "Value:" )
403+ default = last_value_selection .get (self .title , self .default )
404+ text_ctrl = wx .TextCtrl (dlg , value = str (default ), size = (200 , - 1 ))
405+
406+ # Add text control components to input sizer
407+ input_sizer .Add (text_label , 0 , wx .ALL | wx .ALIGN_CENTER_VERTICAL , 5 )
408+ input_sizer .Add (text_ctrl , 1 , wx .ALL | wx .EXPAND , 5 )
409+
410+ # Dropdown label and control
411+ dropdown_label = wx .StaticText (dlg , label = self .dropdown_label )
412+ dropdown_ctrl = wx .Choice (dlg , choices = self .dropdown_options )
413+
414+ # Select first item by default if options exist
415+ if self .dropdown_options :
416+ dropdown_ctrl .SetSelection (last_dropdown_selection .get (self .title ,0 ))
417+
418+ # Add dropdown components to input sizer
419+ input_sizer .Add (dropdown_label , 0 , wx .ALL | wx .ALIGN_CENTER_VERTICAL , 5 )
420+ input_sizer .Add (dropdown_ctrl , 0 , wx .ALL | wx .EXPAND , 5 )
421+
422+ # Add the input sizer to the main sizer
423+ main_sizer .Add (input_sizer , 0 , wx .ALL | wx .EXPAND , 5 )
424+
425+ # Create button sizer with OK and Cancel buttons
426+ button_sizer = dlg .CreateButtonSizer (wx .OK | wx .CANCEL )
427+ main_sizer .Add (button_sizer , 0 , wx .ALL | wx .ALIGN_CENTER , 10 )
428+
429+ # Set the sizer for the dialog
430+ dlg .SetSizer (main_sizer )
431+
432+ # Fit the dialog to its contents
433+ dlg .Fit ()
434+
435+ # Show the dialog and get the result
436+ if dlg .ShowModal () != wx .ID_OK :
437+ return None
438+
439+ text_value = text_ctrl .GetValue ()
440+ dropdown_index = dropdown_ctrl .GetSelection ()
441+ dropdown_value = self .dropdown_options [dropdown_index ] if dropdown_index != - 1 and self .dropdown_options else ""
442+
443+ last_dropdown_selection [self .title ] = dropdown_index
444+ last_value_selection [self .title ] = text_value
445+
446+ # Return tuple with text value and selected dropdown value
447+ return text_value + " " + dropdown_value
448+
375449class MPMenuConfirmDialog (object ):
376450 '''used to create a confirmation dialog'''
377451 def __init__ (self , title = 'Confirmation' , message = '' , callback = None , args = None ):
0 commit comments