handle conf params more robustly
This commit is contained in:
parent
bb6896e0ba
commit
bd72122b95
13
Window.py
13
Window.py
@ -12,8 +12,7 @@ class Window(object):
|
|||||||
self.connection = None
|
self.connection = None
|
||||||
self.fgcolor = ''.join(map(lambda x: '%02x' % int(0xFF * x),
|
self.fgcolor = ''.join(map(lambda x: '%02x' % int(0xFF * x),
|
||||||
self.conf['fgcolor']))
|
self.conf['fgcolor']))
|
||||||
self.font_sz = 1024 * self.conf['font_size']
|
self.font_sz = int(1024 * self.conf['font_size'])
|
||||||
self.flash_rate = 0
|
|
||||||
|
|
||||||
if not 'width' in self.conf:
|
if not 'width' in self.conf:
|
||||||
self.conf['width'] = 32
|
self.conf['width'] = 32
|
||||||
@ -29,8 +28,8 @@ class Window(object):
|
|||||||
self.conf['bgcolor'] = (1.0, 0.5, 0.0)
|
self.conf['bgcolor'] = (1.0, 0.5, 0.0)
|
||||||
if not 'bgcolor2' in self.conf:
|
if not 'bgcolor2' in self.conf:
|
||||||
self.conf['bgcolor2'] = (1.0, 1.0, 1.0)
|
self.conf['bgcolor2'] = (1.0, 1.0, 1.0)
|
||||||
if 'flash_rate' in self.conf:
|
if not 'flash_rate' in self.conf:
|
||||||
self.flash_rate = self.conf['flash_rate']
|
self.conf['flash_rate'] = 3000
|
||||||
if not 'font_size' in self.conf:
|
if not 'font_size' in self.conf:
|
||||||
self.conf['font_size'] = 18
|
self.conf['font_size'] = 18
|
||||||
sticky = True
|
sticky = True
|
||||||
@ -97,7 +96,9 @@ class Window(object):
|
|||||||
msgs = self.connection.search(None, 'UnSeen')[1][0].split()
|
msgs = self.connection.search(None, 'UnSeen')[1][0].split()
|
||||||
old_count = self.count
|
old_count = self.count
|
||||||
self.count = len(msgs)
|
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()
|
self.flash_start_dt = datetime.now()
|
||||||
gobject.timeout_add(100, self.do_flash)
|
gobject.timeout_add(100, self.do_flash)
|
||||||
except:
|
except:
|
||||||
@ -118,7 +119,7 @@ class Window(object):
|
|||||||
if self.count > 0:
|
if self.count > 0:
|
||||||
delta = datetime.now() - self.flash_start_dt
|
delta = datetime.now() - self.flash_start_dt
|
||||||
delta_msec = delta.seconds * 1000 + delta.microseconds / 1000
|
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
|
mix = (math.sin(math.pi * 2 * period) + 1.0) / 2.0
|
||||||
else:
|
else:
|
||||||
mix = 0
|
mix = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user