Add ModuleList
This commit is contained in:
parent
92b2af56a8
commit
1fd53cd60a
@ -48,8 +48,6 @@ class IntervalModule(AsyncModule):
|
|||||||
time.sleep(self.interval)
|
time.sleep(self.interval)
|
||||||
|
|
||||||
class i3pystatus:
|
class i3pystatus:
|
||||||
modules = []
|
|
||||||
|
|
||||||
def __init__(self, standalone=False, interval=1, input_stream=sys.stdin):
|
def __init__(self, standalone=False, interval=1, input_stream=sys.stdin):
|
||||||
if standalone:
|
if standalone:
|
||||||
self.io = core.io.StandaloneIO(interval)
|
self.io = core.io.StandaloneIO(interval)
|
||||||
@ -57,17 +55,13 @@ class i3pystatus:
|
|||||||
self.io = core.io.IOHandler(input_stream)
|
self.io = core.io.IOHandler(input_stream)
|
||||||
|
|
||||||
self.finder = ClassFinder(Module)
|
self.finder = ClassFinder(Module)
|
||||||
|
self.modules = ModuleList(self)
|
||||||
|
|
||||||
def register(self, module, *args, **kwargs):
|
def register(self, module, *args, **kwargs):
|
||||||
"""Register a new module."""
|
"""Register a new module."""
|
||||||
|
|
||||||
if not module: # One can pass in False or None, if he wishes to temporarily disable a module
|
if module:
|
||||||
return
|
self.modules.append(self.finder.instanciate_class_from_module(module, *args, **kwargs))
|
||||||
|
|
||||||
module = self.finder.instanciate_class_from_module(module, *args, **kwargs)
|
|
||||||
|
|
||||||
self.modules.append(module)
|
|
||||||
module.registered(self)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for j in core.io.JSONIO(self.io).read():
|
for j in core.io.JSONIO(self.io).read():
|
||||||
|
@ -8,8 +8,18 @@ from .exceptions import *
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"SettingsBase",
|
"SettingsBase",
|
||||||
"ClassFinder",
|
"ClassFinder",
|
||||||
|
"ModuleList",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class ModuleList(collections.UserList):
|
||||||
|
def __init__(self, status_handler):
|
||||||
|
self.status_handler = status_handler
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def append(self, module):
|
||||||
|
module.registered(self.status_handler)
|
||||||
|
super().append(module)
|
||||||
|
|
||||||
class KeyConstraintDict(collections.UserDict):
|
class KeyConstraintDict(collections.UserDict):
|
||||||
class MissingKeys(Exception):
|
class MissingKeys(Exception):
|
||||||
def __init__(self, keys):
|
def __init__(self, keys):
|
||||||
|
Loading…
Reference in New Issue
Block a user