コード例 #1
0
    def _AskToDoTheyThemFix(cls, callback: typing.Callable[[bool],
                                                           None]) -> None:
        def createDialogCallback() -> typing.Callable:
            def dialogCallback(
                    shownDialog: ui_dialog.UiDialogOkCancel) -> None:
                callback(shownDialog.accepted)

            return dialogCallback

        dialogArguments = {
            "title":
            cls.AskToDoTheyAreFixDialogTitle.GetCallableLocalizationString(),
            "text":
            cls.AskToDoTheyAreFixDialogText.GetCallableLocalizationString(),
            "text_ok":
            cls.AskToDoTheyAreFixDialogYesButton.GetCallableLocalizationString(
            ),
            "text_cancel":
            cls.AskToDoTheyAreFixDialogNoButton.GetCallableLocalizationString(
            )
        }  # type: typing.Dict[str, ...]

        UIDialogs.ShowOkCancelDialog(callback=createDialogCallback(),
                                     queue=False,
                                     **dialogArguments)
コード例 #2
0
ファイル: Generic.py プロジェクト: NeonOcean/S4.Main
def ShowOpenBrowserDialog (url: str, returnCallback: typing.Optional[typing.Callable[[], None]] = None) -> None:
	"""
	Show a dialog asking the user to confirm their intention to open a website in their browser.
	:param url: The url to be opened when the user clicks the ok button.
	:type url: str
	:param returnCallback: Called after the dialog has closed.
	:type returnCallback: typing.Optional[typing.Callable[[], None]]
	"""

	if not isinstance(url, str):
		raise Exceptions.IncorrectTypeException(url, "url", (str,))

	if not isinstance(returnCallback, typing.Callable) and returnCallback is not None:
		raise Exceptions.IncorrectTypeException(returnCallback, "returnCallback", ("Callable", None))

	dialogArguments = {
		"text": OpenBrowserDialogText.GetCallableLocalizationString(url),
		"text_ok": OpenBrowserDialogYesButton.GetCallableLocalizationString(),
		"text_cancel": OpenBrowserDialogNoButton.GetCallableLocalizationString()
	}

	def DialogCallback (dialogReference: ui_dialog.UiDialogOkCancel) -> None:
		try:
			if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
				webbrowser.open(url, new = 2)

			if returnCallback is not None:
				returnCallback()
		except Exception:
			Debug.Log("Failed to run the callback for the open browser dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__)

	Dialogs.ShowOkCancelDialog(callback = DialogCallback, queue = False, **dialogArguments)
コード例 #3
0
        def ResetAllButtonCallback(
                listDialogReference: ui_dialog.UiDialog) -> None:
            def ResetAllConfirmDialogCallback(
                    confirmDialogReference: ui_dialog.UiDialog) -> None:
                if confirmDialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
                    self.SettingsSystem.ResetAll()

                self.ShowDialog(listPath,
                                returnCallback=returnCallback,
                                **showDialogArguments)

            confirmDialogArguments = {
                "title":
                Language.MakeLocalizationStringCallable(
                    self._GetResetAllConfirmDialogTitleText()),
                "text":
                Language.MakeLocalizationStringCallable(
                    self._GetResetAllConfirmDialogDescriptionText()),
                "text_ok":
                Language.MakeLocalizationStringCallable(
                    self._GetResetAllConfirmDialogYesButtonText()),
                "text_cancel":
                Language.MakeLocalizationStringCallable(
                    self._GetResetAllConfirmDialogNoButtonText())
            }

            Dialogs.ShowOkCancelDialog(callback=ResetAllConfirmDialogCallback,
                                       queue=False,
                                       **confirmDialogArguments)
コード例 #4
0
ファイル: Reporting.py プロジェクト: NeonOcean/S4.Main
def _ShowReportCreatedDialog() -> None:
    dialogArguments = {
        "title": ReportCreatedDialogTitle.GetCallableLocalizationString(),
        "text": ReportCreatedDialogText.GetCallableLocalizationString(),
        "text_ok": ReportCreatedDialogButton.GetCallableLocalizationString(),
    }

    Dialogs.ShowOkDialog(queue=False, **dialogArguments)
コード例 #5
0
    def _ShowDeleteSetConfirmDialog(
            self,
            editingSetTitle: str,
            setting: UISettingsShared.SettingWrapper,
            currentValue: typing.Any,
            showDialogArguments: typing.Dict[str, typing.Any],
            returnCallback: typing.Callable[[], None] = None,
            *args,
            **kwargs) -> None:

        editingPronounSetIdentifier = showDialogArguments[
            "editingPronounSetIdentifier"]  # type: str

        def deleteSetConfirmDialog(
            shownDeleteSetConfirmDialog: ui_dialog_generic.
            UiDialogTextInputOkCancel
        ) -> None:
            if shownDeleteSetConfirmDialog.accepted:
                currentValue.pop(editingPronounSetIdentifier, None)

                setting.Set(currentValue)

                if returnCallback is not None:
                    returnCallback()
            else:
                self._ShowDialogInternal(
                    setting,
                    currentValue,
                    showDialogArguments=showDialogArguments,
                    returnCallback=returnCallback,
                    *args,
                    **kwargs)

        dialogArguments = {
            "title":
            Language.MakeLocalizationStringCallable(
                self._GetDeleteSetConfirmDialogTitle()),
            "text":
            Language.MakeLocalizationStringCallable(
                self._GetDeleteSetConfirmDialogText(editingSetTitle)),
            "text_ok":
            Language.MakeLocalizationStringCallable(
                self._GetDeleteSetConfirmDialogOkButton()),
            "text_cancel":
            Language.MakeLocalizationStringCallable(
                self._GetDeleteSetConfirmDialogCancelButton()),
        }

        UIDialogs.ShowOkCancelDialog(callback=deleteSetConfirmDialog,
                                     queue=False,
                                     **dialogArguments)
コード例 #6
0
def ShowPresetConfirmDialog(
        callback: typing.Callable[[ui_dialog.UiDialog], None]) -> None:
    if services.current_zone() is None:
        Debug.Log("Tried to show setting dialog before a zone was loaded.\n" +
                  str.join("", traceback.format_stack()),
                  This.Mod.Namespace,
                  Debug.LogLevels.Warning,
                  group=This.Mod.Namespace,
                  owner=__name__)
        return

    dialogArguments = {
        "title": PresetConfirmDialogTitle.GetCallableLocalizationString(),
        "text": PresetConfirmDialogText.GetCallableLocalizationString(),
        "text_ok":
        PresetConfirmDialogYesButton.GetCallableLocalizationString(),
        "text_cancel":
        PresetConfirmDialogNoButton.GetCallableLocalizationString()
    }

    Dialogs.ShowOkCancelDialog(callback=callback, **dialogArguments)
コード例 #7
0
    def DialogCallback(dialogReference: ui_dialog.UiDialogOkCancel) -> None:
        try:
            if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
                return

            confirmDialogCallback = None  # type: typing.Optional[typing.Callable]
            confirmDialogText = None  # type: typing.Optional[typing.Callable]

            if dialogReference.response == everythingResponseID:
                confirmDialogCallback = ConfirmDialogEverythingCallback
                confirmDialogText = ConfirmDialogEverythingText.GetCallableLocalizationString(
                )
            elif dialogReference.response == settingsResponseID:
                confirmDialogCallback = ConfirmDialogSettingsCallback
                confirmDialogText = ConfirmDialogSettingsText.GetCallableLocalizationString(
                )

            confirmDialogArguments = {
                "title":
                ConfirmDialogTitle.GetCallableLocalizationString(mod.Name),
                "text":
                confirmDialogText,
                "text_ok":
                ConfirmDialogYesButton.GetCallableLocalizationString(),
                "text_cancel":
                ConfirmDialogNoButton.GetCallableLocalizationString()
            }  # type: typing.Dict[str, ...]

            Dialogs.ShowOkCancelDialog(callback=confirmDialogCallback,
                                       queue=False,
                                       **confirmDialogArguments)
        except Exception:
            Debug.Log("Failed to run the callback for the reset dialog.",
                      This.Mod.Namespace,
                      Debug.LogLevels.Exception,
                      group=This.Mod.Namespace,
                      owner=__name__)
コード例 #8
0
ファイル: Generic.py プロジェクト: NeonOcean/S4.Main
def ShowAboutModDialog (mod: Mods.Mod, returnCallback: typing.Optional[typing.Callable[[], None]] = None) -> None:
	"""
	:param mod: The mod for the about dialog to show information on.
	:type mod: Mods.Mod
	:param returnCallback: Called after the dialog has closed.
	:type returnCallback: typing.Optional[typing.Callable[[], None]]
	"""

	if not isinstance(mod, Mods.Mod):
		raise Exceptions.IncorrectTypeException(mod, "mod", (Mods.Mod,))

	if mod.BuildDate is not None:
		buildDate = str(mod.BuildDate.date())  # type: typing.Union[str, localization.LocalizedString]
	else:
		buildDate = AboutModDialogUnknown.GetLocalizationString()  # type: typing.Union[str, localization.LocalizedString]

	if mod.BuildGameVersion is not None:
		buildGameVersion = str(mod.BuildGameVersion)  # type: typing.Union[str, localization.LocalizedString]
	else:
		buildGameVersion = AboutModDialogUnknown.GetLocalizationString()  # type: typing.Union[str, localization.LocalizedString]

	dialogArguments = {
		"title": AboutModDialogTitle.GetCallableLocalizationString(mod.Name),
		"text": AboutModDialogText.GetCallableLocalizationString(mod.Name, mod.Author, str(mod.Version), buildDate, buildGameVersion),
		"text_ok": AboutModDialogOkButton.GetCallableLocalizationString(),
	}

	# noinspection PyUnusedLocal
	def DialogCallback (dialogReference: ui_dialog.UiDialogOkCancel) -> None:
		try:
			if returnCallback is not None:
				returnCallback()
		except Exception:
			Debug.Log("Failed to run the callback for the about mod dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__)

	Dialogs.ShowOkDialog(callback = DialogCallback, queue = False, **dialogArguments)
コード例 #9
0
def ShowUpdatesList(
        updatedMods: typing.List[DistributionShared.UpdateInformation]
) -> None:
    dialogArguments = {
        "title": UpdatesListTitle.GetCallableLocalizationString(),
        "text": UpdatesListText.GetCallableLocalizationString()
    }

    options = {}  # type: typing.Dict[int, str]

    dialogRows = list()  # type: typing.List

    for updatedModIndex in range(len(updatedMods)):  # type: int
        updatedMod = updatedMods[
            updatedModIndex]  # type: DistributionShared.UpdateInformation

        optionID = 5000 + updatedModIndex  # type: int

        dialogRowArguments = {
            "option_id":
            optionID,
            "name":
            UpdatesListRowText.GetLocalizationString(updatedMod.ModName,
                                                     updatedMod.ModAuthor),
            "icon":
            resources.ResourceKeyWrapper(UIResources.PickerDownloadIconKey)
        }

        if not updatedMod.IsPreview:
            descriptionTypeText = UpdatesListRowDescriptionReleaseType.GetLocalizationString(
            )  # type: localization.LocalizedString
        else:
            descriptionTypeText = UpdatesListRowDescriptionPreviewType.GetLocalizationString(
            )  # type: localization.LocalizedString

        dialogRowArguments[
            "row_description"] = UpdatesListRowDescription.GetLocalizationString(
                descriptionTypeText, updatedMod.CurrentVersion,
                updatedMod.NewVersion, updatedMod.DownloadURL)
        dialogRows.append(
            ui_dialog_picker.ObjectPickerRow(**dialogRowArguments))

        options[optionID] = updatedMod.DownloadURL

    def OpenBrowserDialogCallback() -> None:
        ShowUpdatesList(updatedMods)

    def DialogCallback(
            dialogReference: ui_dialog_picker.UiObjectPicker) -> None:
        if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL:
            return

        resultRows = dialogReference.picked_results  # type: typing.Tuple[int]

        if len(resultRows) == 0:
            return

        selectedModURL = options.get(
            resultRows[0])  # type: typing.Optional[str]

        if selectedModURL is None:
            return

        Generic.ShowOpenBrowserDialog(selectedModURL,
                                      returnCallback=OpenBrowserDialogCallback)

    Dialogs.ShowObjectPickerDialog(callback=DialogCallback,
                                   pickerRows=dialogRows,
                                   **dialogArguments)
コード例 #10
0
def ShowResetDialog(mod: Mods.Mod) -> None:
    everythingResponseID = 20000  # type: int
    everythingResponse = ui_dialog.UiDialogResponse(
        sort_order=-2,
        dialog_response_id=everythingResponseID,
        text=DialogEverythingButton.GetCallableLocalizationString(
        ))  # type: ui_dialog.UiDialogResponse

    settingsResponseID = 20001  # type: int
    settingsResponse = ui_dialog.UiDialogResponse(
        sort_order=-1,
        dialog_response_id=settingsResponseID,
        text=DialogSettingsButton.GetCallableLocalizationString(
        ))  # type: ui_dialog.UiDialogResponse

    dialogArguments = {
        "title": DialogTitle.GetCallableLocalizationString(mod.Name),
        "text": DialogText.GetCallableLocalizationString(),
        "text_ok": DialogCancelButton.GetCallableLocalizationString(),
        "ui_responses": [everythingResponse, settingsResponse]
    }

    def ConfirmDialogEverythingCallback(
            dialogReference: ui_dialog.UiDialogOkCancel) -> None:
        try:
            if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
                ResetEverything(mod)
                return
        except Exception:
            Debug.Log(
                "Failed to run the confirm dialog everything callback for the reset dialog.",
                This.Mod.Namespace,
                Debug.LogLevels.Exception,
                group=This.Mod.Namespace,
                owner=__name__)

    def ConfirmDialogSettingsCallback(
            dialogReference: ui_dialog.UiDialogOkCancel) -> None:
        try:
            if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
                ResetSettings(mod)
                return
        except Exception:
            Debug.Log(
                "Failed to run the confirm dialog settings callback for the reset dialog.",
                This.Mod.Namespace,
                Debug.LogLevels.Exception,
                group=This.Mod.Namespace,
                owner=__name__)

    def DialogCallback(dialogReference: ui_dialog.UiDialogOkCancel) -> None:
        try:
            if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
                return

            confirmDialogCallback = None  # type: typing.Optional[typing.Callable]
            confirmDialogText = None  # type: typing.Optional[typing.Callable]

            if dialogReference.response == everythingResponseID:
                confirmDialogCallback = ConfirmDialogEverythingCallback
                confirmDialogText = ConfirmDialogEverythingText.GetCallableLocalizationString(
                )
            elif dialogReference.response == settingsResponseID:
                confirmDialogCallback = ConfirmDialogSettingsCallback
                confirmDialogText = ConfirmDialogSettingsText.GetCallableLocalizationString(
                )

            confirmDialogArguments = {
                "title":
                ConfirmDialogTitle.GetCallableLocalizationString(mod.Name),
                "text":
                confirmDialogText,
                "text_ok":
                ConfirmDialogYesButton.GetCallableLocalizationString(),
                "text_cancel":
                ConfirmDialogNoButton.GetCallableLocalizationString()
            }  # type: typing.Dict[str, ...]

            Dialogs.ShowOkCancelDialog(callback=confirmDialogCallback,
                                       queue=False,
                                       **confirmDialogArguments)
        except Exception:
            Debug.Log("Failed to run the callback for the reset dialog.",
                      This.Mod.Namespace,
                      Debug.LogLevels.Exception,
                      group=This.Mod.Namespace,
                      owner=__name__)

    Dialogs.ShowOkDialog(callback=DialogCallback,
                         queue=False,
                         **dialogArguments)
コード例 #11
0
ファイル: Reporting.py プロジェクト: NeonOcean/S4.Main
def _ShowPrepareReportLocationDialog(_connection: int = None) -> None:
    try:
        reportFileName = "NeonOcean Sims 4 Bug Report.zip"  # type: str

        dialogResponses = list(
        )  # type: typing.List[ui_dialog.UiDialogResponse]

        gameUserDataDirectoryPath = Paths.UserDataPath  # type: str
        gameUserDataReportFilePath = os.path.join(gameUserDataDirectoryPath,
                                                  reportFileName)  # type: str
        gameUserDataReportResponseID = 1  # type: int

        if os.path.exists(gameUserDataDirectoryPath):
            gameUserDataResponseArguments = {
                "dialog_response_id":
                gameUserDataReportResponseID,
                "sort_order":
                -2,
                "text":
                PrepareReportLocationDialogGameUserDataButton.
                GetCallableLocalizationString()
            }

            dialogResponses.append(
                ui_dialog.UiDialogResponse(**gameUserDataResponseArguments))
        else:
            raise Exception("The game's user data path does not exist.")

        desktopDirectoryPath = os.path.expanduser("~/Desktop")  # type: str
        desktopReportFilePath = os.path.join(desktopDirectoryPath,
                                             reportFileName)  # type: str
        desktopReportResponseID = 2  # type: int

        if os.path.exists(desktopDirectoryPath):
            desktopResponseArguments = {
                "dialog_response_id":
                desktopReportResponseID,
                "sort_order":
                -2,
                "text":
                PrepareReportLocationDialogDesktopButton.
                GetCallableLocalizationString()
            }

            dialogResponses.append(
                ui_dialog.UiDialogResponse(**desktopResponseArguments))

        dialogArguments = {
            "title":
            PrepareReportLocationDialogTitle.GetCallableLocalizationString(),
            "text":
            PrepareReportLocationDialogText.GetCallableLocalizationString(),
            "text_ok":
            PrepareReportLocationDialogCancelButton.
            GetCallableLocalizationString(),
            "ui_responses":
            dialogResponses
        }

        def dialogCallback(closedDialog: ui_dialog.UiDialog) -> None:
            try:
                if closedDialog.response == gameUserDataReportResponseID:
                    Reporting.PrepareReportFiles(gameUserDataReportFilePath)
                    _ShowReportCreatedDialog()
                elif closedDialog.response == desktopReportResponseID:
                    Reporting.PrepareReportFiles(desktopReportFilePath)
                    _ShowReportCreatedDialog()
            except:
                commands.CheatOutput(
                    _connection
                )("Failed to run the callback for the prepare report location dialog."
                  )

                Debug.Log(
                    "Failed to run the callback for the prepare report location dialog.",
                    This.Mod.Namespace,
                    Debug.LogLevels.Exception,
                    group=This.Mod.Namespace,
                    owner=__name__)

        Dialogs.ShowOkDialog(callback=dialogCallback,
                             queue=False,
                             **dialogArguments)
    except:
        commands.CheatOutput(_connection)(
            "Failed to show the prepare report location dialog.")
        Debug.Log("Failed to show the prepare report location dialog.",
                  This.Mod.Namespace,
                  Debug.LogLevels.Exception,
                  group=This.Mod.Namespace,
                  owner=__name__)
コード例 #12
0
ファイル: SelectSave.py プロジェクト: NeonOcean/S4.Main
def ShowSelectSaveDialog () -> None:
	gameSaveSlotID = str(services.get_persistence_service().get_save_slot_proto_buff().slot_id)  # type: str
	gameSaveGUID = str(services.get_persistence_service().get_save_slot_proto_guid())  # type: str

	dialogArguments = {
		"owner": services.get_active_sim().sim_info,
		"title": SelectSaveDialogTitle,
		"text": SelectSaveDialogText.GetCallableLocalizationString(*(gameSaveSlotID, gameSaveGUID))
	}

	dialogRows = list()

	options = { }  # type: typing.Dict[int, str]

	loadedSaveDirectoryPath = Save.GetLoadedDirectoryPath()  # type: typing.Optional[str]
	loadedSaveDirectoryPathObject = pathlib.Path(Save.GetLoadedDirectoryPath()) if loadedSaveDirectoryPath is not None else None  # type: typing.Optional[pathlib.Path]

	for saveDirectoryName in os.listdir(Paths.SavesPath):  # type: str
		saveDirectoryPath = os.path.join(Paths.SavesPath, saveDirectoryName)  # type: str

		if os.path.isdir(saveDirectoryPath):
			saveDirectoryPathObject = pathlib.Path(saveDirectoryPath)  # type: pathlib.Path

			currentOptionID = 50000 + len(options)
			options[currentOptionID] = saveDirectoryPath

			saveDirectoryMetaData = Save.GetSaveMetaData(saveDirectoryPath)  # type: typing.Optional[Save.ModSaveMetaData]

			rowDescriptionTokens = (SelectSaveDialogDescriptionMatchUnknown.GetLocalizationString(),)

			if saveDirectoryMetaData is not None:
				saveDirectoryMatchType = saveDirectoryMetaData.MatchesGameSave()  # type: Save.ModSaveMatchTypes

				if saveDirectoryMatchType in Save.ModSaveMatchTypes.Match:
					rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMatches.GetLocalizationString(),)
				elif saveDirectoryMatchType in Save.ModSaveMatchTypes.MismatchedGUID:
					rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMismatchGUID.GetLocalizationString(),)
				elif saveDirectoryMatchType in Save.ModSaveMatchTypes.MismatchedGameTick:
					rowDescriptionTokens = (SelectSaveDialogDescriptionMatchMismatchGameTick.GetLocalizationString(),)

			if loadedSaveDirectoryPathObject is not None:
				if loadedSaveDirectoryPathObject == saveDirectoryPathObject:
					rowDescription = SelectSaveDialogDescriptionCurrentlyLoaded.GetLocalizationString(*rowDescriptionTokens)
				else:
					rowDescription = SelectSaveDialogDescriptionNormal.GetLocalizationString(*rowDescriptionTokens)
			else:
				rowDescription = SelectSaveDialogDescriptionNormal.GetLocalizationString(*rowDescriptionTokens)

			if saveDirectoryMetaData is None:
				rowNameTokens = (saveDirectoryName,)
			else:
				rowNameTokens = (saveDirectoryName + " (" + saveDirectoryMetaData.Name + ")",)

			dialogRows.append(ui_dialog_picker.ObjectPickerRow(
				option_id = currentOptionID,
				name = Language.CreateLocalizationString(*rowNameTokens),
				row_description = rowDescription))

	def DialogCallback (dialogReference: ui_dialog_picker.UiObjectPicker) -> None:
		try:
			if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_CANCEL:
				return

			resultRows = dialogReference.picked_results  # type: typing.Tuple[int]

			if len(resultRows) == 0:
				return

			selectedSaveDirectory = options.get(resultRows[0])  # type: typing.Optional[str]

			if selectedSaveDirectory is None:
				return

			Save.Load(services.get_persistence_service().get_save_slot_proto_buff().slot_id, selectedSaveDirectory, changingSave = True)
		except Exception as e:
			Debug.Log("Failed to run the callback for the select save dialog.", This.Mod.Namespace, Debug.LogLevels.Exception, group = This.Mod.Namespace, owner = __name__, exception = e)

	Dialogs.ShowObjectPickerDialog(DialogCallback, dialogRows, **dialogArguments)
