Beispiel #1
0
def notify(text):
    """Displays a notification.

    Notification title and icon are read from the notify_title and notify_icon
    config options, some defaults are applies.  Messages are logged."""
    tmradio.log.debug(u"Notification: " + text)
    if HAVE_NOTIFY and not main_window_visible:
        global notification_title
        config = tmradio.config.Open()
        n = pynotify.Notification(
            config.get("notify_title", notification_title or "TMRadio Client"),
            text,
            config.get("notify_icon", "audio-volume-medium"),
        )
        n.set_urgency(pynotify.URGENCY_LOW)
        n.show()
Beispiel #2
0
    def add_message(self, **_kwargs):
        kwargs = {"time": datetime.datetime.now(), "nick": None, "nicklink": None, "message": ""}
        kwargs.update(_kwargs)

        ts = kwargs["time"]
        nick = kwargs["nick"]
        nicklink = kwargs["nicklink"]
        text = kwargs["message"].strip()

        tb = self.get_buffer()
        sob, eob = tb.get_bounds()

        if tb.get_char_count():
            tb.insert(eob, "\n")

        tb.insert_with_tags_by_name(eob, time.strftime("%d.%m %H:%M ", time.localtime(ts)), "time")
        self._add_nickname(tb, eob, kwargs)
        tb.insert(eob, ":")
        notifyUser = False
        for word in text.split(" "):
            tb.insert(eob, " ")
            if is_url(word):
                # http://www.mail-archive.com/[email protected]/msg18007.html
                t = tb.create_tag()
                t.set_property("foreground", "blue")
                t.set_property("underline", pango.UNDERLINE_SINGLE)
                t.connect("event", self.on_link_event, word)
                tb.insert_with_tags(eob, word, t)
                self.url_tags.append(t)
            elif self.highlight_re is not None and self.highlight_re.search(word) is not None:
                t = tb.create_tag()
                config = tmradio.config.Open()
                t.set_property("foreground", config.get("highlight_color", "red"))
                bg = config.get("highlight_bgcolor", None)
                if bg is not None:
                    t.set_property("background", bg)
                tb.insert_with_tags(eob, word, t)
                notifyUser = True
            else:
                tb.insert(eob, word)

        if not notifyUser and self.highlight_re is not None and self.highlight_re.search(text):
            notifyUser = True

        if notifyUser:
            notify(u"You were mentioned in the chat!")
Beispiel #3
0
    def add_message(self, **_kwargs):
        kwargs = {'time': datetime.datetime.now(), 'nick': None, 'nicklink': None, 'message': '' }
        kwargs.update(_kwargs)

        ts = kwargs['time']
        nick = kwargs['nick']
        nicklink = kwargs['nicklink']
        text = kwargs['message'].strip()

        tb = self.get_buffer()
        sob, eob = tb.get_bounds()

        if tb.get_char_count():
            tb.insert(eob, '\n')

        tb.insert_with_tags_by_name(eob, time.strftime('%d.%m %H:%M ', time.localtime(ts)), 'time')
        self._add_nickname(tb, eob, kwargs)
        tb.insert(eob, ':')
        notifyUser = False
        for word in text.split(' '):
            tb.insert(eob, ' ')
            if self.is_url(word):
                # http://www.mail-archive.com/[email protected]/msg18007.html
                t = tb.create_tag()
                t.set_property('foreground', 'blue')
                t.set_property('underline', pango.UNDERLINE_SINGLE)
                t.connect('event', self.on_link_event, word)
                tb.insert_with_tags(eob, word, t)
                self.url_tags.append(t)
            elif self.highlight_re is not None and self.highlight_re.search(word) is not None:
                t = tb.create_tag()
                config = tmradio.config.Open()
                t.set_property('foreground', config.get('highlight_color', 'red'))
                bg = config.get('highlight_bgcolor', None)
                if bg is not None:
                    t.set_property('background', bg)
                tb.insert_with_tags(eob, word, t)
                notifyUser = True
            else:
                tb.insert(eob, word)

        if not notifyUser and self.highlight_re is not None and self.highlight_re.search(text):
            notifyUser = True

        if notifyUser:
            notify(u'You were mentioned in the chat!')
Beispiel #4
0
    def get_highlight_re(self):
        config = tmradio.config.Open()

        expr = config.get('highlight_re')
        if expr is None:
            try: expr = config.get_jabber_id() + u'|' + config.get_jabber_chat_nick()
            except: return None

        return re.compile(expr)