def _select_template(self, sim_info: SimInfo, on_close: Callable[[], None] = None): self.log.format_with_message('Opening dialog.', sim=sim_info) def _on_close() -> None: self.log.debug('Slider Template dialog closed.') if on_close is not None: on_close() option_dialog = CommonChooseObjectOptionDialog( CSFStringId.SELECTED_TEMPLATE, CSFStringId.PLEASE_SELECT_A_TEMPLATE, mod_identity=self.mod_identity, on_close=_on_close, per_page=400) self.log.debug('Opening Customize Slider dialog.') def _on_chosen(_: str, _chosen_template: CSFSliderTemplate): if _chosen_template is None: self.log.debug('No template name entered, dialog closed.') _on_close() return self.log.format_with_message( 'Template name entered.', template_name=_chosen_template.template_name) CSFSliderTemplateDialog._SELECTED_TEMPLATE = _chosen_template _on_close() for (template_name, template) in self._template_utils.template_library.items(): template: CSFSliderTemplate = template option_dialog.add_option( CommonDialogObjectOption( template_name, template, CommonDialogOptionContext( template.display_name, 0, icon=CommonIconUtils.load_filled_circle_icon() if CSFSliderTemplateDialog._SELECTED_TEMPLATE == template else CommonIconUtils.load_unfilled_circle_icon(), ), on_chosen=_on_chosen)) if not option_dialog.has_options(): def _on_acknowledge(_) -> None: _on_close() CommonOkDialog(CSFStringId.NO_TEMPLATES_DETECTED_NAME, CSFStringId.NO_TEMPLATES_DETECTED_DESCRIPTION, mod_identity=self.mod_identity).show( on_acknowledged=_on_acknowledge) return option_dialog.show(sim_info=sim_info)
def _select_option(self, title: int, description: LocalizedString, current_string: int, setting_name: str, on_name: int, off_name: int, on_chosen: Callable[[str, Union[bool, int]], Any], on_close: Callable[[], Any] = None): def _on_close() -> None: if on_close is not None: on_close() option_dialog = CommonChooseObjectOptionDialog( title, description, title_tokens=(current_string, ), mod_identity=self.mod_identity, on_close=_on_close) current_val = self._data_store.get_value_by_key(setting_name) @CommonExceptionHandler.catch_exceptions(self.mod_identity) def _on_chosen(_: str, picked_option: bool): if picked_option is None: _on_close() return on_chosen(_, picked_option) option_dialog.add_option( CommonDialogSelectOption( setting_name, -1, CommonDialogOptionContext( CGSStringId.DISABLED, 0, icon=CommonIconUtils.load_filled_circle_icon() if current_val is None else CommonIconUtils.load_unfilled_circle_icon()), on_chosen=_on_chosen)) option_dialog.add_option( CommonDialogSelectOption( setting_name, True, CommonDialogOptionContext( on_name, 0, icon=CommonIconUtils.load_filled_circle_icon() if current_val is True else CommonIconUtils.load_unfilled_circle_icon()), on_chosen=_on_chosen)) option_dialog.add_option( CommonDialogSelectOption( setting_name, False, CommonDialogOptionContext( off_name, 0, icon=CommonIconUtils.load_filled_circle_icon() if current_val is False else CommonIconUtils.load_unfilled_circle_icon()), on_chosen=_on_chosen)) option_dialog.show()