[hackers] [wmii] Cleanup. Add wmiirc.local.py. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Mon, 18 May 2009 01:23:59 +0000 (UTC)

changeset: 2456:d1a33e9207d0
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sun May 17 21:23:57 2009 -0400
files: alternative_wmiircs/python/pygmi/__init__.py alternative_wmiircs/python/pygmi/events.py alternative_wmiircs/python/pygmi/fs.py alternative_wmiircs/python/pygmi/monitor.py alternative_wmiircs/python/wmiirc
description:
Cleanup. Add wmiirc.local.py.

diff -r c6e4f5df5678 -r d1a33e9207d0 alternative_wmiircs/python/pygmi/__init__.py
--- a/alternative_wmiircs/python/pygmi/__init__.py Sun May 17 14:15:08 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/__init__.py Sun May 17 21:23:57 2009 -0400
@@ -35,6 +35,14 @@
     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.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:
diff -r c6e4f5df5678 -r d1a33e9207d0 alternative_wmiircs/python/pygmi/events.py
--- a/alternative_wmiircs/python/pygmi/events.py Sun May 17 14:15:08 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/events.py Sun May 17 21:23:57 2009 -0400
@@ -3,6 +3,7 @@
 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 @@
     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))])
 
diff -r c6e4f5df5678 -r d1a33e9207d0 alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Sun May 17 14:15:08 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Sun May 17 21:23:57 2009 -0400
@@ -344,14 +344,17 @@
             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])),
@@ -371,6 +374,13 @@
     def __init__(self, foreground=None, background=None, border=None):
         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):
@@ -484,8 +494,8 @@
 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),
     }
 
diff -r c6e4f5df5678 -r d1a33e9207d0 alternative_wmiircs/python/pygmi/monitor.py
--- a/alternative_wmiircs/python/pygmi/monitor.py Sun May 17 14:15:08 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/monitor.py Sun May 17 21:23:57 2009 -0400
@@ -38,7 +38,7 @@
     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 @@
         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:
diff -r c6e4f5df5678 -r d1a33e9207d0 alternative_wmiircs/python/wmiirc
--- a/alternative_wmiircs/python/wmiirc Sun May 17 14:15:08 2009 -0400
+++ b/alternative_wmiircs/python/wmiirc Sun May 17 21:23:57 2009 -0400
@@ -3,6 +3,7 @@
 import re
 import sys
 
+import pygmi
 from pygmi import *
 from pygmi import events
 
@@ -24,18 +25,18 @@
 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():
@@ -63,10 +64,6 @@
         client.slay()
 
 # End Configuration
-
-confpath = os.environ['WMII_CONFPATH'].split(':')
-events.confpath = confpath
-events.shell = shell
 
 client.write('/event', 'Start wmiirc')
 
@@ -112,7 +109,7 @@
 
 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 @@
 
 Actions.rehash()
 
-# Misc Setup
-#progs_file=`{namespace}^/proglist.$pid
+execfile(pygmi.find_script('wmiirc.local.py') or '/dev/null')
 
 event_loop()
 
Received on Mon May 18 2009 - 01:23:59 UTC

This archive was generated by hypermail 2.2.0 : Mon May 18 2009 - 01:36:04 UTC