コード例 #13
0
ファイル: Debug.py プロジェクト: NeonOcean/S4.Cycle
def _ShowSetPregnancyProgressDialog(
        targetSimHandler: argument_helpers.RequiredTargetParam,
        _connection=None) -> None:
    try:
        if game_services.service_manager is None:
            return

        targetSimInfo = targetSimHandler.get_target(
            services.sim_info_manager())

        if not isinstance(targetSimInfo, sim_info.SimInfo):
            raise ValueError(
                "Failed to get the target sim, %s is not a valid sim id." %
                targetSimHandler.target_id)

        targetSimSystem = Reproduction.GetSimSystem(
            targetSimInfo
        )  # type: typing.Optional[ReproductionShared.ReproductiveSystem]

        if targetSimSystem is None:
            return

        targetSimPregnancyTracker = targetSimSystem.GetTracker(
            FemalesShared.PregnancyTrackerIdentifier
        )  # type: typing.Optional[PregnancyTracker.PregnancyTracker]

        currentProgress = round(
            targetSimPregnancyTracker.GetPregnancyProgress(), 3)  # type: float

        def dialogCallback(
                dialogReference: ui_dialog_generic.UiDialogTextInputOkCancel):
            if dialogReference.response == ui_dialog.ButtonType.DIALOG_RESPONSE_OK:
                nextProgressString = dialogReference.text_input_responses[
                    "Input"]  # type: str

                try:
                    nextProgress = float(nextProgressString)  # type: float
                except:
                    return

                if currentProgress != nextProgress:
                    targetSimPregnancyTracker.SetPregnancyProgress(
                        nextProgress)

        textInputKey = "Input"  # type: str

        textInputLockedArguments = {
            "sort_order": 0,
        }

        textInput = ui_text_input.UiTextInput.TunableFactory(
            locked_args=textInputLockedArguments
        ).default  # type: ui_text_input.UiTextInput
        textInputInitialValue = Language.MakeLocalizationStringCallable(
            Language.CreateLocalizationString(str(currentProgress)))

        textInput.initial_value = textInputInitialValue

        textInputs = collections.make_immutable_slots_class([textInputKey])
        textInputs = textInputs({textInputKey: textInput})

        dialogArguments = {
            "title":
            SetPregnancyProgressDialogTitle.GetCallableLocalizationString(),
            "text":
            SetPregnancyProgressDialogText.GetCallableLocalizationString(),
            "text_ok":
            SetPregnancyProgressDialogOkButton.GetCallableLocalizationString(),
            "text_cancel":
            SetPregnancyProgressDialogCancelButton.
            GetCallableLocalizationString(),
            "text_inputs":
            textInputs
        }

        Dialogs.ShowOkCancelInputDialog(callback=dialogCallback,
                                        queue=False,
                                        **dialogArguments)
    except Exception as e:
        Debug.Log(
            "Failed to show the set pregnancy progress dialog for a sim.",
            This.Mod.Namespace,
            Debug.LogLevels.Exception,
            group=This.Mod.Namespace,
            owner=__name__,
            exception=e)
        raise e
