-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSettings.py
More file actions
115 lines (93 loc) · 4.48 KB
/
Settings.py
File metadata and controls
115 lines (93 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Python Plugin Reloader for QGIS: Reloader's settings.
begin : 2024-07-04
copyright : (C) 2024 by Borys Jurgiel
email : qgis at borysjurgiel dot pl
The "Reload" icon copyright by Matt Ball http://www.mattballdesign.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from qgis.PyQt.QtCore import Qt, QSettings
class Settings():
"""A helper class for handling reloader's all QSettings."""
PREFIX = '/PluginReloader'
"""QSettings branch used by the plugin"""
DEFAULT_RECENT_PLUGINS_COUNT = 5
@classmethod
def recentPlugins(cls, listAll: bool = False) -> list[str]:
"""Recently used plugins. The most recent first.
:param listAll: List all stored plugins instead of cropping
to the currently configured number.
"""
if plugins := QSettings().value(f'{cls.PREFIX}/recentPlugins', '',
type=str):
plugins = [plugin.strip() for plugin in plugins]
else:
# Fallback to the old setting
currentPlugin = QSettings().value(f'{cls.PREFIX}/plugin', type=str)
plugins = [currentPlugin] if currentPlugin else []
if not listAll:
plugins = plugins[:cls.recentPluginsCount()]
return plugins
@classmethod
def updateRecentPlugins(cls, recentPlugin: str):
"""Set the recently reloaded plugin list. The most recent first."""
plugins = cls.recentPlugins()
if recentPlugin in plugins:
plugins.remove(recentPlugin)
plugins = [recentPlugin] + plugins
plugins = plugins[:cls.recentPluginsCount()]
QSettings().setValue(f'{cls.PREFIX}/recentPlugins', plugins)
@classmethod
def notificationsEnabled(cls) -> bool:
"""Whether plugin reload confirmaion message is enabled."""
return QSettings().value(f'{cls.PREFIX}/notify', True, type=bool)
@classmethod
def setNotificationsEnabled(cls, enabled: bool):
"""Enable or disable plugin reload confirmaion message."""
QSettings().setValue(f'{cls.PREFIX}/notify', enabled)
@classmethod
def extraCommandsEnabled(cls) -> bool:
"""Whether CLI command execution before plugin reload is enabled."""
return QSettings().value(f'{cls.PREFIX}/extraCommandsEnabled', False,
type=bool)
@classmethod
def setExtraCommandsEnabled(cls, enabled: bool):
"""Enable or disable CLI command execution prior to plugin reload."""
QSettings().setValue(f'{cls.PREFIX}/extraCommandsEnabled', enabled)
@classmethod
def getExtraCommands(cls) -> str:
"""CLI commands to be executed prior to the plugin reload."""
return QSettings().value(f'{cls.PREFIX}/extraCommands', '')
@classmethod
def setExtraCommands(cls, commands: str):
"""Set CLI commands to be executed prior to the plugin reload."""
QSettings().setValue(f'{cls.PREFIX}/extraCommands', commands)
@classmethod
def recentPluginsCount(cls) -> int:
"""Get the number of recent plugins to display in the menu."""
return QSettings().value(f'{cls.PREFIX}/recentPluginsCount',
cls.DEFAULT_RECENT_PLUGINS_COUNT,
type=int)
@classmethod
def setRecentPluginsCount(cls, count: int):
"""Set number of recent plugins to display in the menu."""
QSettings().setValue(f'{cls.PREFIX}/recentPluginsCount', count)
@classmethod
def toolButtonStyle(cls) -> Qt.ToolButtonStyle:
"""Get toolbar button style (with text or icon only)."""
if cls.toolButtonTextEnabled():
buttonStyle = Qt.ToolButtonStyle.ToolButtonTextBesideIcon
else:
buttonStyle = Qt.ToolButtonStyle.ToolButtonIconOnly
return buttonStyle
@classmethod
def toolButtonTextEnabled(cls) -> bool:
"""Whether to display text beside the toolbar icon."""
return QSettings().value(f'{cls.PREFIX}/toolButtonTextEnabled',
True, type=bool)
@classmethod
def setToolButtonTextEnabled(cls, state: bool):
"""Enable or disable text displayed beside the toolbar icon."""
QSettings().setValue(f'{cls.PREFIX}/toolButtonTextEnabled', state)