Skip to content

Commit ff2be09

Browse files
committed
Add clarifying message when plugin is not loaded due to version mismatch
1 parent 6ec5e06 commit ff2be09

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed

SidebarIncompatibleVersion.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+

__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import os, json
55

6-
from . import SidebarGUIPlugin
76
from UM.i18n import i18nCatalog
87

98
i18n_catalog = i18nCatalog("cura")
@@ -12,6 +11,9 @@
1211
from UM.Application import Application
1312
from UM.Logger import Logger
1413

14+
from . import SidebarGUIPlugin
15+
from . import SidebarIncompatibleVersion
16+
1517

1618
def getMetaData():
1719
return {}
@@ -22,7 +24,7 @@ def register(app):
2224
return {"extension": SidebarGUIPlugin.SidebarGUIPlugin()}
2325
else:
2426
Logger.log("w", "Plugin not loaded because of a version mismatch")
25-
return {}
27+
return {"extension": SidebarIncompatibleVersion.SidebarIncompatibleVersion()}
2628

2729

2830
def __matchVersion():
@@ -46,7 +48,7 @@ def __matchVersion():
4648
plugin_info = json.load(plugin_file)
4749
minimum_cura_version = Version(plugin_info["minimum_cura_version"])
4850
maximum_cura_version = Version(plugin_info["maximum_cura_version"])
49-
except:
51+
except Exception:
5052
Logger.log("w", "Could not get version information for the plugin")
5153
return False
5254

0 commit comments

Comments
 (0)