Ejemplo n.º 1
0
def ShowStatusNotification (targetSimInfo: sim_info.SimInfo) -> None:  # TODO create quick glance notification, only show the times?
	if not isinstance(targetSimInfo, sim_info.SimInfo):
		raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

	targetDotInformation = Dot.GetDotInformation(targetSimInfo)  # type: typing.Optional[Dot.DotInformation]

	if targetDotInformation is None:
		Debug.Log("Attempted to show a dot app status notification on a sim missing a dot information object.\nSim ID: %s" % targetSimInfo.id, This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__)
		return

	if not targetDotInformation.Enabled:
		Debug.Log("Attempted to show a dot app status notification on a sim its not enabled for.\nSim ID: %s" % targetSimInfo.id, This.Mod.Namespace, Debug.LogLevels.Warning, group = This.Mod.Namespace, owner = __name__)
		return

	dotCycle = targetDotInformation.GetCurrentCycle()  # type: typing.Optional[Dot.DotCycle]

	if dotCycle is None:
		ShowErrorNotification(targetSimInfo)
		return

	text = Language.MakeLocalizationStringCallable(_BuildStatusText(targetSimInfo, dotCycle))

	notificationArguments = {
		"owner": targetSimInfo,
		"title": StatusNotificationTitle.GetCallableLocalizationString(),
		"text": text,
		"icon": lambda *args, **kwargs: shared_messages.IconInfoData(icon_resource = resources.ResourceKeyWrapper(CycleUIResources.DotAppIconKey)),
		"secondary_icon": lambda *args, **kwargs: shared_messages.IconInfoData(obj_instance = targetSimInfo),
	}

	Notifications.ShowNotification(queue = False, **notificationArguments)
Ejemplo n.º 2
0
def ShowFertilityNotificationsEnabledNotification (targetSimInfo: sim_info.SimInfo) -> None:
	if not isinstance(targetSimInfo, sim_info.SimInfo):
		raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

	notificationArguments = {
		"owner": targetSimInfo,
		"title": FertilityNotificationsEnabledNotificationTitle.GetCallableLocalizationString(),
		"text": FertilityNotificationsEnabledNotificationText.GetCallableLocalizationString(),
		"icon": lambda *args, **kwargs: shared_messages.IconInfoData(icon_resource = resources.ResourceKeyWrapper(CycleUIResources.DotAppIconKey)),
		"secondary_icon": lambda *args, **kwargs: shared_messages.IconInfoData(obj_instance = targetSimInfo),
	}

	Notifications.ShowNotification(queue = False, **notificationArguments)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def _GetNewSetRowIcon(self) -> typing.Any:
     return resources.ResourceKeyWrapper(ReferUIResources.PickerPlusIconKey)
Ejemplo n.º 5
0
    def _CreateRows(self,
                    listPath: str,
                    showDialogArguments: typing.Dict[str, typing.Any],
                    returnCallback: typing.Callable[[], None] = None,
                    *args,
                    **kwargs) -> typing.List[DialogRow]:

        dialogRows = list()  # type: typing.List[DialogRow]

        if self.ShowResetAllButton and not self.ListPathSeparator in listPath:
            resetAllButtonCallback = self._CreateResetAllButtonCallback(
                listPath,
                showDialogArguments,
                returnCallback=returnCallback,
                *args,
                **kwargs)  # type: typing.Callable

            dialogRows.append(
                DialogRow(40000,
                          callback=resetAllButtonCallback,
                          text=self._GetResetAllButtonText(),
                          description=self._GetResetAllButtonDescriptionText(),
                          icon=resources.ResourceKeyWrapper(
                              self._GetResetAllButtonIconKey())))

        currentOptionID = 50000  # type: int
        currentReturnCallback = self._CreateReturnCallback(
            listPath, showDialogArguments,
            returnCallback)  # type: typing.Callable[[], None]

        visibleListPaths = self._GetVisibleListPaths(
            listPath)  # type: typing.List[str]

        for visibleListPath in visibleListPaths:  # type: str

            def CreateVisibleListPathCallback(
                targetListPath: str
            ) -> typing.Callable[[ui_dialog.UiDialog], None]:

                # noinspection PyUnusedLocal
                def VisibleListPathCallback(
                        dialog: ui_dialog.UiDialog) -> None:
                    self.ShowDialog(targetListPath,
                                    returnCallback=currentReturnCallback,
                                    **showDialogArguments)

                return VisibleListPathCallback

            dialogRows.append(
                DialogRow(
                    currentOptionID,
                    callback=CreateVisibleListPathCallback(visibleListPath),
                    text=self._GetRowListPathText(visibleListPath),
                    description=self._GetRowListPathDescriptionText(
                        visibleListPath),
                    icon=resources.ResourceKeyWrapper(
                        self._GetRowListPathIconKey(visibleListPath))))

            currentOptionID += 1

        visibleSettings = self._GetVisibleSettings(
            listPath)  # type: typing.List[UISettingsShared.SettingWrapper]

        for visibleSetting in visibleSettings:  # type: UISettingsShared.SettingWrapper

            def CreateVisibleSettingCallback(
                targetSetting: UISettingsShared.SettingWrapper
            ) -> typing.Callable[[ui_dialog.UiDialog], None]:

                # noinspection PyUnusedLocal
                def VisibleSettingCallback(dialog: ui_dialog.UiDialog) -> None:
                    targetSetting.ShowDialog(
                        returnCallback=currentReturnCallback)

                return VisibleSettingCallback

            dialogRows.append(
                DialogRow(
                    currentOptionID,
                    callback=CreateVisibleSettingCallback(visibleSetting),
                    text=self._GetRowSettingText(visibleSetting),
                    description=self._GetRowSettingDescriptionText(
                        visibleSetting),
                    icon=resources.ResourceKeyWrapper(
                        self._GetRowSettingIconKey(visibleSetting))))

            currentOptionID += 1

        return dialogRows
