mirror of
https://github.com/0intro/wmii
synced 2024-11-22 05:42:05 +03:00
Cleanup. Add wmiirc.local.py.
This commit is contained in:
parent
9ff6791633
commit
120f5a34a3
@ -35,6 +35,14 @@ def curry(func, *args, **kwargs):
|
||||
curried.__name__ = func.__name__ + '__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.events import *
|
||||
from pygmi.fs import *
|
||||
@ -42,6 +50,8 @@ from pygmi.menu import *
|
||||
from pygmi.monitor import *
|
||||
|
||||
__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:
|
||||
|
@ -3,6 +3,7 @@ import re
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import pygmi
|
||||
from pygmi import monitor, client, call, program_list
|
||||
|
||||
__all__ = ('bind_keys', 'bind_events', 'toggle_keys', 'event_loop',
|
||||
@ -65,29 +66,27 @@ def event_loop():
|
||||
events.alive = False
|
||||
|
||||
class Actions(object):
|
||||
which = call('which', 'which')
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith('_') or name.endswith('_'):
|
||||
raise AttributeError()
|
||||
if hasattr(self, name + '_'):
|
||||
return getattr(self, name + '_')
|
||||
def action(args=''):
|
||||
cmd = call(self.which, name,
|
||||
env=dict(os.environ, PATH=':'.join(confpath)))
|
||||
call(shell, '-c', '$* %s' % args, '--', cmd,
|
||||
background=True)
|
||||
cmd = pygmi.find_script(name)
|
||||
if cmd:
|
||||
call(pygmi.shell, '-c', '$* %s' % args, '--', cmd,
|
||||
background=True)
|
||||
return action
|
||||
|
||||
def _call(self, args):
|
||||
a = args.split(' ')
|
||||
a = args.split(' ', 1)
|
||||
if a:
|
||||
getattr(self, a[0])(*a[1:])
|
||||
|
||||
@property
|
||||
def _choices(self):
|
||||
return sorted(
|
||||
program_list(confpath) +
|
||||
program_list(pygmi.confpath) +
|
||||
[re.sub('_$', '', k) for k in dir(self)
|
||||
if not re.match('^_', k) and callable(getattr(self, k))])
|
||||
|
||||
|
@ -344,14 +344,17 @@ class Button(object):
|
||||
if colors or label:
|
||||
f.write(self.getval(colors, label))
|
||||
def remove(self):
|
||||
client.remove(self.path)
|
||||
try:
|
||||
client.remove(self.path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def getval(self, colors=None, label=None):
|
||||
if colors is None:
|
||||
colors = self.colors
|
||||
if label is None:
|
||||
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(
|
||||
lambda self: tuple(map(Color, client.read(self.path).split(' ')[:3])),
|
||||
@ -372,6 +375,13 @@ class Colors(object):
|
||||
vals = foreground, background, border
|
||||
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
|
||||
def from_string(cls, val):
|
||||
return cls(*val.split(' '))
|
||||
@ -484,8 +494,8 @@ class Rules(collections.MutableMapping):
|
||||
class wmii(Ctl):
|
||||
ctl_path = '/ctl'
|
||||
ctl_types = {
|
||||
'normcolors': (Colors.from_string, lambda c: str(Colors(c))),
|
||||
'focuscolors': (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))),
|
||||
'border': (int, str),
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Monitor(object):
|
||||
interval = 1.0
|
||||
|
||||
def __init__(self, name=None, interval=None, side=None,
|
||||
action=None):
|
||||
action=None, colors=None, label=None):
|
||||
if side:
|
||||
self.side = side
|
||||
if name:
|
||||
@ -48,13 +48,15 @@ class Monitor(object):
|
||||
if 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()
|
||||
|
||||
def tick(self):
|
||||
from pygmi import events
|
||||
if not events.alive:
|
||||
if client:
|
||||
mon = monitors.get(self.name, None)
|
||||
if self.timer and not (events.alive and mon is self):
|
||||
if client and (not mon or mon is self):
|
||||
self.button.remove()
|
||||
return
|
||||
if self.active:
|
||||
|
@ -3,6 +3,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
import pygmi
|
||||
from pygmi import *
|
||||
from pygmi import events
|
||||
|
||||
@ -24,18 +25,18 @@ noticebar=('right', '!notice')
|
||||
background = '#333333'
|
||||
floatbackground='#222222'
|
||||
|
||||
wmii.font = 'drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*'
|
||||
wmii.normcolors = '#000000', '#c1c48b', '#81654f'
|
||||
wmii.focuscolors = '#000000', '#81654f', '#000000'
|
||||
wmii.grabmod = events.keydefs['mod']
|
||||
wmii.border = 2
|
||||
wmii['font'] = 'drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*'
|
||||
wmii['normcolors'] = '#000000', '#c1c48b', '#81654f'
|
||||
wmii['focuscolors'] = '#000000', '#81654f', '#000000'
|
||||
wmii['grabmod'] = events.keydefs['mod']
|
||||
wmii['border'] = 2
|
||||
|
||||
def setbackground(color):
|
||||
call('xsetroot', '-solid', color)
|
||||
setbackground(background)
|
||||
|
||||
terminal = 'wmiir', 'setsid', 'xterm'
|
||||
shell = os.environ.get('SHELL', 'sh')
|
||||
pygmi.shell = os.environ.get('SHELL', 'sh')
|
||||
|
||||
@defmonitor
|
||||
def load():
|
||||
@ -64,10 +65,6 @@ def unresponsive_client(client):
|
||||
|
||||
# End Configuration
|
||||
|
||||
confpath = os.environ['WMII_CONFPATH'].split(':')
|
||||
events.confpath = confpath
|
||||
events.shell = shell
|
||||
|
||||
client.write('/event', 'Start wmiirc')
|
||||
|
||||
tags = Tags()
|
||||
@ -112,7 +109,7 @@ class Actions(events.Actions):
|
||||
|
||||
program_menu = Menu(histfile='%s/history.prog' % confpath[0], nhist=5000,
|
||||
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,
|
||||
choices=lambda: Actions._choices,
|
||||
action=Actions._call)
|
||||
@ -200,8 +197,7 @@ map(bind_num, range(0, 10))
|
||||
|
||||
Actions.rehash()
|
||||
|
||||
# Misc Setup
|
||||
#progs_file=`{namespace}^/proglist.$pid
|
||||
execfile(pygmi.find_script('wmiirc.local.py') or '/dev/null')
|
||||
|
||||
event_loop()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user