Cleanup. Add wmiirc.local.py.

This commit is contained in:
Kris Maglione 2009-05-17 21:23:57 -04:00
parent 9ff6791633
commit 120f5a34a3
5 changed files with 47 additions and 30 deletions

View File

@ -35,6 +35,14 @@ def curry(func, *args, **kwargs):
curried.__name__ = func.__name__ + '__curried__' curried.__name__ = func.__name__ + '__curried__'
return curried return curried
def find_script(name):
for path in confpath:
if os.access('%s/%s' % (path, name), os.X_OK):
return '%s/%s' % (path, name)
confpath = os.environ['WMII_CONFPATH'].split(':')
shell = None
from pygmi import events, fs, menu, monitor from pygmi import events, fs, menu, monitor
from pygmi.events import * from pygmi.events import *
from pygmi.fs import * from pygmi.fs import *
@ -42,6 +50,8 @@ from pygmi.menu import *
from pygmi.monitor import * from pygmi.monitor import *
__all__ = (fs.__all__ + monitor.__all__ + events.__all__ + __all__ = (fs.__all__ + monitor.__all__ + events.__all__ +
menu.__all__ + ('client', 'call', 'curry', 'program_list')) menu.__all__ + (
'client', 'call', 'curry', 'program_list',
'find_script', 'confpath', 'shell'))
# vim:se sts=4 sw=4 et: # vim:se sts=4 sw=4 et:

View File

