diff --git a/Window.py b/Window.py index 6a40599..139b27d 100755 --- a/Window.py +++ b/Window.py @@ -1,9 +1,11 @@ +import re import gtk import gobject import imaplib import math from datetime import datetime, timedelta +from subprocess import * class Window(object): def __init__(self, title, conf): @@ -29,6 +31,14 @@ class Window(object): self.conf['flash_rate'] = 3000 if not 'font_size' in self.conf: self.conf['font_size'] = 18 + if not 'mouse' in self.conf: + self.conf['mouse'] = {} + if not 'left' in self.conf['mouse']: + self.conf['mouse']['left'] = '' + if not 'middle' in self.conf['mouse']: + self.conf['mouse']['middle'] = 'reconnect' + if not 'right' in self.conf['mouse']: + self.conf['mouse']['right'] = 'exit' self.font_sz = int(1024 * self.conf['font_size']) self.fgcolor = ''.join(map(lambda x: '%02x' % int(0xFF * x), self.conf['fgcolor'])) @@ -138,9 +148,18 @@ class Window(object): return False def button_release(self, widget, event): - if event.button == 2: - self.disconnect() - self.connect() - elif event.button == 3: - self.destroy_event() + try: + btn_name = {1: 'left', 2: 'middle', 3: 'right'}[event.button] + action = self.conf['mouse'][btn_name] + m = re.match(r'\s*cmd:\s*(.*)', action) + if m is not None: + cmd = m.group(1) + Popen(cmd, stdout=PIPE) + elif action == 'reconnect': + self.disconnect() + self.connect() + elif action == 'exit': + self.destroy_event() + except KeyError: + return False return True