コード例 #14
0
    def _ShowEditPairDialog(self,
                            editingPronounSet: dict,
                            editingPairIdentifier: str,
                            editingPairCurrentValue: str,
                            setting: UISettingsShared.SettingWrapper,
                            currentValue: typing.Any,
                            showDialogArguments: typing.Dict[str, typing.Any],
                            returnCallback: typing.Callable[[], None] = None,
                            *args,
                            **kwargs) -> None:
        def editPairDialogCallback(
            shownEditPairDialog: ui_dialog_generic.UiDialogTextInputOkCancel
        ) -> None:
            try:
                if shownEditPairDialog.accepted:
                    editingPairNextValue = shownEditPairDialog.text_input_responses.get(
                        textInputKey, editingPairCurrentValue)  # type: str
                    editingPairNextValue = editingPairNextValue.lower()
                    editingPronounSet[
                        editingPairIdentifier] = editingPairNextValue

                    # noinspection PyUnusedLocal
                    def askToApplyAndFixCallback(appliedFix: bool) -> None:
                        self._ShowDialogInternal(
                            setting,
                            currentValue,
                            showDialogArguments=showDialogArguments,
                            returnCallback=returnCallback,
                            *args,
                            **kwargs)

                    currentLanguageHandler = LanguageHandlers.GetCurrentLanguageHandler(
                    )  # type: LanguageHandlers.LanguageHandlerBase
                    currentLanguageHandler.AskToApplyAndFixCustomPronounSetPair(
                        editingPronounSet, editingPairIdentifier,
                        editingPairNextValue, askToApplyAndFixCallback)
                else:
                    self._ShowDialogInternal(
                        setting,
                        currentValue,
                        showDialogArguments=showDialogArguments,
                        returnCallback=returnCallback,
                        *args,
                        **kwargs)
            except:
                Debug.Log("Failed to run an edit pair dialog callback.",
                          This.Mod.Namespace,
                          Debug.LogLevels.Exception,
                          group=This.Mod.Namespace,
                          owner=__name__)

        editingPairParts = editingPairIdentifier.split(
            "|")  # type: typing.List[str]

        if len(editingPairParts) != 2:
            femaleLanguage = maleLanguage = ""  # type: str
        else:
            femaleLanguage = editingPairParts[0].capitalize()  # type: str
            maleLanguage = editingPairParts[1].capitalize()  # type: str

        textInputKey = "Input"  # type: str

        textInputLockedArguments = {
            "sort_order": 0,
        }

        textInput = ui_text_input.UiTextInput.TunableFactory(
            locked_args=textInputLockedArguments
        ).default  # type: ui_text_input.UiTextInput
        textInputInitialValue = Language.MakeLocalizationStringCallable(
            Language.CreateLocalizationString(
                editingPairCurrentValue.capitalize()))

        textInput.initial_value = textInputInitialValue

        textInputs = collections.make_immutable_slots_class([textInputKey])
        textInputs = textInputs({textInputKey: textInput})

        dialogArguments = {
            "title":
            Language.MakeLocalizationStringCallable(
                self._GetEditPairDialogTitle()),
            "text":
            Language.MakeLocalizationStringCallable(
                self._GetEditPairDialogText(femaleLanguage, maleLanguage)),
            "text_ok":
            Language.MakeLocalizationStringCallable(
                self._GetEditPairDialogOkButton()),
            "text_cancel":
            Language.MakeLocalizationStringCallable(
                self._GetEditPairDialogCancelButton()),
            "text_inputs":
            textInputs
        }

        UIDialogs.ShowOkCancelInputDialog(callback=editPairDialogCallback,
                                          queue=False,
                                          **dialogArguments)
