Skip to content

Commit c2669d2

Browse files
authored
allow to use different plugin name (#186)
1 parent b05e96b commit c2669d2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

oqtopus/core/settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,24 @@ class Settings:
7070
Settings().installed_project_path.setValue(
7171
path, dynamicKeyPartList=[module_id, version]
7272
)
73+
74+
A custom *plugin_name* can be passed on first instantiation to
75+
register settings under a different tree node (e.g. ``"tmmt"``).
76+
Subsequent calls ignore the argument and return the existing
77+
singleton.
7378
"""
7479

7580
instance = None
7681

77-
def __new__(cls):
82+
def __new__(cls, plugin_name=None):
7883
if cls.instance is not None:
7984
return cls.instance
8085

8186
cls.instance = super().__new__(cls)
87+
cls._plugin_name = plugin_name or PLUGIN_NAME
8288

8389
if HAS_QGS_SETTINGS:
84-
settings_node = QgsSettingsTree.createPluginTreeNode(pluginName=PLUGIN_NAME)
90+
settings_node = QgsSettingsTree.createPluginTreeNode(pluginName=cls._plugin_name)
8591

8692
cls.github_token = QgsSettingsEntryString(
8793
"github-token",

oqtopus/oqtopus_plugin.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
from qgis.PyQt.QtGui import QIcon
55
from qgis.PyQt.QtWidgets import QAction, QApplication
66

7-
from .core.settings import PLUGIN_NAME, Settings
7+
from .core.settings import Settings
88
from .gui.about_dialog import AboutDialog
99
from .gui.main_dialog import MainDialog
1010
from .utils.plugin_utils import PluginUtils, logger
1111

1212

1313
class OqtopusPlugin:
1414

15-
def __init__(self, iface, modules_config_path=None, about_dialog_cls=None):
15+
def __init__(
16+
self, iface, modules_config_path=None, about_dialog_cls=None, settings_plugin_name=None
17+
):
1618
"""Constructor.
1719
1820
:param iface: An interface instance that will be passed to this class
@@ -25,6 +27,9 @@ def __init__(self, iface, modules_config_path=None, about_dialog_cls=None):
2527
:param about_dialog_cls: Optional custom About dialog class.
2628
Defaults to the bundled ``AboutDialog``.
2729
:type about_dialog_cls: type | None
30+
:param settings_plugin_name: Optional name for the QGIS settings tree node.
31+
Defaults to ``"oqtopus"``.
32+
:type settings_plugin_name: str | None
2833
"""
2934
# Save reference to the QGIS interface
3035
self.iface = iface
@@ -33,6 +38,7 @@ def __init__(self, iface, modules_config_path=None, about_dialog_cls=None):
3338
modules_config_path or Path(__file__).parent / "default_config.yaml"
3439
)
3540
self._about_dialog_cls = about_dialog_cls or AboutDialog
41+
self._settings_plugin_name = settings_plugin_name
3642

3743
self.__version__ = PluginUtils.get_plugin_version()
3844

@@ -131,7 +137,7 @@ def add_action(
131137
def initGui(self):
132138
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
133139
# Register settings tree node early
134-
Settings()
140+
Settings(plugin_name=self._settings_plugin_name)
135141

136142
self.add_action(
137143
icon_path=PluginUtils.get_plugin_icon_path("oqtopus-logo.png"),
@@ -173,7 +179,7 @@ def unload(self):
173179
self.iface.removeToolBarIcon(action)
174180

175181
# Unregister the plugin settings tree node
176-
QgsSettingsTree.unregisterPluginTreeNode(PLUGIN_NAME)
182+
QgsSettingsTree.unregisterPluginTreeNode(Settings._plugin_name)
177183
Settings.instance = None
178184

179185
# Remove pum modules from sys.modules to allow proper reloading

0 commit comments

Comments
 (0)