diff --git a/PortMaster/pylibs/locales/de_DE.json b/PortMaster/pylibs/locales/de_DE.json index d2f0a557..2c7ce4e3 100644 --- a/PortMaster/pylibs/locales/de_DE.json +++ b/PortMaster/pylibs/locales/de_DE.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "Der Theme-Editor wurde beendet. Siehe theme_server.txt im PortMaster-Ordner.", "{theme_name} (Selected)": "{theme_name} (Ausgewählt)", "Download": "Herunterladen", + "Theme {theme_name} is not downloaded, would you like to download it?": "Das Theme {theme_name} ist nicht heruntergeladen. Möchten Sie es herunterladen?", "{item_name} (Selected)": "{item_name} (Ausgewählt)", "Please wait.": "Bitte warten.", "Up to date already": "Neuste Version bereits installiert", diff --git a/PortMaster/pylibs/locales/es_ES.json b/PortMaster/pylibs/locales/es_ES.json index e43d2480..410784aa 100644 --- a/PortMaster/pylibs/locales/es_ES.json +++ b/PortMaster/pylibs/locales/es_ES.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "El editor de temas se ha detenido. Consulta theme_server.txt en la carpeta de PortMaster.", "{theme_name} (Selected)": "{theme_name} (seleccionado)", "Download": "Descargar", + "Theme {theme_name} is not downloaded, would you like to download it?": "El tema {theme_name} no está descargado, ¿quieres descargarlo?", "{item_name} (Selected)": "{item_name} (seleccionado)", "Please wait.": "Espera, por favor.", "Up to date already": "Ya está actualizado", diff --git a/PortMaster/pylibs/locales/fr_FR.json b/PortMaster/pylibs/locales/fr_FR.json index f4c9252f..3b1eadab 100644 --- a/PortMaster/pylibs/locales/fr_FR.json +++ b/PortMaster/pylibs/locales/fr_FR.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "L'éditeur de thèmes s'est arrêté. Voir theme_server.txt dans le dossier de PortMaster.", "{theme_name} (Selected)": "{theme_name} (Sélectionné)", "Download": "Télécharger", + "Theme {theme_name} is not downloaded, would you like to download it?": "Le thème {theme_name} n'est pas téléchargé, voulez-vous le télécharger ?", "{item_name} (Selected)": "{item_name} (Sélectionné)", "Please wait.": "Veuillez patienter.", "Up to date already": "Déjà à jour", diff --git a/PortMaster/pylibs/locales/it_IT.json b/PortMaster/pylibs/locales/it_IT.json index 4ae4100e..35119ba4 100644 --- a/PortMaster/pylibs/locales/it_IT.json +++ b/PortMaster/pylibs/locales/it_IT.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "L'editor dei temi si è fermato. Vedi theme_server.txt nella cartella di PortMaster.", "{theme_name} (Selected)": "{theme_name} (Attuale)", "Download": "Download", + "Theme {theme_name} is not downloaded, would you like to download it?": "Il tema {theme_name} non è scaricato, vuoi scaricarlo?", "{item_name} (Selected)": "{item_name} (Attuale)", "Please wait.": "Attendi.", "Up to date already": "Già aggiornata", diff --git a/PortMaster/pylibs/locales/ja_JP.json b/PortMaster/pylibs/locales/ja_JP.json index e00fef6f..be69e202 100644 --- a/PortMaster/pylibs/locales/ja_JP.json +++ b/PortMaster/pylibs/locales/ja_JP.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "テーマエディターが停止しました。PortMaster フォルダーの theme_server.txt を確認してください。", "{theme_name} (Selected)": "{theme_name} (選択済み)", "Download": "ダウンロード", + "Theme {theme_name} is not downloaded, would you like to download it?": "テーマ {theme_name} はダウンロードされていません。ダウンロードしますか?", "{item_name} (Selected)": "{item_name} (選択済み)", "Please wait.": "お待ちください。", "Up to date already": "既に最新の状態です", diff --git a/PortMaster/pylibs/locales/ko_KR.json b/PortMaster/pylibs/locales/ko_KR.json index 9cfc12db..813be089 100644 --- a/PortMaster/pylibs/locales/ko_KR.json +++ b/PortMaster/pylibs/locales/ko_KR.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "테마 편집기가 중지되었습니다. PortMaster 폴더의 theme_server.txt를 확인하세요.", "{theme_name} (Selected)": "{theme_name} (선택됨)", "Download": "다운로드", + "Theme {theme_name} is not downloaded, would you like to download it?": "{theme_name} 테마가 다운로드되지 않았습니다. 다운로드하시겠습니까?", "{item_name} (Selected)": "{item_name} (선택됨)", "Please wait.": "잠시 기다려 주세요.", "Up to date already": "이미 최신 상태입니다.", diff --git a/PortMaster/pylibs/locales/nl_NL.json b/PortMaster/pylibs/locales/nl_NL.json index e0696366..e0e5d569 100644 --- a/PortMaster/pylibs/locales/nl_NL.json +++ b/PortMaster/pylibs/locales/nl_NL.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "De thema-editor is gestopt. Zie theme_server.txt in de PortMaster-map.", "{theme_name} (Selected)": "{theme_name} (Geselecteerd)", "Download": "Download", + "Theme {theme_name} is not downloaded, would you like to download it?": "Thema {theme_name} is niet gedownload, wilt u het downloaden?", "{item_name} (Selected)": "{item_name} (Geselecteerd)", "Please wait.": "Even geduld.", "Up to date already": "Al bijgewerkt", diff --git a/PortMaster/pylibs/locales/pl_PL.json b/PortMaster/pylibs/locales/pl_PL.json index 490d1275..eb503b4a 100644 --- a/PortMaster/pylibs/locales/pl_PL.json +++ b/PortMaster/pylibs/locales/pl_PL.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "Edytor motywów się zatrzymał. Zobacz theme_server.txt w folderze PortMastera.", "{theme_name} (Selected)": "{theme_name} (Wybrany)", "Download": "Pobierz", + "Theme {theme_name} is not downloaded, would you like to download it?": "Motyw {theme_name} nie jest pobrany, czy chcesz go pobrać?", "{item_name} (Selected)": "{item_name} (Wybrany)", "Please wait.": "Proszę czekać.", "Up to date already": "Już aktualne", diff --git a/PortMaster/pylibs/locales/pt_BR.json b/PortMaster/pylibs/locales/pt_BR.json index ceb90901..a9b8a4be 100644 --- a/PortMaster/pylibs/locales/pt_BR.json +++ b/PortMaster/pylibs/locales/pt_BR.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "O editor de temas parou. Veja theme_server.txt na pasta do PortMaster.", "{theme_name} (Selected)": "{theme_name} (Selecionado)", "Download": "Baixar", + "Theme {theme_name} is not downloaded, would you like to download it?": "O tema {theme_name} não foi baixado, deseja baixá-lo?", "{item_name} (Selected)": "{item_name} (Selecionado)", "Please wait.": "Aguarde.", "Up to date already": "Já está atualizado", diff --git a/PortMaster/pylibs/locales/ro_RO.json b/PortMaster/pylibs/locales/ro_RO.json index f6c31463..367b4f63 100644 --- a/PortMaster/pylibs/locales/ro_RO.json +++ b/PortMaster/pylibs/locales/ro_RO.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "Editorul de teme s-a oprit. Vezi theme_server.txt în folderul PortMaster.", "{theme_name} (Selected)": "{theme_name} (Selectat)", "Download": "Descarcă", + "Theme {theme_name} is not downloaded, would you like to download it?": "Tema {theme_name} nu este descărcată, vrei să o descarci?", "{item_name} (Selected)": "{item_name} (Selectat)", "Please wait.": "Te rugăm să aștepți.", "Up to date already": "Deja la zi", diff --git a/PortMaster/pylibs/locales/ru_RU.json b/PortMaster/pylibs/locales/ru_RU.json index 1b9a8af4..e49d787a 100644 --- a/PortMaster/pylibs/locales/ru_RU.json +++ b/PortMaster/pylibs/locales/ru_RU.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "Редактор тем остановился. См. theme_server.txt в папке PortMaster.", "{theme_name} (Selected)": "{theme_name} (Выбрана)", "Download": "Скачать", + "Theme {theme_name} is not downloaded, would you like to download it?": "Тема {theme_name} не загружена. Загрузить её?", "{item_name} (Selected)": "{item_name} (Выбранная)", "Please wait.": "Пожалуйста, подождите.", "Up to date already": "Актуальная версия уже существует", diff --git a/PortMaster/pylibs/locales/strings.json b/PortMaster/pylibs/locales/strings.json index c07a93a9..9f42e84a 100644 --- a/PortMaster/pylibs/locales/strings.json +++ b/PortMaster/pylibs/locales/strings.json @@ -229,19 +229,19 @@ ], "Updating": [ "pylibs/harbourmaster/source/portmaster.py:42", - "pylibs/pugwash/theme.py:581" + "pylibs/pugwash/theme.py:588" ], "Fetching latest info": [ "pylibs/harbourmaster/source/portmaster.py:46", - "pylibs/pugwash/theme.py:591" + "pylibs/pugwash/theme.py:598" ], "Done.": [ "pylibs/harbourmaster/source/portmaster.py:165", - "pylibs/pugwash/theme.py:614" + "pylibs/pugwash/theme.py:621" ], "Fetching info": [ "pylibs/harbourmaster/source/portmaster.py:197", - "pylibs/pugwash/theme.py:620" + "pylibs/pugwash/theme.py:627" ], "Unable to find {port_name}.": [ "pylibs/harbourmaster/source/portmaster.py:418" @@ -433,7 +433,7 @@ "pylibs/pugwash/scenes/keyboard.py:41", "pylibs/pugwash/scenes/language.py:30", "pylibs/pugwash/scenes/themes.py:46", - "pylibs/pugwash/scenes/themes.py:127" + "pylibs/pugwash/scenes/themes.py:145" ], "Back": [ "pylibs/pugwash/scenes/featured.py:30", @@ -451,8 +451,8 @@ "pylibs/pugwash/scenes/runtimes.py:109", "pylibs/pugwash/scenes/runtimes.py:112", "pylibs/pugwash/scenes/themes.py:48", - "pylibs/pugwash/scenes/themes.py:126", - "pylibs/pugwash/scenes/themes.py:127" + "pylibs/pugwash/scenes/themes.py:144", + "pylibs/pugwash/scenes/themes.py:145" ], "No featured ports found, internet connection is required.": [ "pylibs/pugwash/scenes/featured.py:47" @@ -712,7 +712,7 @@ ], "Select Color Scheme": [ "pylibs/pugwash/scenes/options.py:43", - "pylibs/pugwash/scenes/themes.py:106" + "pylibs/pugwash/scenes/themes.py:124" ], "Select a color scheme for PortMaster.": [ "pylibs/pugwash/scenes/options.py:44" @@ -1057,14 +1057,17 @@ "Download": [ "pylibs/pugwash/scenes/themes.py:51" ], + "Theme {theme_name} is not downloaded, would you like to download it?": [ + "pylibs/pugwash/scenes/themes.py:82" + ], "{item_name} (Selected)": [ - "pylibs/pugwash/scenes/themes.py:120" + "pylibs/pugwash/scenes/themes.py:138" ], "Please wait.": [ "pylibs/pugwash/theme.py:358" ], "Up to date already": [ - "pylibs/pugwash/theme.py:588" + "pylibs/pugwash/theme.py:595" ], "You are switching from the {old_release_channel} to the {new_release_channel} version.\n\nDo you want to downgrade?": [ "pylibs/pugwash/update.py:79" diff --git a/PortMaster/pylibs/locales/sv_SE.json b/PortMaster/pylibs/locales/sv_SE.json index 0989db44..a13896ac 100644 --- a/PortMaster/pylibs/locales/sv_SE.json +++ b/PortMaster/pylibs/locales/sv_SE.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "Temaredigeraren stoppades. Se theme_server.txt i PortMaster-mappen.", "{theme_name} (Selected)": "{theme_name} (Vald)", "Download": "Hämta", + "Theme {theme_name} is not downloaded, would you like to download it?": "Temat {theme_name} är inte nedladdat, vill du ladda ner det?", "{item_name} (Selected)": "{item_name} (Vald)", "Please wait.": "Vänta.", "Up to date already": "Redan uppdaterad", diff --git a/PortMaster/pylibs/locales/uk_UA.json b/PortMaster/pylibs/locales/uk_UA.json index 9f9b3a7e..6cb75e2b 100644 --- a/PortMaster/pylibs/locales/uk_UA.json +++ b/PortMaster/pylibs/locales/uk_UA.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "Редактор тем зупинився. Див. theme_server.txt у теці PortMaster.", "{theme_name} (Selected)": "{theme_name} (Обрано)", "Download": "Завантажити", + "Theme {theme_name} is not downloaded, would you like to download it?": "Тему {theme_name} не завантажено. Завантажити її?", "{item_name} (Selected)": "{item_name} (Обрано)", "Please wait.": "Будь ласка, зачекайте.", "Up to date already": "Вже оновлено", diff --git a/PortMaster/pylibs/locales/zh_CN.json b/PortMaster/pylibs/locales/zh_CN.json index ac8e566f..57606739 100644 --- a/PortMaster/pylibs/locales/zh_CN.json +++ b/PortMaster/pylibs/locales/zh_CN.json @@ -304,6 +304,7 @@ "The theme editor stopped. See theme_server.txt in the PortMaster folder.": "主题编辑器已停止。请查看 PortMaster 文件夹中的 theme_server.txt。", "{theme_name} (Selected)": "{theme_name} (已选)", "Download": "下载", + "Theme {theme_name} is not downloaded, would you like to download it?": "主题 {theme_name} 尚未下载,是否要下载?", "{item_name} (Selected)": "{item_name} (已选)", "Please wait.": "请稍候。", "Up to date already": "已经更新", diff --git a/PortMaster/pylibs/pugwash/scenes/themes.py b/PortMaster/pylibs/pugwash/scenes/themes.py index 7ac7aa86..5848ed45 100644 --- a/PortMaster/pylibs/pugwash/scenes/themes.py +++ b/PortMaster/pylibs/pugwash/scenes/themes.py @@ -52,6 +52,18 @@ def update_selection(self): self.set_buttons(keys) + def download_theme(self): + theme_info = self.themes[self.last_select] + + with self.gui.enable_cancellable(True): + with self.gui.enable_messages(): + self.gui.do_install(theme_info['name'], theme_info['url'] + ".md5") + + self.themes = self.gui.themes.get_themes_list( + self.gui.theme_downloader.get_theme_list()) + + self.update_selection() + def do_update(self, events): super().do_update(events) @@ -63,9 +75,24 @@ def do_update(self, events): theme_info = self.themes[self.last_select] if theme_info['status'] not in ("Installed", "Update Available"): - return True + if theme_info['url'] is None: + return True - self.button_activate() + if not self.gui.message_box( + _("Theme {theme_name} is not downloaded, would you like to download it?").format( + theme_name=theme_info['name']), + want_cancel=True): + return True + + self.button_activate() + self.download_theme() + + ## Downloaded: on to what A does for it, using it. + if self.themes.get(self.last_select, {}).get('status') not in ("Installed", "Update Available"): + return True + + else: + self.button_activate() ## Applies straight away, back in this list. from .options import OptionScene @@ -82,16 +109,7 @@ def do_update(self, events): return True self.button_activate() - - with self.gui.enable_cancellable(True): - with self.gui.enable_messages(): - self.gui.do_install(theme_info['name'], theme_info['url'] + ".md5") - - self.themes = self.gui.themes.get_themes_list( - self.gui.theme_downloader.get_theme_list()) - - self.update_selection() - + self.download_theme() return True elif events.was_pressed('B'): diff --git a/tests/test_gui_screens.py b/tests/test_gui_screens.py index 4bf453df..3b0c8aaf 100644 --- a/tests/test_gui_screens.py +++ b/tests/test_gui_screens.py @@ -495,7 +495,7 @@ def test_themes_select(screen_gui, themes, monkeypatch): assert screen_gui.events.running is True -def test_themes_not_installed_cant_be_selected(screen_gui, themes, monkeypatch): +def test_themes_x_downloads(screen_gui, themes, monkeypatch): themes.themes['remote_theme'] = dict(themes.themes['default_theme'], name="Remote", status="Not Installed", url="https://example.com/remote.theme.zip") ## Still listed after the download reloads the list. listed = dict(themes.themes) @@ -509,13 +509,73 @@ def test_themes_not_installed_cant_be_selected(screen_gui, themes, monkeypatch): screen_gui.do_loop(no_delay=True) assert "Download" in bar(themes) and "Select" not in bar(themes) - press(screen_gui, monkeypatch, 'A') - assert screen_gui.boxes == [] - press(screen_gui, monkeypatch, 'X') assert installs == [("Remote", "https://example.com/remote.theme.zip.md5")] +@pytest.fixture +def remote_theme(screen_gui, themes, monkeypatch): + """A theme that isn't downloaded, selected; `installs` gets what was downloaded, `reloads` what was applied.""" + themes.themes['remote_theme'] = dict(themes.themes['default_theme'], name="Remote", status="Not Installed", url="https://example.com/remote.theme.zip") + listed = {name: dict(info) for name, info in themes.themes.items()} + monkeypatch.setattr(screen_gui.themes, "get_themes_list", lambda *args: {name: dict(info) for name, info in listed.items()}) + themes.tags['themes_list'].add_option('remote_theme', "Remote") + + remote_theme = type("Remote", (), {})() + remote_theme.installs = [] + remote_theme.reloads = [] + remote_theme.listed = listed + + def do_install(name, url): + remote_theme.installs.append((name, url)) + if remote_theme.works: + listed['remote_theme']['status'] = "Installed" + + remote_theme.works = True + monkeypatch.setattr(screen_gui, "do_install", do_install) + monkeypatch.setattr(screen_gui, "reload_theme", lambda then=None: remote_theme.reloads.append([name for name, _ in then])) + monkeypatch.setitem(screen_gui.hm.cfg_data, 'theme', 'default_theme') + + select(themes, 'remote_theme', tag='themes_list') + screen_gui.do_loop(no_delay=True) + return remote_theme + + +def test_themes_a_asks_to_download(screen_gui, themes, remote_theme, monkeypatch): + ## A on a theme that isn't downloaded asks; yes downloads it, then uses it. + press(screen_gui, monkeypatch, 'A') + + assert screen_gui.boxes == ["Theme Remote is not downloaded, would you like to download it?"] + assert remote_theme.installs == [("Remote", "https://example.com/remote.theme.zip.md5")] + assert screen_gui.hm.cfg_data['theme'] == 'remote_theme' + assert remote_theme.reloads == [['option', 'select-theme']] + + +def test_themes_a_download_declined(screen_gui, themes, remote_theme, monkeypatch): + screen_gui.answer = False + press(screen_gui, monkeypatch, 'A') + + assert len(screen_gui.boxes) == 1 + assert remote_theme.installs == [] and remote_theme.reloads == [] + assert screen_gui.hm.cfg_data['theme'] == 'default_theme' + + +def test_themes_a_download_failed(screen_gui, themes, remote_theme, monkeypatch): + ## Still not installed afterwards (failed, cancelled): the theme stays as it was. + remote_theme.works = False + press(screen_gui, monkeypatch, 'A') + + assert len(remote_theme.installs) == 1 + assert remote_theme.reloads == [] and screen_gui.hm.cfg_data['theme'] == 'default_theme' + + +def test_themes_a_without_a_url(screen_gui, themes, remote_theme, monkeypatch): + ## Not installed and nowhere to download it from: nothing to ask. + themes.themes['remote_theme']['url'] = None + press(screen_gui, monkeypatch, 'A') + assert screen_gui.boxes == [] and remote_theme.installs == [] + + def test_themes_x_without_a_url(screen_gui, themes, monkeypatch): installs = [] monkeypatch.setattr(screen_gui, "do_install", lambda name, url: installs.append(name))