Merge pull request #98 from Arvedui/disable_click_events

Optionally disable click events
This commit is contained in:
enkore 2014-08-15 14:22:30 +02:00
commit 521804449e
2 changed files with 14 additions and 8 deletions

View File

@ -42,11 +42,13 @@ class Status:
:param input_stream: A file-like object that provides the input stream, if `standalone` is False. :param input_stream: A file-like object that provides the input stream, if `standalone` is False.
""" """
def __init__(self, standalone=False, interval=1, input_stream=sys.stdin): def __init__(self, standalone=False, interval=1, input_stream=sys.stdin, click_events=True):
self.modules = util.ModuleList(self, ClassFinder(Module)) self.modules = util.ModuleList(self, ClassFinder(Module))
self.standalone = standalone self.standalone = standalone
self.click_events = click_events
if standalone: if standalone:
self.io = io.StandaloneIO(interval) self.io = io.StandaloneIO(self.click_events, interval)
if self.click_events:
self.command_endpoint = CommandEndpoint( self.command_endpoint = CommandEndpoint(
self.modules, self.modules,
lambda: io.JSONIO(io=io.IOHandler(sys.stdin, open(os.devnull, "w")), skiplines=1)) lambda: io.JSONIO(io=io.IOHandler(sys.stdin, open(os.devnull, "w")), skiplines=1))
@ -78,6 +80,7 @@ class Status:
text=configuration_error.message)) text=configuration_error.message))
def run(self): def run(self):
if self.click_events:
self.command_endpoint.start() self.command_endpoint.start()
for j in io.JSONIO(self.io).read(): for j in io.JSONIO(self.io).read():
for module in self.modules: for module in self.modules:

View File

@ -51,11 +51,14 @@ class StandaloneIO(IOHandler):
""" """
n = -1 n = -1
proto = ('{"version":1,"click_events":true}', "[", "[]", ",[]",) proto = [{"version":1,"click_events":True}, "[", "[]", ",[]",]
def __init__(self, interval=1): def __init__(self, click_events, interval=1):
super().__init__() super().__init__()
self.interval = interval self.interval = interval
self.proto[0]['click_events'] = click_events
self.proto[0] = json.dumps(self.proto[0])
def read(self): def read(self):
while True: while True: