def icon(self) -> Any: if super().icon is not None: return super().icon return CommonIconUtils.load_arrow_right_icon()
def _show(self, on_chosen: Callable[[Any, CommonChoiceOutcome], Any] = CommonFunctionUtils.noop, picker_type: UiObjectPicker. UiObjectPickerObjectPickerType = UiObjectPicker. UiObjectPickerObjectPickerType.OBJECT, page: int = 1, sim_info: SimInfo = None): self.log.format_with_message('Attempting to display choices.', page=page) _dialog = self._create_dialog(picker_type=picker_type) if _dialog is None: self.log.error('_dialog was None for some reason.') return if on_chosen is None: raise ValueError('on_chosen was None.') if len(self.rows) == 0: raise AssertionError( 'No rows have been provided. Add rows to the dialog before attempting to display it.' ) if page < 0: raise AssertionError('page cannot be less than zero.') @CommonExceptionHandler.catch_exceptions(self.mod_identity.name) def _on_chosen(dialog: UiObjectPicker): if not dialog.accepted: self.log.debug('Dialog cancelled.') return on_chosen(None, CommonChoiceOutcome.CANCEL) choice = CommonDialogUtils.get_chosen_item(dialog) if choice == 'S4CL_NEXT': self.log.debug('Next chosen.') self.show(on_chosen=on_chosen, picker_type=picker_type, page=page + 1, sim_info=sim_info) return True elif choice == 'S4CL_PREVIOUS': self.log.debug('Previous chosen.') self.show(on_chosen=on_chosen, picker_type=picker_type, page=page - 1, sim_info=sim_info) return True self.log.format_with_message('Choice made.', choice=choice) result = on_chosen(choice, CommonChoiceOutcome.CHOICE_MADE) self.log.format_with_message('Finished handling choice.', result=result) return result number_of_rows = len(self.rows) self.log.format(number_of_rows=number_of_rows, per_page=self._per_page) if number_of_rows > self._per_page: number_of_pages = math.ceil(number_of_rows / self._per_page) if page > number_of_pages: raise AssertionError( 'page was out of range. Number of Pages: {}, Requested Page: {}' .format(str(number_of_pages), str(page))) start_index = (page - 1) * self._per_page end_index = page * self._per_page self.log.format(start_index=start_index, end_index=end_index) current_choices = self.rows[start_index:end_index] self.log.format(current_rows=current_choices) for row in current_choices: _dialog.add_row(row) if page < number_of_pages: self.log.format_with_message('Adding Next.', page=page, number_of_pages=number_of_pages) next_choice = ObjectPickerRow( option_id=len(self.rows) + 1, name=CommonLocalizationUtils.create_localized_string( CommonStringId.NEXT), row_description=None, row_tooltip=None, icon=CommonIconUtils.load_arrow_right_icon(), tag='S4CL_NEXT') _dialog.add_row(next_choice) else: self.log.format_with_message('Not adding Next.', page=page, number_of_pages=number_of_pages) if page > 1: self.log.format_with_message('Adding Previous.', page=page, number_of_pages=number_of_pages) previous_choice = ObjectPickerRow( option_id=len(self.rows) + 2, name=CommonLocalizationUtils.create_localized_string( CommonStringId.PREVIOUS), row_description=None, row_tooltip=None, icon=CommonIconUtils.load_arrow_right_icon(), tag='S4CL_PREVIOUS') _dialog.add_row(previous_choice) else: self.log.format_with_message('Not adding Previous.', page=page) else: self.log.debug('Adding all choices') for row in self.rows: _dialog.add_row(row) _dialog.add_listener(_on_chosen) _dialog.show_dialog()
def open(self) -> None: """ Open Dialog. """ def _on_close() -> None: if self._on_close is not None: self._on_close() def _reopen(*_, **__) -> None: self.open() option_dialog = CommonChooseObjectOptionDialog( CGSStringId.GLOBAL_SETTINGS_NAME, CGSStringId.GLOBAL_SETTINGS_DESCRIPTION, mod_identity=self.mod_identity, on_close=_on_close) @CommonExceptionHandler.catch_exceptions(self.mod_identity) def _on_force_all_chosen(_: str, picked_option: Union[int, bool]): if picked_option is None: return if picked_option == -1: self._data_store.set_value_by_key(_, None) _reopen() return @CommonExceptionHandler.catch_exceptions(self.mod_identity) def _on_ok(_d): self.log.debug('Ok chosen {}, \'{}\''.format(picked_option, _)) self._data_store.set_value_by_key(_, picked_option) self.log.format_with_message( 'set value with', val=self._data_store.get_value_by_key(_)) for sim_info in CommonSimUtils.get_instanced_sim_info_for_all_sims_generator( ): _CGSUpdateGenderOptions()._update_gender_options(sim_info) _reopen() def _on_cancel(_d): self.log.debug('Cancel chosen') _reopen() CommonOkCancelDialog( CGSStringId.PLEASE_CONFIRM_NAME, CGSStringId.PLEASE_CONFIRM_DESCRIPTION, ok_text_identifier=CGSStringId.YES_UPDATE_ALL_SIMS, cancel_text_identifier=CGSStringId.NO).show( on_ok_selected=_on_ok, on_cancel_selected=_on_cancel) current_force_all_val = self._data_store.get_value_by_key( CGSGlobalSetting.ALL_SIMS_FORCE_AS_MALE) force_all_selected_string = CGSStringId.DISABLED if current_force_all_val is True: force_all_selected_string = CGSStringId.MALE elif current_force_all_val is False: force_all_selected_string = CGSStringId.FEMALE option_dialog.add_option( CommonDialogActionOption( CommonDialogOptionContext( CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_NAME, CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_DESCRIPTION, title_tokens=(force_all_selected_string, )), on_chosen=lambda *_, **__: self._select_option( CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_NAME, CGSStringId.CGS_FORCE_ALL_SIMS_TO_GENDER_DESCRIPTION, force_all_selected_string, CGSGlobalSetting.ALL_SIMS_FORCE_AS_MALE, CGSStringId.MALE, CGSStringId.FEMALE, on_chosen=_on_force_all_chosen, on_close=_reopen))) def _set_all_to_vanilla_gender_options_chosen(): for sim_info in CommonSimUtils.get_instanced_sim_info_for_all_sims_generator( ): if CommonGenderUtils.is_male(sim_info): CommonSimGenderOptionUtils.update_gender_options_to_vanilla_male( sim_info) else: CommonSimGenderOptionUtils.update_gender_options_to_vanilla_female( sim_info) _reopen() option_dialog.add_option( CommonDialogActionOption( CommonDialogOptionContext( CGSStringId.SET_ALL_SIMS_TO_VANILLA_GENDER_OPTIONS_NAME, CGSStringId. SET_ALL_SIMS_TO_VANILLA_GENDER_OPTIONS_DESCRIPTION, icon=CommonIconUtils.load_arrow_right_icon()), on_chosen=_set_all_to_vanilla_gender_options_chosen)) option_dialog.add_option( CommonDialogActionOption(CommonDialogOptionContext( CGSStringId.ALL_MALE_SIM_OPTIONS, CGSStringId.ALL_MALE_SIM_OPTIONS_DESCRIPTION, icon=CommonIconUtils.load_arrow_navigate_into_icon()), on_chosen=lambda *_, **__: self. _all_male_options(on_close=_reopen))) option_dialog.add_option( CommonDialogActionOption(CommonDialogOptionContext( CGSStringId.ALL_FEMALE_SIM_OPTIONS, CGSStringId.ALL_FEMALE_SIM_OPTIONS_DESCRIPTION, icon=CommonIconUtils.load_arrow_navigate_into_icon()), on_chosen=lambda *_, **__: self. _all_female_options(on_close=_reopen))) option_dialog.show()
def _setup_dialog_rows( self, _dialog: UiObjectPicker, page: int = 1, categories: Iterator[CommonDialogObjectOptionCategory] = ()): if page < 0: raise AssertionError('page cannot be less than zero.') number_of_rows = len(self.rows) self.log.format(number_of_rows=number_of_rows, per_page=self._per_page) if number_of_rows > self._per_page: number_of_pages = math.ceil(number_of_rows / self._per_page) if page > number_of_pages: raise AssertionError( 'page was out of range. Number of Pages: {}, Requested Page: {}' .format(str(number_of_pages), str(page))) # Add the rows that are always visible. for always_visible_row in self.always_visible_rows: _dialog.add_row(always_visible_row) # Add the rows that should show on the current page. start_index = (page - 1) * self._per_page end_index = page * self._per_page self.log.format(start_index=start_index, end_index=end_index) current_choices = self.rows[start_index:end_index] self.log.format(current_rows=current_choices) for row in current_choices: _dialog.add_row(row) tag_list = [(abs(hash(category.object_category)) % (10**8)) for category in categories] self.log.format_with_message('Found tags.', tag_list=tag_list) if page > 1: self.log.format_with_message('Adding Previous row.', page=page, number_of_pages=number_of_pages) previous_choice = ObjectPickerRow( option_id=len(self.rows) + 2, name=CommonLocalizationUtils.create_localized_string( CommonStringId.PREVIOUS), row_description=None, row_tooltip=CommonLocalizationUtils. create_localized_tooltip(CommonStringId.PREVIOUS), icon=CommonIconUtils.load_arrow_left_icon(), tag_list=tag_list, tag=CommonDialogNavigationButtonTag.PREVIOUS) _dialog.add_row(previous_choice) else: self.log.format_with_message('Not adding Previous row.', page=page) if page < number_of_pages: self.log.format_with_message('Adding Next row.', page=page, number_of_pages=number_of_pages) next_choice = ObjectPickerRow( option_id=len(self.rows) + 1, name=CommonLocalizationUtils.create_localized_string( CommonStringId.NEXT), row_description=None, row_tooltip=CommonLocalizationUtils. create_localized_tooltip(CommonStringId.NEXT), icon=CommonIconUtils.load_arrow_right_icon(), tag_list=tag_list, tag=CommonDialogNavigationButtonTag.NEXT) _dialog.add_row(next_choice) else: self.log.format_with_message('Not adding Next.', page=page, number_of_pages=number_of_pages) else: self.log.debug('Adding always visible rows.') for always_visible_row in self.always_visible_rows: _dialog.add_row(always_visible_row) self.log.debug('Adding rows.') for row in self.rows: _dialog.add_row(row)