|
| 1 | +# Copyright (c) 2023 Aldo Hoeben / fieldOfView |
| 2 | +# The SidebarGUIPlugin is released under the terms of the AGPLv3 or higher. |
| 3 | + |
| 4 | +import os.path |
| 5 | +import json |
| 6 | + |
| 7 | +from PyQt6.QtCore import QUrl |
| 8 | +from PyQt6.QtGui import QDesktopServices |
| 9 | + |
| 10 | +from cura.CuraApplication import CuraApplication |
| 11 | +from UM.Extension import Extension |
| 12 | +from UM.Message import Message |
| 13 | +from UM.Version import Version |
| 14 | + |
| 15 | +from UM.i18n import i18nCatalog |
| 16 | + |
| 17 | +i18n_catalog = i18nCatalog("octoprint") |
| 18 | + |
| 19 | + |
| 20 | +class SidebarIncompatibleVersion(Extension): |
| 21 | + HIDE_MESSAGE_PREFERENCE = "sidebargui/hide_incompatibility_message" |
| 22 | + |
| 23 | + def __init__(self): |
| 24 | + super().__init__() |
| 25 | + |
| 26 | + cura_version = CuraApplication.getInstance().getVersion() |
| 27 | + if cura_version == "master" or cura_version == "dev": |
| 28 | + cura_version = "" |
| 29 | + if cura_version.startswith("Arachne_engine"): |
| 30 | + cura_version = "" |
| 31 | + |
| 32 | + cura_version = Version(cura_version) |
| 33 | + cura_version = Version([cura_version.getMajor(), cura_version.getMinor()]) |
| 34 | + |
| 35 | + # Get version information from plugin.json |
| 36 | + plugin_file_path = os.path.join( |
| 37 | + os.path.dirname(os.path.abspath(__file__)), "plugin.json" |
| 38 | + ) |
| 39 | + try: |
| 40 | + with open(plugin_file_path) as plugin_file: |
| 41 | + plugin_info = json.load(plugin_file) |
| 42 | + plugin_version = Version(plugin_info["version"]) |
| 43 | + except Exception: |
| 44 | + plugin_version = Version() |
| 45 | + |
| 46 | + self._version_combination = "%s/%s" % (str(cura_version), str(plugin_version)) |
| 47 | + |
| 48 | + preferences = CuraApplication.getInstance().getPreferences() |
| 49 | + preferences.addPreference(self.HIDE_MESSAGE_PREFERENCE, []) |
| 50 | + if self._version_combination in preferences.getValue(self.HIDE_MESSAGE_PREFERENCE): |
| 51 | + return |
| 52 | + |
| 53 | + self._incompatibility_message = Message( |
| 54 | + i18n_catalog.i18nc( |
| 55 | + "@info:status", |
| 56 | + "Using this version of the Sidebar GUI plugin with this version of Cura is untested and might cause issues so it is disabled. " |
| 57 | + "An updated version of the plugin may be available on github and/or (soon) in the Marketplace.", |
| 58 | + ), |
| 59 | + title=i18n_catalog.i18nc("@label", "Sidebar GUI"), |
| 60 | + option_text=i18n_catalog.i18nc("@info:option_text", "Do not show this message again for this version of Cura"), |
| 61 | + option_state=False, |
| 62 | + ) |
| 63 | + self._incompatibility_message.optionToggled.connect(self._onDontTellMeAgain) |
| 64 | + self._incompatibility_message.addAction("github", |
| 65 | + name = i18n_catalog.i18nc("@action:button", "Open Github..."), |
| 66 | + icon = "", |
| 67 | + description = "Visit the releases page on Github to check for a new version", |
| 68 | + button_align = Message.ActionButtonAlignment.ALIGN_LEFT, |
| 69 | + button_style=2) |
| 70 | + self._incompatibility_message.addAction("marketplace", |
| 71 | + name = i18n_catalog.i18nc("@action:button", "Marketplace..."), |
| 72 | + icon = "", |
| 73 | + description = "Open Marketplace to check for a new version", |
| 74 | + button_align = Message.ActionButtonAlignment.ALIGN_LEFT, |
| 75 | + button_style=2) |
| 76 | + self._incompatibility_message.addAction("dismiss", |
| 77 | + name = i18n_catalog.i18nc("@action:button", "Ok"), |
| 78 | + icon = "", |
| 79 | + description = "Dismiss this message", |
| 80 | + button_align = Message.ActionButtonAlignment.ALIGN_RIGHT) |
| 81 | + self._incompatibility_message.actionTriggered.connect(self._onMessageAction) |
| 82 | + self._incompatibility_message.show() |
| 83 | + |
| 84 | + def _onDontTellMeAgain(self, checked: bool) -> None: |
| 85 | + preferences = CuraApplication.getInstance().getPreferences() |
| 86 | + |
| 87 | + version_combinations = set(preferences.getValue(self.HIDE_MESSAGE_PREFERENCE).split(",")) |
| 88 | + if checked: |
| 89 | + version_combinations.add(self._version_combination) |
| 90 | + else: |
| 91 | + version_combinations.discard(self._version_combination) |
| 92 | + preferences.setValue(self.HIDE_MESSAGE_PREFERENCE, ";".join(version_combinations)) |
| 93 | + |
| 94 | + def _onMessageAction(self, message, action) -> None: |
| 95 | + if action=="dismiss": |
| 96 | + message.hide() |
| 97 | + |
| 98 | + elif action=="github": |
| 99 | + QDesktopServices.openUrl(QUrl("https://github.com/fieldOfView/Cura-SidebarGUIPlugin/releases")) |
| 100 | + |
| 101 | + elif action=="marketplace": |
| 102 | + marketplace = CuraApplication.getInstance().getPluginRegistry().getPluginObject("Marketplace") |
| 103 | + if marketplace: |
| 104 | + marketplace.show() |
| 105 | + |
0 commit comments