Skip to content

Commit 4645510

Browse files
committed
just a code update to set the config path in the decorator.
1 parent 9a11be3 commit 4645510

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

addon/globalPlugins/beepKeyboard/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212

1313
from ._configHelper import configSpec, registerConfig
14-
@configSpec
14+
@configSpec('beepKeyboard')
1515
class AppConfig:
16-
__path__ = 'beepKeyboard'
1716
beepUpperWithCapsLock = 'boolean(default=True)'
1817
beepCharacterWithShift = 'boolean(default=False)'
1918
beepToggleKeyChanges = 'boolean(default=False)'

addon/globalPlugins/beepKeyboard/_configHelper.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,31 @@ def createSpec(self):
9191
__confOpts__ = []
9292

9393

94-
def configSpec(cls):
95-
class ConfigSpec(BaseConfig):
96-
pass
97-
98-
for k in cls.__dict__:
99-
if k == '__path__':
100-
ConfigSpec.__path__ = cls.__path__
101-
if k.startswith("__"): continue
102-
v = getattr(cls, k)
103-
d = OptConfig(v)
104-
d.__set_name__(ConfigSpec, k)
105-
setattr(ConfigSpec, k, d)
106-
return ConfigSpec
94+
def configSpec(pathOrCls):
95+
""" a decorator to help with the generation of the class config spec.
96+
adds a get and set descriptor for eatch attribute in the config class.
97+
except the attributes starting with "__".
98+
params:
99+
@pathOrCls: the config path,
100+
or if the decorator is called without params, then the decorated class.
101+
path as an argument in the decorator has a higher priority than the __path__ declared in the class.
102+
"""
103+
def configDecorator(cls):
104+
class ConfigSpec(BaseConfig):
105+
pass
106+
107+
for k in cls.__dict__:
108+
if k == '__path__':
109+
ConfigSpec.__path__ = cls.__path__
110+
if k.startswith("__"): continue
111+
v = getattr(cls, k)
112+
d = OptConfig(v)
113+
d.__set_name__(ConfigSpec, k)
114+
setattr(ConfigSpec, k, d)
115+
if isinstance(pathOrCls, str):
116+
ConfigSpec.__path__ = pathOrCls
117+
return ConfigSpec
118+
if isinstance(pathOrCls, str):
119+
return configDecorator
120+
else:
121+
return configDecorator(pathOrCls)

0 commit comments

Comments
 (0)