On Sun, May 30, 2010 at 09:52:35PM +0200, pascal wrote:
Hi again

I'm using the python script and I wonder if I do it correctly. I copied the
content of /etc/wmii-hg/python into ~/.wmii-hg and moved wmiirc.py to
wmiirc_local.py. The thing is it seems the script in /etc/wmii-hg is read first
because wmii is starting with the default appearance (for less than one second),
and I get the message "witray: fatal: another system tray is already running",
probably due to the fact that it's also called from the wmiirc_local.py.
So I tried to only leave my modifications in the wmiirc_local.py along with the
import statements, but then some of my modifications aren't effective, for
example it keeps using xterm in place of urxvtc, and my theme is not applied
all at once.

I'm getting confused trying to read the above, so I'll just explain from the begining.

You don't want to copy wmiirc.py to wmiirc_local.py. The whole point of wmiirc_local.py is that it gets called *in addion to* wmiirc.py. So if you copy the former to the latter, you just execute it twice (and therefore you execute witray twice, as well). The witray error is because, for the moment, witray just gives up rathe than taking over for another system tray. It may change in the future.

As for copying files from /etc/wmii-hg, you almost certainly don't want to do that. Instead, run wmii as ‘wmii -r python/wmiirc’ and it will run /etc/wmii-hg/python/wmiirc for you. Any customization you want to do, do in ~/.wmii-hg/wmiirc_local.py or ~/.wmii-hg/plugins/any_filename_you_want.py. Only in the event that you can't manage your customizations in wmiirc_local.py should you copy /etc/wmii-hg/python/wmiirc.py to ~/.wmii-hg/wmiirc.py and edit it. But don't copy *any* other files.

I hope the above wasn't too confusing. If you want an example, my wmiirc_local.py is attached.

And then a detail, to get the time displayed in my locale I add these two lines
in ~/.wmii-hg/wmiirc :
import locale
locale.setlocale(locale.LC_ALL, "")
I wonder if that's the right place to put it, and if it could be included in
the default configuration?

Why would you want any kind of locale-specific time? Here's what I do:

@defmonitoR(colors=wmii['focuscolors'], name='time')
def s9time(self):
    return time.strftime('%H:%M:%S %Z')
@defmonitor(interval=60)
def s9date(self):
    return time.strftime('%a, %d %b')

--
Kris Maglione

Oh, come *on*.  Revelation was a mushroom dream that belonged in the
Apocrypha.  The New Testament is basically about what happened when
God got religion.
        --Terry Pratchett, alt.fan.pratchett

# coding=UTF-8
import operator
import os
import re
import signal
import subprocess
import sys
from threading import Thread
import time
import traceback

sys.path.append(os.environ['HOME'] + '/lib/python')
import alsaaudio

import pygmi
from pygmi import *

import wmiirc
from wmiirc import notice, tags

time.tzset()

zip = '17402'
zip = '34450'

temp_min = 69
temp_max = 91

wmiirc.terminal = 'wmiir', 'setsid', 'term'

wmii['font'] = 'xft:drift:pixelsize=12'

from wmiirc import Actions
events.bind({
    'Eval': lambda args: Actions.eval_(args)
});

wmii.tagrules = (
    (r'^::.*VLC',    'sel+~'),
    (r'^huludesktop:','tv'),
    (r'^::',         'orphans'),
    (r'^quodlibet:', 'music'),
    (r'^transmission:', 'bt'),
    (r'^amarok:', 'music'),
    (r'^Transmission:', 'torrent'),
    (r'^[Gg]imp',    'gimp'),
    (r'^[Ii]nkscape','inkscape'),
    (r'XMMS',        '~'), # No, I don't use this, but I do test it. :(
    (r'VLC|MPlayer', '~'),
    (r'^pinentry',   '~'),
    (r'^xmag',   '~'),

    (r'^claws-mail:', 'mail'),

    (r'^[^:]+:(Minefield|Namoroka):(Page Info|Firefox Preferences|Tab Mix Plus Options|Add-ons)$', '~+www'),
    (r'^[^:]+:(Minefield|Namoroka):', 'www'),

    (r'^[^:]*:OpenOffice.org', 'OOo'),
    (r'^vinagre:Vinagre:', 'vnc'),
)

def toggle_mute():
    mixer = alsaaudio.Mixer()
    if mixer.getmute()[0]:
        mixer.setmute(0)
        notice.write('Unmute')
    else:
        mixer.setmute(1)
        notice.write('Mute')

    if False:
        cmd = 'unmute'
        if '[on]' in call('amixer', 'get', 'Master'):
            cmd = 'mute'
        call('amixer', 'set', 'Master', cmd)
        notice.write(cmd.capitalize())

def adj_mixer(delta, mod=None):

    import mixer
    if mod is not None:
        mixer.mod += 1
        if mixer.mod % mod:
            return
    vol = mixer.getlevel('vol')
    vol = vol - vol % abs(delta) + delta
    vol = min(100, max(0, vol))
    mixer.setlevel('vol', vol)

    alsaaudio.Mixer('PCM').setvolume(100)

    nbar = 20
    bar = '-' * (nbar - 1) + '|'
    notice.write('[% -*s] %3d%%' % (nbar, bar[nbar-nbar*vol/100:], vol))

