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