[hackers] [wmii] Make a better attempt to keep up with color scheme changes in python wmiirc without extra roundtrips. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Wed, 21 Oct 2009 04:15:59 +0000 (UTC)

changeset: 2559:098e81d3fa26
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed Oct 21 00:03:59 2009 -0400
files: alternative_wmiircs/python/pygmi/fs.py alternative_wmiircs/python/pygmi/monitor.py alternative_wmiircs/python/wmiirc.py
description:
Make a better attempt to keep up with color scheme changes in python wmiirc without extra roundtrips.

diff -r 36bc6d4ac065 -r 098e81d3fa26 alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Tue Oct 20 01:40:59 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Wed Oct 21 00:03:59 2009 -0400
@@ -36,7 +36,7 @@
     ctl_hasid = False
 
     def __init__(self):
- pass
+ self.cache = {}
 
     def ctl(self, *args):
         """
@@ -56,6 +56,7 @@
         return key in self.keys()
     def __setitem__(self, key, val):
         assert '\n' not in key
+ self.cache[key] = val
         if key in self.ctl_types:
             val = self.ctl_types[key][1](val)
         self.ctl(key, val)
@@ -610,8 +611,8 @@
         self.ignore = set()
         self.tags = {}
         self.sel = None
- self.normcol = normcol or wmii['normcolors']
- self.focuscol = focuscol or wmii['focuscolors']
+ self.normcol = normcol
+ self.focuscol = focuscol
         self.lastselect = datetime.now()
         for t in wmii.tags:
             self.add(t.id)
@@ -626,15 +627,15 @@
 
     def add(self, tag):
         self.tags[tag] = Tag(tag)
- self.tags[tag].button = Button('left', tag, self.normcol, tag)
+ self.tags[tag].button = Button('left', tag, self.normcol or wmii.cache['normcolors'], tag)
     def delete(self, tag):
         self.tags.pop(tag).button.remove()
 
     def focus(self, tag):
         self.sel = self.tags[tag]
- self.sel.button.colors = self.focuscol
+ self.sel.button.colors = self.focuscol or wmii.cache['focuscolors']
     def unfocus(self, tag):
- self.tags[tag].button.colors = self.normcol
+ self.tags[tag].button.colors = self.normcol or wmii.cache['normcolors']
 
     def set_urgent(self, tag, urgent=True):
         self.tags[tag].button.label = urgent and '*' + tag or tag
diff -r 36bc6d4ac065 -r 098e81d3fa26 alternative_wmiircs/python/pygmi/monitor.py
--- a/alternative_wmiircs/python/pygmi/monitor.py Tue Oct 20 01:40:59 2009 -0400
+++ b/alternative_wmiircs/python/pygmi/monitor.py Wed Oct 21 00:03:59 2009 -0400
@@ -57,8 +57,8 @@
         Initializes the new monitor. For parameter values, see the
         corresponding property values in the class's docstring.
 
- Param color: The initial colors for the monitor.
- Param label: The initial label for the monitor.
+ Param colors: The initial colors for the monitor.
+ Param label: The initial label for the monitor.
         """
         if side:
             self.side = side
diff -r 36bc6d4ac065 -r 098e81d3fa26 alternative_wmiircs/python/wmiirc.py
--- a/alternative_wmiircs/python/wmiirc.py Tue Oct 20 01:40:59 2009 -0400
+++ b/alternative_wmiircs/python/wmiirc.py Wed Oct 21 00:03:59 2009 -0400
@@ -4,7 +4,7 @@
 import re
 import sys
 import traceback
-from threading import Thread
+from threading import Thread, Timer
 
 import pygmi
 from pygmi import *
@@ -50,10 +50,10 @@
 
 @defmonitor
 def load(self):
- return re.sub(r'^.*: ', '', call('uptime')).replace(', ', ' ')
+ return wmii.cache['normcolors'], re.sub(r'^.*: ', '', call('uptime')).replace(', ', ' ')
 @defmonitor
 def time(self):
- return datetime.datetime.now().strftime('%c')
+ return wmii.cache['focuscolors'], datetime.datetime.now().strftime('%c')
 
 wmii.colrules = (
     ('gimp', '17+83+41'),
@@ -143,11 +143,12 @@
 
 class Notice(Button):
     def __init__(self):
- super(Notice, self).__init__(*noticebar, colors=wmii['normcolors'])
+ super(Notice, self).__init__(*noticebar, colors=wmii.cache['normcolors'])
         self.timer = None
+ self.show(' ')
 
     def tick(self):
- self.label = ' '
+ self.create(wmii.cache['normcolors'], ' ')
 
     def write(self, notice):
         client.awrite('/event', 'Notice %s' % notice.replace('\n', ' '))
@@ -155,8 +156,7 @@
     def show(self, notice):
         if self.timer:
             self.timer.cancel()
- self.label = notice
- from threading import Timer
+ self.create(wmii.cache['normcolors'], notice)
         self.timer = Timer(noticetimeout, self.tick)
         self.timer.start()
 notice = Notice()
@@ -294,14 +294,15 @@
 
 Actions.rehash()
 
-dirs = filter(curry(os.access, _, os.R_OK),
- ('%s/plugins' % dir for dir in confpath))
-files = filter(re.compile(r'\.py$').match,
- reduce(operator.add, map(os.listdir, dirs), []))
-for f in ['wmiirc_local'] + ['plugins.%s' % file[:-3] for file in files]:
- try:
- exec 'import %s' % f
- except Exception, e:
- traceback.print_exc(sys.stdout)
+if not os.environ.get('WMII_NOPLUGINS', ''):
+ dirs = filter(curry(os.access, _, os.R_OK),
+ ('%s/plugins' % dir for dir in confpath))
+ files = filter(re.compile(r'\.py$').match,
+ reduce(operator.add, map(os.listdir, dirs), []))
+ for f in ['wmiirc_local'] + ['plugins.%s' % file[:-3] for file in files]:
+ try:
+ exec 'import %s' % f
+ except Exception, e:
+ traceback.print_exc(sys.stdout)
 
 # vim:se sts=4 sw=4 et:
Received on Wed Oct 21 2009 - 04:15:59 UTC

This archive was generated by hypermail 2.2.0 : Wed Oct 21 2009 - 04:24:06 UTC