def _OnDialogResponse(self, dialog: ui_dialog_picker.UiObjectPicker, *args, **kwargs) -> None: dialogButtons = kwargs[ "dialogButtons"] # type: typing.List[DialogButton] dialogRows = kwargs["dialogRows"] # type: typing.List[DialogRow] if dialog.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK: resultRows = dialog.get_result_rows( ) # type: typing.List[ui_dialog_picker.BasePickerRow] for resultRow in resultRows: # type: ui_dialog_picker.BasePickerRow for dialogRow in dialogRows: # type: DialogRow if dialogRow.OptionID == resultRow.option_id: dialogRow.Callback(dialog) acceptButtonCallback = kwargs[ "acceptButtonCallback"] # type: typing.Callable[[ui_dialog.UiDialog], None] acceptButtonCallback(dialog) if dialog.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL: cancelButtonCallback = kwargs[ "cancelButtonCallback"] # type: typing.Callable[[ui_dialog.UiDialog], None] cancelButtonCallback(dialog) for dialogButton in dialogButtons: # type: DialogButton if dialog.response == dialogButton.ResponseID: dialogButton.Callback(dialog)
def _create_dialog(self, picker_type: UiObjectPicker.UiObjectPickerObjectPickerType=UiObjectPicker.UiObjectPickerObjectPickerType.OBJECT) -> Union[UiObjectPicker, None]: return UiObjectPicker.TunableFactory().default(CommonSimUtils.get_active_sim_info(), text=lambda *_, **__: self.description, title=lambda *_, **__: self.title, min_selectable=1, max_selectable=1, picker_type=picker_type)
def _create_dialog( self, picker_type: UiObjectPicker. UiObjectPickerObjectPickerType = UiObjectPicker. UiObjectPickerObjectPickerType.OBJECT, sim_info: SimInfo = None, categories: Iterator[CommonDialogObjectOptionCategory] = (), min_selectable: int = 1, max_selectable: int = 1) -> Union[UiObjectPicker, None]: try: from collections import namedtuple object_category_type = namedtuple( 'object_category_type', ('object_category', 'icon', 'category_name')) object_categories = list() for category in tuple(categories): object_categories.append( object_category_type( category.object_category, lambda *_, **__: IconInfoData(icon_resource=CommonIconUtils._load_icon( category.icon)), CommonLocalizationUtils.create_localized_string( category.category_name))) if len(object_categories) > 0: self.log.debug('Building dialog with categories.') return CommonUiObjectCategoryPicker.TunableFactory().default( sim_info or CommonSimUtils.get_active_sim_info(), text=lambda *_, **__: self.description, title=lambda *_, **__: self.title, picker_type=picker_type, use_dropdown_filter=True, object_categories=tuple(object_categories), min_selectable=min_selectable, max_selectable=max_selectable) else: self.log.debug('Building dialog without categories.') return UiObjectPicker.TunableFactory().default( sim_info or CommonSimUtils.get_active_sim_info(), text=lambda *_, **__: self.description, title=lambda *_, **__: self.title, picker_type=picker_type, min_selectable=min_selectable, max_selectable=max_selectable) except Exception as ex: self.log.error('_create_dialog', exception=ex) return None
def _create_dialog( self, picker_type: UiObjectPicker. UiObjectPickerObjectPickerType = UiObjectPicker. UiObjectPickerObjectPickerType.OBJECT, sim_info: SimInfo = None) -> Union[UiObjectPicker, None]: try: return UiObjectPicker.TunableFactory().default( sim_info or CommonSimUtils.get_active_sim_info(), text=lambda *_, **__: self.description, title=lambda *_, **__: self.title, min_selectable=1, max_selectable=1, picker_type=picker_type) except Exception as ex: CommonExceptionHandler.log_exception(self.mod_identity.name, '_create_dialog', exception=ex) return None
def display(text, title, picker_rows, min_selectable=1, max_selectable=1, sim=None, callback=None): picker_list_dialog = UiObjectPicker.TunableFactory().default( sim or TurboUIUtil._get_client_sim(), text=lambda *args, **kwargs: text, title=lambda *args, **kwargs: title, min_selectable=min_selectable, max_selectable=max_selectable) for picker_row in picker_rows: if picker_row is None: pass picker_list_dialog.add_row(picker_row.get_object_picker_row()) if callback is not None: picker_list_dialog.add_listener(callback) picker_list_dialog.show_dialog()
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_rows in self.always_visible_rows: _dialog.add_row(always_visible_rows) # 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_rows in self.always_visible_rows: _dialog.add_row(always_visible_rows) self.log.debug('Adding rows.') for row in self.rows: _dialog.add_row(row)