@@ -486,6 +486,56 @@ def result(self, value):
486486 self ._result = value
487487
488488
489+ class CheckboxField :
490+ """
491+ ``CheckboxField`` prompts the user to choose a yes/no option in a checkbox.
492+ Result is stored in self.result as a boolean value.
493+
494+ :param str prompt: Prompt to be presented to the user
495+ :param bool default: Default state of the checkbox (False == unchecked, True == checked)
496+ """
497+ def __init__ (self , prompt , default ):
498+ self ._prompt = prompt
499+ self ._result = None
500+ self ._default = default
501+
502+ def _fill_core_struct (self , value ):
503+ value .type = FormInputFieldType .CheckboxFormField
504+ value .prompt = self ._prompt
505+ value .hasDefault = True
506+ value .intDefault = 1 if self ._default else 0
507+
508+ def _fill_core_result (self , value ):
509+ value .intResult = 1 if self .result else 0
510+
511+ def _get_result (self , value ):
512+ self ._result = value .intResult != 0
513+
514+ @property
515+ def prompt (self ):
516+ return self ._prompt
517+
518+ @prompt .setter
519+ def prompt (self , value ):
520+ self ._prompt = value
521+
522+ @property
523+ def result (self ):
524+ return self ._result
525+
526+ @result .setter
527+ def result (self , value ):
528+ self ._result = value
529+
530+ @property
531+ def default (self ):
532+ return self ._default
533+
534+ @default .setter
535+ def default (self , value ):
536+ self ._default = value
537+
538+
489539class InteractionHandler :
490540 _interaction_handler = None
491541
@@ -505,6 +555,7 @@ def __init__(self):
505555 self ._cb .getOpenFileNameInput = self ._cb .getOpenFileNameInput .__class__ (self ._get_open_filename_input )
506556 self ._cb .getSaveFileNameInput = self ._cb .getSaveFileNameInput .__class__ (self ._get_save_filename_input )
507557 self ._cb .getDirectoryNameInput = self ._cb .getDirectoryNameInput .__class__ (self ._get_directory_name_input )
558+ self ._cb .getCheckboxInput = self ._cb .getCheckboxInput .__class__ (self ._get_checkbox_input )
508559 self ._cb .getFormInput = self ._cb .getFormInput .__class__ (self ._get_form_input )
509560 self ._cb .showMessageBox = self ._cb .showMessageBox .__class__ (self ._show_message_box )
510561 self ._cb .openUrl = self ._cb .openUrl .__class__ (self ._open_url )
@@ -650,6 +701,16 @@ def _get_directory_name_input(self, ctxt, result, prompt, default_name):
650701 except :
651702 log_error (traceback .format_exc ())
652703
704+ def _get_checkbox_input (self , ctxt , result , prompt , default_choice ):
705+ try :
706+ value = self .get_checkbox_input (prompt , default_choice )
707+ if value is None :
708+ return False
709+ result [0 ] = value
710+ return True
711+ except :
712+ log_error (traceback .format_exc ())
713+
653714 def _get_form_input (self , ctxt , fields , count , title ):
654715 try :
655716 field_objs = []
@@ -714,6 +775,14 @@ def _get_form_input(self, ctxt, fields, count, title):
714775 default = fields [i ].stringDefault if fields [i ].hasDefault else None
715776 )
716777 )
778+ elif fields [i ].type == FormInputFieldType .CheckboxFormField :
779+ log_error (fields [i ].hasDefault )
780+ field_objs .append (
781+ CheckboxField (
782+ fields [i ].prompt ,
783+ default = fields [i ].intDefault != 0 if fields [i ].hasDefault else None
784+ )
785+ )
717786 else :
718787 field_objs .append (LabelField (fields [i ].prompt ))
719788 if not self .get_form_input (field_objs , title ):
@@ -795,6 +864,9 @@ def get_save_filename_input(self, prompt, ext, default_name):
795864 def get_directory_name_input (self , prompt , default_name ):
796865 return get_text_line_input (prompt , "Select Directory" )
797866
867+ def get_checkbox_input (self , prompt , default_choice ):
868+ return get_checkbox_input (prompt , "Choose Option(s)" , default_choice )
869+
798870 def get_form_input (self , fields , title ):
799871 return False
800872
@@ -1361,6 +1433,22 @@ def get_directory_name_input(prompt: str, default_name: str = ""):
13611433 core .free_string (value )
13621434 return result .decode ("utf-8" )
13631435
1436+ def get_checkbox_input (prompt : str , title : str , default : bool = False ):
1437+ """
1438+ ``get_checkbox_input`` prompts the user for a checkbox input
1439+ :param prompt: String to prompt with
1440+ :param title: Title of the window when executed in the UI
1441+ :param default: Optional default state for the checkbox (false == unchecked, true == checked), False if not set.
1442+ :rtype: bool indicating the state of the checkbox
1443+ """
1444+ default_state = ctypes .c_int64 ()
1445+ default_state .value = 1 if default else 0
1446+ value = ctypes .c_int64 ()
1447+ if not core .BNGetCheckboxInput (value , prompt , title , default_state ):
1448+ return None
1449+ result = value .value
1450+ assert result is not None
1451+ return result != 0
13641452
13651453def get_form_input (fields , title ):
13661454 """
@@ -1382,6 +1470,7 @@ def get_form_input(fields, title):
13821470 OpenFileNameField Prompt for file to open
13831471 SaveFileNameField Prompt for file to save to
13841472 DirectoryNameField Prompt for directory name
1473+ CheckboxFormField Prompt for a checkbox
13851474 ===================== ===================================================
13861475
13871476 This API is flexible and works both in the UI via a pop-up dialog and on the command-line.
0 commit comments