From bd72122b9554cd87d40820bc78f7cb8d9f83e0b3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 7 Jul 2011 16:02:09 -0400 Subject: [PATCH] handle conf params more robustly --- Window.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Window.py b/Window.py index 02d3b21..011f651 100755 --- a/Window.py +++ b/Window.py @@ -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