@ -3,6 +3,7 @@ import re
import sys import sys
import traceback import traceback
import pygmi
from pygmi import monitor, client, call, program_list from pygmi import monitor, client, call, program_list
__all__ = ('bind_keys', 'bind_events', 'toggle_keys', 'event_loop', __all__ = ('bind_keys', 'bind_events', 'toggle_keys', 'event_loop',
@ -65,29 +66,27 @@ def event_loop():
events.alive = False events.alive = False
class Actions(object): class Actions(object):
which = call('which', 'which')
def __getattr__(self, name): def __getattr__(self, name):
if name.startswith('_') or name.endswith('_'): if name.startswith('_') or name.endswith('_'):
raise AttributeError() raise AttributeError()
if hasattr(self, name + '_'): if hasattr(self, name + '_'):
return getattr(self, name + '_') return getattr(self, name + '_')
def action(args=''): def action(args=''):
cmd = call(self.which, name, cmd = pygmi.find_script(name)
env=dict(os.environ, PATH=':'.join(confpath))) if cmd:
call(shell, '-c', '$* %s' % args, '--', cmd, call(pygmi.shell, '-c', '$* %s' % args, '--', cmd,
background=True) background=True)
return action return action
def _call(self, args): def _call(self, args):
a = args.split(' ') a = args.split(' ', 1)
if a: if a:
getattr(self, a[0])(*a[1:]) getattr(self, a[0])(*a[1:])
@property @property
def _choices(self): def _choices(self):
return sorted( return sorted(
program_list(confpath) + program_list(pygmi.confpath) +
[re.sub('_$', '', k) for k in dir(self) [re.sub('_$', '', k) for k in dir(self)
if not re.match('^_', k) and callable(getattr(self, k))]) if not re.match('^_', k) and callable(getattr(self, k))])

View File

@ -344,14 +344,17 @@ class Button(object):
if colors or label: if colors or label:
f.write(self.getval(colors, label)) f.write(self.getval(colors, label))
def remove(self): def remove(self):
client.remove(self.path) try:
client.remove(self.path)
except Exception:
pass
def getval(self, colors=None, label=None): def getval(self, colors=None, label=None):
if colors is None: if colors is None:
colors = self.colors colors = self.colors
if label is None: if label is None:
label = self.label label = self.label
return ' '.join([Color(c).hex for c in colors] + [label]) return ' '.join([Color(c).hex for c in colors] + [str(label)])
colors = property( colors = property(
lambda self: tuple(map(Color, client.read(self.path).split(' ')[:3])), lambda self: tuple(map(Color, client.read(self.path).split(' ')[:3])),
@ -372,6 +375,13 @@ class Colors(object):
vals = foreground, background, border vals = foreground, background, border
self.vals = tuple(map(Color, vals)) self.vals = tuple(map(Color, vals))
def __iter__(self):
return iter(self.vals)
def __list__(self):
return list(self.vals)
def __tuple__(self):
return self.vals
@classmethod @classmethod
def from_string(cls, val): def from_string(cls, val):
return cls(*val.split(' ')) return cls(*val.split(' '))
@ -484,8 +494,8 @@ class Rules(collections.MutableMapping):
class wmii(Ctl): class wmii(Ctl):
ctl_path = '/ctl' ctl_path = '/ctl'
ctl_types = { ctl_types = {
'normcolors': (Colors.from_string, lambda c: str(Colors(c))), 'normcolors': (Colors.from_string, lambda c: str(Colors(*c))),
'focuscolors': (Colors.from_string, lambda c: str(Colors(c))), 'focuscolors': (Colors.from_string, lambda c: str(Colors(*c))),
'border': (int, str), 'border': (int, str),
} }

View File

@ -38,7 +38,7 @@ class Monitor(object):
interval = 1.0 interval = 1.0
def __init__(self, name=None, interval=None, side=None, def __init__(self, name=None, interval=None, side=None,
action=None): action=None, colors=None, label=None):
if side: if side:
self.side = side self.side = side
if name: if name:
@ -48,13 +48,15 @@ class Monitor(object):
if action: if action:
self.action = action self.action = action
self.button = Button(self.side, self.name) self.timer = None
self.button = Button(self.side, self.name, colors, label)
self.tick() self.tick()
def tick(self): def tick(self):
from pygmi import events from pygmi import events
if not events.alive: mon = monitors.get(self.name, None)
if client: if self.timer and not (events.alive and mon is self):
if client and (not mon or mon is self):
self.button.remove() self.button.remove()
return return
if self.active: if self.active:

View File

@ -3,6 +3,7 @@ import os
import re import re
import sys import sys
import pygmi
from pygmi import * from pygmi import *
from pygmi import events from pygmi import events
@ -24,18 +25,18 @@ noticebar=('right', '!notice')
background = '#333333' background = '#333333'
floatbackground='#222222' floatbackground='#222222'
wmii.font = 'drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*' wmii['font'] = 'drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*'
wmii.normcolors = '#000000', '#c1c48b', '#81654f' wmii['normcolors'] = '#000000', '#c1c48b', '#81654f'
wmii.focuscolors = '#000000', '#81654f', '#000000' wmii['focuscolors'] = '#000000', '#81654f', '#000000'
wmii.grabmod = events.keydefs['mod'] wmii['grabmod'] = events.keydefs['mod']
wmii.border = 2 wmii['border'] = 2
def setbackground(color): def setbackground(color):
call('xsetroot', '-solid', color) call('xsetroot', '-solid', color)
setbackground(background) setbackground(background)
terminal = 'wmiir', 'setsid', 'xterm' terminal = 'wmiir', 'setsid', 'xterm'
shell = os.environ.get('SHELL', 'sh') pygmi.shell = os.environ.get('SHELL', 'sh')
@defmonitor @defmonitor
def load(): def load():
@ -64,10 +65,6 @@ def unresponsive_client(client):
# End Configuration # End Configuration
confpath = os.environ['WMII_CONFPATH'].split(':')
events.confpath = confpath
events.shell = shell
client.write('/event', 'Start wmiirc') client.write('/event', 'Start wmiirc')
tags = Tags() tags = Tags()
@ -112,7 +109,7 @@ class Actions(events.Actions):
program_menu = Menu(histfile='%s/history.prog' % confpath[0], nhist=5000, program_menu = Menu(histfile='%s/history.prog' % confpath[0], nhist=5000,
action=curry(call, 'wmiir', 'setsid', action=curry(call, 'wmiir', 'setsid',
shell, '-c', background=True)) pygmi.shell, '-c', background=True))
action_menu = Menu(histfile='%s/history.action' % confpath[0], nhist=500, action_menu = Menu(histfile='%s/history.action' % confpath[0], nhist=500,
choices=lambda: Actions._choices, choices=lambda: Actions._choices,
action=Actions._call) action=Actions._call)
@ -200,8 +197,7 @@ map(bind_num, range(0, 10))
Actions.rehash() Actions.rehash()
# Misc Setup execfile(pygmi.find_script('wmiirc.local.py') or '/dev/null')
#progs_file=`{namespace}^/proglist.$pid
event_loop() event_loop()