Пример #1
0
def update():
    try:
        fg_color = config.FG_COLOR
        icon = ICON_AC

        ac_vals = utils.parse_file(FILE_AC, RE_AC_ONLINE)
        bat_vals = utils.parse_file([FILE_BAT_INFO, FILE_BAT_STATE], [RE_FULL_CAPACITY, RE_REMAINING_CAPACITY, RE_PRESENT_RATE])

        lastfull = float(bat_vals['lastfull'][0])
        remain = float(bat_vals['remain'][0])
        rate = float(bat_vals['rate'][0])

        percent = math.floor(remain / lastfull * 100.0 + 0.5)
        if percent < 25:
            fg_color = config.FG_COLOR_URGENT
        elif percent < 50:
            fg_color = config.FG_COLOR_NOTICE
        bat = utils.gdbar('%s %s' % (remain, lastfull), 
                          l = '%d%% ' % (100. / lastfull * remain))

        ac = ''
        if not ac_vals and rate > 0:
            mins = (3600.0 * (remain / rate)) / 60.0
            hours = math.floor(mins / 60.0)
            mins = math.floor(mins - (hours * 60.0))
            ac = ' %02d:%02d' % (hours, mins)
            icon = ICON_BAT

        return '^fg(%s)^i(%s)%s%s^fg()' % (fg_color, icon, bat, ac)
    except StandardError, e:
        logger.warn(e)
Пример #2
0
def update():
    try:
        fg_color = config.FG_COLOR
        icon = ICON_AC

        ac_vals = bool(int(open(os.path.join(AC, "online")).read()))

        lastfull = int(open(os.path.join(BAT, "energy_full")).read())
        remain = int(open(os.path.join(BAT, "energy_now")).read())
        rate = int(open(os.path.join(BAT, "voltage_now")).read())

        percent = 100.0 / lastfull * remain
        if percent < 25:
            fg_color = config.FG_COLOR_URGENT
        elif percent < 50:
            fg_color = config.FG_COLOR_NOTICE
        bat = utils.gdbar("%s %s" % (remain, lastfull), l="%d%% " % percent)

        ac = ""
        if not ac_vals and rate > 0:
            mins = (3600.0 * (float(remain) / float(rate))) / 60.0
            hours = math.floor(mins / 60.0)
            mins = math.floor(mins - (hours * 60.0))
            ac = " %02d:%02d" % (hours, mins)
            icon = ICON_BAT

        return "^fg(%s)^i(%s)%s%s^fg()" % (fg_color, icon, bat, ac)
    except StandardError, e:
        logger.warn(e)
Пример #3
0
def update():
    global amarok

    if has_pydcop:
        try:
            if 'amarok' in pydcop.apps():
                if not amarok:
                    amarok = pydcop.DCOPObject('amarok', 'player')

                state = dict(artist = amarok.artist(),
                             album = amarok.album(),
                             title = amarok.title(),
                             currentTime = amarok.trackCurrentTime(),
                             totalTime = amarok.trackTotalTime(),
                             status = amarok.status())

                song = '--'
                if state['status'] != AMAROK_STOP:
                    song = ' %s' % songstr(state)
                icon = { AMAROK_PLAY: ICON_PLAY,
                         AMAROK_PAUSE: ICON_PAUSE,
                         AMAROK_STOP: ICON_STOP}.get(state['status'], ICON_STOP)
                progress = ''
                progress_detail = ''
                if state['status'] != AMAROK_STOP:
                    state['currentMin'] = state['currentTime'] / 60
                    state['currentSec'] = state['currentTime'] % 60
                    state['totalMin'] = state['totalTime'] / 60
                    state['totalSec'] = state['totalTime'] % 60
                    state['song'] = song

                    progress = utils.gdbar('%(currentTime)d %(totalTime)d' % state,
                                           l = '%d%% ' % (100. / state['totalTime'] * state['currentTime']))
                    progress_detail = '[%(currentMin)02d:%(currentSec)02d/%(totalMin)02d:%(totalSec)02d]' % state
                return ['Amarok: ^i(%s)%s' % (icon, progress),
                        'Amarok: %s%s' % (song, progress_detail)]
        except (StandardError, RuntimeError), e:
            amarok = None  # try to reconnect if connection is lost
            logger.warn(e)
Пример #4
0
def update():
    global mpd
        
    if has_pympd:
        try:
            if not mpd:
                mpd = mpdlib2.connect()

            status = mpd.status()

            if status:
                song = '--'
                if status.state != 'stop':
                    song = ' %s' % songstr(mpd.currentsong())
                icon = dict(play = ICON_PLAY, pause = ICON_PAUSE, stop = ICON_STOP).get(status.state, '')
                progress = ''
                if 'time' in status:
                    cur, max = [float(i) for i in status['time'].split(':')]
                    progress = utils.gdbar('%d %d' % (cur, max), l = '%d%% ' % (100. / max * cur))
                return ['MPD: ^i(%s)%s' % (icon, progress),
                        'MPD: %s' % song]
        except (StandardError, socket.error), e:
            mpd = None  # try to reconnect if connection is lost
            logger.warn(e)
Пример #5
0
def bar(used, total):
    return utils.gdbar('%d %d' % (used, total), l = '%d%% ' % (100. / total * used))