From 4b51770266ae42c5dd87079ff7c0d6a15d8184ea Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 21 Oct 2009 00:03:59 -0400 Subject: [PATCH] Make a better attempt to keep up with color scheme changes in python wmiirc without extra roundtrips. --- alternative_wmiircs/python/pygmi/fs.py | 13 ++++---- alternative_wmiircs/python/pygmi/monitor.py | 4 +-- alternative_wmiircs/python/wmiirc.py | 33 +++++++++++---------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/alternative_wmiircs/python/pygmi/fs.py b/alternative_wmiircs/python/pygmi/fs.py index c61eef75..877087e1 100644 --- a/alternative_wmiircs/python/pygmi/fs.py +++ b/alternative_wmiircs/python/pygmi/fs.py @@ -36,7 +36,7 @@ class Ctl(object): ctl_hasid = False def __init__(self): - pass + self.cache = {} def ctl(self, *args): """ @@ -56,6 +56,7 @@ class Ctl(object): 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 @@ class Tags(object): 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 @@ class Tags(object): 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 --git a/alternative_wmiircs/python/pygmi/monitor.py b/alternative_wmiircs/python/pygmi/monitor.py index a9d40126..528e9cdf 100644 --- a/alternative_wmiircs/python/pygmi/monitor.py +++ b/alternative_wmiircs/python/pygmi/monitor.py @@ -57,8 +57,8 @@ class Monitor(object): 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 --git a/alternative_wmiircs/python/wmiirc.py b/alternative_wmiircs/python/wmiirc.py index 1a4c2627..1bc65cde 100644 --- a/alternative_wmiircs/python/wmiirc.py +++ b/alternative_wmiircs/python/wmiirc.py @@ -4,7 +4,7 @@ import os import re import sys import traceback -from threading import Thread +from threading import Thread, Timer import pygmi from pygmi import * @@ -50,10 +50,10 @@ pygmi.shell = os.environ.get('SHELL', 'sh') @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 @@ def clickmenu(choices, args): 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 @@ class Notice(Button): 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 @@ addresize('Shift-', 'Nudge', 'nudge') 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: