@@ -485,29 +485,30 @@ def result(self):
485485 def result (self , value ):
486486 self ._result = value
487487
488- class CheckBoxField :
488+ class CheckboxField :
489489 """
490- ``CheckBoxField `` prompts the user to choose a yes/no option in a checkbox.
490+ ``CheckboxField `` prompts the user to choose a yes/no option in a checkbox.
491491 Result is stored in self.result as a boolean value.
492492
493493 :param str prompt: Prompt to be presented to the user
494- :param Optional[bool]: Optional boolean value for the default setting of the checkbox. \
495- by default set to 'false'
494+ :param bool default: Default state of the checkbox (False == unchecked, True == checked)
496495 """
497- def __init__ (self , prompt , default = None ):
496+ def __init__ (self , prompt , default ):
498497 self ._prompt = prompt
499- self ._default = default
500498 self ._result = None
499+ self ._default = default
501500
502501 def _fill_core_struct (self , value ):
503- value .type = FormInputFieldType .CheckBoxFormField
502+ value .type = FormInputFieldType .CheckboxFormField
504503 value .prompt = self ._prompt
505- value .hasDefault = self ._default is not None
506- if self ._default is not None :
507- value .boolDefault = self ._default
504+ value .hasDefault = True
505+ value .intDefault = 1 if self ._default else 0
508506
509507 def _fill_core_result (self , value ):
510- self ._boolResult = value .result
508+ value .intResult = 1 if self .result else 0
509+
510+ def _get_result (self , value ):
511+ self ._result = value .intResult != 0
511512
512513 @property
513514 def prompt (self ):
@@ -699,6 +700,16 @@ def _get_directory_name_input(self, ctxt, result, prompt, default_name):
699700 except :
700701 log_error (traceback .format_exc ())
701702
703+ def _get_checkbox_input (self , ctxt , result , prompt , default_choice ):
704+ try :
705+ value = self .get_checkbox_input (prompt , default_choice )
706+ if value is None :
707+ return False
708+ result [0 ] = value
709+ return True
710+ except :
711+ log_error (traceback .format_exc ())
712+
702713 def _get_form_input (self , ctxt , fields , count , title ):
703714 try :
704715 field_objs = []
@@ -763,10 +774,12 @@ def _get_form_input(self, ctxt, fields, count, title):
763774 default = fields [i ].stringDefault if fields [i ].hasDefault else None
764775 )
765776 )
766- elif fields [i ].type == FormInputFieldType .CheckBoxFormField :
777+ elif fields [i ].type == FormInputFieldType .CheckboxFormField :
778+ log_error (fields [i ].hasDefault )
767779 field_objs .append (
768- CheckBoxField (
769- fields [i ].prompt , default = fields [i ].boolDefault if fields [i ].hasDefault else None
780+ CheckboxField (
781+ fields [i ].prompt ,
782+ default = fields [i ].intDefault != 0 if fields [i ].hasDefault else None
770783 )
771784 )
772785 else :
@@ -850,6 +863,9 @@ def get_save_filename_input(self, prompt, ext, default_name):
850863 def get_directory_name_input (self , prompt , default_name ):
851864 return get_text_line_input (prompt , "Select Directory" )
852865
866+ def get_checkbox_input (self , prompt , default_choice ):
867+ return get_checkbox_input (prompt , "Choose Option(s)" , default_choice )
868+
853869 def get_form_input (self , fields , title ):
854870 return False
855871
@@ -1416,19 +1432,22 @@ def get_directory_name_input(prompt: str, default_name: str = ""):
14161432 core .free_string (value )
14171433 return result .decode ("utf-8" )
14181434
1419- def get_checkbox_input (prompt : str , title : str ):
1435+ def get_checkbox_input (prompt : str , title : str , default : bool = False ):
14201436 """
1421- ``get_checkbox_input`` prompts the user for a checkbox input, and returns True if the checkbox is checked, otherwise returns False.
1437+ ``get_checkbox_input`` prompts the user for a checkbox input
14221438 :param prompt: String to prompt with
14231439 :param title: Title of the window when executed in the UI
1440+ :param default: Optional default state for the checkbox (false == unchecked, true == checked), False if not set.
14241441 :rtype: bool indicating the state of the checkbox
14251442 """
1426- value = ctypes .c_bool ()
1427- if not core .BNGetCheckboxInput (value , prompt , title ):
1443+ default_state = ctypes .c_int64 ()
1444+ default_state .value = 1 if default else 0
1445+ value = ctypes .c_int64 ()
1446+ if not core .BNGetCheckboxInput (value , prompt , title , default_state ):
14281447 return None
14291448 result = value .value
14301449 assert result is not None
1431- return result
1450+ return result != 0
14321451
14331452def get_form_input (fields , title ):
14341453 """
@@ -1450,6 +1469,7 @@ def get_form_input(fields, title):
14501469 OpenFileNameField Prompt for file to open
14511470 SaveFileNameField Prompt for file to save to
14521471 DirectoryNameField Prompt for directory name
1472+ CheckboxFormField Prompt for a checkbox
14531473 ===================== ===================================================
14541474
14551475 This API is flexible and works both in the UI via a pop-up dialog and on the command-line.
0 commit comments