keys.bind('main', {
    'dead_horn':  lambda k: call('sudo', 'hibernate', '--force'),
    'XF86AudioMute': lambda k: toggle_mute(),
    '%(mod)s-F6': lambda k: call('stfo', background=True),

    '%(mod)s-KP_Add':       lambda k: adj_mixer(+5),
    '%(mod)s-KP_Subtract':  lambda k: adj_mixer(-5),
    'XF86AudioRaiseVolume': lambda k: adj_mixer(+5, 2),
    'XF86AudioLowerVolume': lambda k: adj_mixer(-5, 2),
})

tags.ignore.add('x')
keys.bind('main',   { '%(mod)s-x': lambda k: tags.select('x') })
keys.bind('xembed', { '%(mod)s-x': lambda k: tags.select(tags.PREV) })
events.bind({
    Match('FocusTag', 'x'):   lambda *a: (setattr(keys, 'mode', 'xembed'), wmii.__setitem__('modkey', 'Mod3')),
    Match('UnfocusTag', 'x'): lambda *a: (setattr(keys, 'mode', 'main'), wmii.__setitem__('modkey', 'Mod4')),
})

@defmonitor(colors=wmii['focuscolors'], name='time')
def s9time(self):
    return time.strftime('%H:%M:%S %Z')
@defmonitor(interval=60)
def s9date(self):
    return time.strftime('%a, %d %b')
monitors['load'].active = False
@defmonitor
def s5load(self):
    return ' '.join(open('/proc/loadavg').read().split(' ')[:3])


if True:
    norm  = wmii['normcolors']
    focus = wmii['focuscolors']
    def col(n, rat, col):
        return norm[col][n] + int((focus[col][n] - norm[col][n]) * rat)

    def cols(val, max_, ary):
        val = min(val, max_)
        val = max(val, 0)
        rat = float(val) / max_
        return Color((col(0, rat, ary),
                      col(1, rat, ary),
                      col(2, rat, ary)))

ps = subprocess.Popen(('iostat', '-c', '1'), stdout=subprocess.PIPE, close_fds=True,
                      preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL))
def loadmonitor():
    cpubutton = Button('right', 's3cpu')
    iobutton  = Button('right', 's4io')

    last = 0
    while True:
        line = ps.stdout.readline()
        if line is None:
            break
        if line[0] == ' ':
            if (time.time() - last) < .9:
                continue
            last = time.time()

            us, ni, sy, await, steal, idle = map(float, line.split())
            to = us + sy
            cpubutton.colors = ((0, 0, 0),
                                cols(to, 100, 'background'),
                                cols(to, 100, 'border'))
            cpubutton.label = '%d:%d+%d %d' % (to, us, sy, ni)

            iobutton.colors = ((0, 0, 0),
                               cols(await, 15, 'background'),
                               cols(await, 15, 'border'))
            iobutton.label = '%0.02f' % await
loadmonitor = Thread(target=loadmonitor)
loadmonitor.daemon = True
loadmonitor.start()

import pywapi
@defmonitor(interval=300)
def s7_0temp(self):
    res = pywapi.get_weather_from_google(zip)
    return u'%(temp_c)s°C %(temp_f)s°F' % res['current_conditions']

@defmonitor(interval=1)
def s7_5temp(self):
    temp = int(open('/proc/acpi/thermal_zone/THRM/temperature').read()
                .split()[1])
    return (((0, 0, 0),
             cols(temp - temp_min, temp_max - temp_min, 'background'),
             cols(temp - temp_min, temp_max - temp_min, 'border')),
            '%d°C' % temp)

@defmonitor(interval=1)
def s7batt(self):
    self.full = getattr(self, 'full', False)
    battery = '/proc/acpi/battery/BAT1'
    def val(s):
        k, v = re.split(r':\s*', s, 1)
        try:
            return k, float(v.split()[0])
        except Exception:
            return k, v.rstrip()
    def info(path, file):
        return dict(map(val, open('/'.join((path, file)))))

    acad = info('/proc/acpi/ac_adapter/ACAD', 'state')

    try:
        plugged = acad['state'] == 'on-line'
        if plugged and self.full:
            self.interval = 1
            return

        self.interval = 5
        state = info(battery, 'state')
        info  = info(battery, 'info')
        if plugged and state['charging state'] == 'charged':
            self.full = True
            return
        self.full = False
        percent = state['remaining capacity'] * 100 / \
                  info['last full capacity']
        percent = '%d%%' % percent
        if plugged or state['present rate'] == 0:
            return percent
        time = state['remaining capacity'] / state['present rate']
        return '%s %d:%02d' % (percent, time, time * 60 % 60)
    except KeyError:
        pass

# vim:se sts=4 sw=4 et:

Reply via email to