CommandEndpoint docs

This commit is contained in:
enkore 2013-10-23 21:35:50 +02:00
parent 3071e65550
commit c33cb3aa60

View File

@ -2,13 +2,19 @@
import sys import sys
import os import os
from threading import Thread from threading import Thread
from i3pystatus.core.imputil import ClassFinder
from i3pystatus.core.imputil import ClassFinder
from i3pystatus.core import io, util from i3pystatus.core import io, util
from i3pystatus.core.modules import Module from i3pystatus.core.modules import Module
class CommandEndpoint: class CommandEndpoint:
"""
Endpoint for i3bar click events: http://i3wm.org/docs/i3bar-protocol.html#_click_events
:param modules: dict-like object with item access semantics via .get()
:param io_handler_factory: function creating a file-like object returning a JSON generator on .read()
"""
def __init__(self, modules, io_handler_factory): def __init__(self, modules, io_handler_factory):
self.modules = modules self.modules = modules
self.io_handler_factory = io_handler_factory self.io_handler_factory = io_handler_factory
@ -16,11 +22,12 @@ class CommandEndpoint:
self.thread.daemon = True self.thread.daemon = True
def start(self): def start(self):
"""Starts the background thread"""
self.thread.start() self.thread.start()
def _command_endpoint(self): def _command_endpoint(self):
for command in self.io_handler_factory().read(): for command in self.io_handler_factory().read():
target_module = self.modules.get_module_by_id(command["instance"]) target_module = self.modules.get(command["instance"])
if target_module: if target_module:
target_module.on_click(command["button"]) target_module.on_click(command["button"])