コード例 #15
0
    def _ShowEditTitleDialog(self,
                             editingPronounSetContainer: dict,
                             setting: UISettingsShared.SettingWrapper,
                             currentValue: typing.Any,
                             showDialogArguments: typing.Dict[str, typing.Any],
                             returnCallback: typing.Callable[[], None] = None,
                             *args,
                             **kwargs) -> None:
        def editPairDialogCallback(
            shownEditPairDialog: ui_dialog_generic.UiDialogTextInputOkCancel
        ) -> None:
            if shownEditPairDialog.accepted:
                editingSetNextTitle = shownEditPairDialog.text_input_responses.get(
                    textInputKey, editingSetCurrentTitle)  # type: str
                editingPronounSetContainer["Title"] = editingSetNextTitle

            self._ShowDialogInternal(setting,
                                     currentValue,
                                     showDialogArguments=showDialogArguments,
                                     returnCallback=returnCallback,
                                     *args,
                                     **kwargs)

        editingSetCurrentTitle = editingPronounSetContainer.get(
            "Title", "New Pronoun Set")  # type: str

        textInputKey = "Input"  # type: str

        textInputLockedArguments = {
            "sort_order": 0,
        }

        textInput = ui_text_input.UiTextInput.TunableFactory(
            locked_args=textInputLockedArguments
        ).default  # type: ui_text_input.UiTextInput
        textInputInitialValue = Language.MakeLocalizationStringCallable(
            Language.CreateLocalizationString(editingSetCurrentTitle))

        textInput.initial_value = textInputInitialValue

        textInputs = collections.make_immutable_slots_class([textInputKey])
        textInputs = textInputs({textInputKey: textInput})

        dialogArguments = {
            "title":
            Language.MakeLocalizationStringCallable(
                self._GetEditTitleDialogTitle()),
            "text":
            Language.MakeLocalizationStringCallable(
                self._GetEditTitleDialogText()),
            "text_ok":
            Language.MakeLocalizationStringCallable(
                self._GetEditTitleDialogOkButton()),
            "text_cancel":
            Language.MakeLocalizationStringCallable(
                self._GetEditTitleDialogCancelButton()),
            "text_inputs":
            textInputs
        }

        UIDialogs.ShowOkCancelInputDialog(callback=editPairDialogCallback,
                                          queue=False,
                                          **dialogArguments)