コード例 #1
0
    def updateFile(self, track):
        """ Show the notification based on the given track """
        output = open(prefs.get(__name__, "file", PREFS_DEFAULT_FILE), "w")

        if track is None:
            output.write("")
        else:
            output.write(track.format(prefs.get(__name__, "status", PREFS_DEFAULT_STATUS)))

        output.close()
コード例 #2
0
    def __format(self, string, track):
        """ Replace the special fields in the given string by their corresponding value and sanitize the result """
        result = track.format(string)

        if len(prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS)) != 0:
            lowerResult = result.lower()
            for word in [w.lower() for w in prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS).split('\n') if len(w) > 2]:
                pos = lowerResult.find(word)
                while pos != -1:
                    result      = result[:pos+1] + ('*' * (len(word)-2)) + result[pos+len(word)-1:]
                    lowerResult = lowerResult[:pos+1] + ('*' * (len(word)-2)) + lowerResult[pos+len(word)-1:]
                    pos         = lowerResult.find(word)

        return result
コード例 #3
0
    def showNotification(self, track):
        """ Show the notification based on the given track """
        body  = track.formatHTMLSafe(prefs.get(__name__, 'body',  PREFS_DEFAULT_BODY))
        title = track.format(prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE))

        # Make sure the notification exists
        if self.notif is None:
            import pynotify

            img = os.path.join(consts.dirPix, 'decibel-audio-player-64.png')
            if os.path.isfile(img):
                self.icon = 'file://' + img

            self.notif = pynotify.Notification(title, body, self.icon)
            self.notif.set_urgency(pynotify.URGENCY_LOW)
            self.notif.set_timeout(prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT) * 1000)

            if prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK):
                self.notif.add_action('stop', _('Skip track'), self.onSkipTrack)

        self.notif.update(title, body, self.icon)
        self.notif.show()