Ejemplo n.º 6
0
 def _GetCustomSetRowIcon(self) -> localization.LocalizedString:
     return resources.ResourceKeyWrapper(
         ReferUIResources.PickerPencilIconKey)
Ejemplo n.º 7
0
 def _GetEditablePairRowIcon(self) -> localization.LocalizedString:
     return resources.ResourceKeyWrapper(ReferUIResources.PickerTextIconKey)
Ejemplo n.º 8
0
 def _GetDeleteSetRowIcon(self) -> localization.LocalizedString:
     return resources.ResourceKeyWrapper(
         ReferUIResources.PickerTrashCanIconKey)
Ejemplo n.º 9
0
    def _CreateRows(self,
                    setting: UISettingsShared.SettingStandardWrapper,
                    currentValue: typing.Any,
                    showDialogArguments: typing.Dict[str, typing.Any],
                    returnCallback: typing.Callable[[], None] = None,
                    *args,
                    **kwargs) -> typing.List[UISettings.DialogRow]:

        rows = super()._CreateRows(
            setting,
            currentValue,
            showDialogArguments,
            returnCallback=returnCallback,
            *args,
            **kwargs)  # type: typing.List[UISettings.DialogRow]

        defaultValue = self.DefaultSetting.Get()  # type: bool

        allMods = Mods.GetAllMods()  # type: typing.List[Mods.Mod]
        for modIndex in range(len(allMods)):  # type: int
            if allMods[modIndex].Distribution.UpdatesController is None:
                continue

            if allMods[modIndex].Distribution.UpdatesFileURL is None:
                continue

            if allMods[modIndex].Distribution.DownloadURL is None:
                continue

            modEnabled = defaultValue  # type: bool

            if allMods[modIndex].Namespace in currentValue:
                modEnabled = currentValue[allMods[modIndex].Namespace]

            def CreateModButtonCallback(mod: Mods.Mod,
                                        lastValue: bool) -> typing.Callable:

                # noinspection PyUnusedLocal
                def ModButtonCallback(dialog: ui_dialog.UiDialog) -> None:
                    if lastValue:
                        currentValue[mod.Namespace] = False
                        self._ShowDialogInternal(setting,
                                                 currentValue,
                                                 showDialogArguments,
                                                 returnCallback=returnCallback)
                    else:
                        currentValue[mod.Namespace] = True
                        self._ShowDialogInternal(setting,
                                                 currentValue,
                                                 showDialogArguments,
                                                 returnCallback=returnCallback)

                return ModButtonCallback

            rowArguments = {
                "optionID": (50000 + modIndex + -1),
                "callback":
                CreateModButtonCallback(allMods[modIndex], modEnabled),
                "text":
                self._GetKeyText(setting, allMods[modIndex], modEnabled),
                "description":
                self._GetValueText(setting, allMods[modIndex], modEnabled),
                "icon":
                resources.ResourceKeyWrapper(self._GetEnabledButtonIconKey())
                if modEnabled else resources.ResourceKeyWrapper(
                    self._GetDisabledButtonIconKey())
            }

            rows.append(UISettings.DialogRow(**rowArguments))

        return rows
Ejemplo n.º 10
0
 def _GetNotSelectedRowIcon(self) -> typing.Any:
     return resources.ResourceKeyWrapper(
         ReferUIResources.PickerBlankIconKey)