handle conf params more robustly

This commit is contained in:
Josh Holtrop 2011-07-07 16:02:09 -04:00
parent bb6896e0ba
commit bd72122b95

View File

@ -12,8 +12,7 @@ class Window(object):
self.connection = None
self.fgcolor = ''.join(map(lambda x: '%02x' % int(0xFF * x),
self.conf['fgcolor']))
self.font_sz = 1024 * self.conf['font_size']
self.flash_rate = 0
self.font_sz = int(1024 * self.conf['font_size'])
if not 'width' in self.conf:
self.conf['width'] = 32
@ -29,8 +28,8 @@ class Window(object):
self.conf['bgcolor'] = (1.0, 0.5, 0.0)
if not 'bgcolor2' in self.conf:
self.conf['bgcolor2'] = (1.0, 1.0, 1.0)
if 'flash_rate' in self.conf:
self.flash_rate = self.conf['flash_rate']
if not 'flash_rate' in self.conf:
self.conf['flash_rate'] = 3000
if not 'font_size' in self.conf:
self.conf['font_size'] = 18
sticky = True
@ -97,7 +96,9 @@ class Window(object):
msgs = self.connection.search(None, 'UnSeen')[1][0].split()
old_count = self.count
self.count = len(msgs)
if self.flash_rate > 0 and old_count == 0 and self.count > 0:
if (self.conf['flash_rate'] > 0
and old_count == 0
and self.count > 0):
self.flash_start_dt = datetime.now()
gobject.timeout_add(100, self.do_flash)
except:
@ -118,7 +119,7 @@ class Window(object):
if self.count > 0:
delta = datetime.now() - self.flash_start_dt
delta_msec = delta.seconds * 1000 + delta.microseconds / 1000
period = delta_msec / float(self.flash_rate)
period = delta_msec / float(self.conf['flash_rate'])
mix = (math.sin(math.pi * 2 * period) + 1.0) / 2.0
else:
mix = 0