def __init__(self, pubsub=None): tick_strangle_max = op.truediv(optz.tbf_max_delay, optz.tbf_tick) self._note_limit = core.FC_TokenBucket( tick=optz.tbf_tick, burst=optz.tbf_size, tick_strangle=lambda x: min(x * optz.tbf_inc, tick_strangle_max), tick_free=lambda x: max(op.truediv(x, optz.tbf_dec), 1)) self._note_buffer = core.RRQ(optz.queue_len) self._note_history = core.RRQ(optz.history_len) self._note_windows = dict() self._note_id_pool = it.chain.from_iterable( it.imap(ft.partial(xrange, 1), it.repeat(2**30))) self._renderer = NotificationDisplay( optz.layout_margin, optz.layout_anchor, optz.layout_direction, icon_scale=optz.icon_scale, markup_default=not optz.markup_disable, markup_warn=optz.markup_warn_on_err, markup_strip=optz.markup_strip_on_err) self._activity_event() self.pubsub = pubsub if pubsub: GLib.io_add_watch(pubsub.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN | GLib.IO_PRI, self._notify_pubsub) if optz.test_message: # Also test crazy web-of-90s markup here :P summary = 'Notification daemon started <small><tt>¯\(°_o)/¯</tt></small>' body = ( 'Desktop notification daemon started successfully on host: <u>{host}</u>' '\nVersion: <span stretch="extraexpanded">{v}</span>' '\nCode path: <small>{code}</small>' '\nSound enabled: <span color="{sound_color}">{sound}</span>' '\nPubSub enabled: <span color="{pubsub_color}">{pubsub}</span>' )\ .format( host=os.uname()[1], v=core.__version__, sound_color='green' if optz.filter_sound else 'red', sound=unicode(bool(optz.filter_sound)).lower(), pubsub_color='green' if pubsub else 'red', pubsub=unicode(bool(pubsub)).lower(), code=os.path.abspath(os.path.dirname(core.__file__)) ) if not self._renderer.markup_default: summary, body = it.imap(strip_markup, [summary, body]) self.display(summary, body) if optz.test_sound and optz.filter_sound: optz.filter_sound['play'](optz.test_sound)
def __init__(self, *argz, **kwz): tick_strangle_max = op.truediv(optz.tbf_max_delay, optz.tbf_tick) super(NotificationDaemon, self).__init__(*argz, **kwz) self._note_limit = core.FC_TokenBucket( tick=optz.tbf_tick, burst=optz.tbf_size, tick_strangle=lambda x: min(x * optz.tbf_inc, tick_strangle_max), tick_free=lambda x: max(op.truediv(x, optz.tbf_dec), 1)) self._note_buffer = core.RRQ(optz.queue_len) self._note_windows = dict() self._note_id_pool = it.chain.from_iterable( it.imap(ft.partial(xrange, 1), it.repeat(2**30))) self._renderer = NotificationDisplay(optz.layout_margin, optz.layout_anchor, optz.layout_direction, optz.img_w, optz.img_h) self._activity_event()