make mouse click actions configurable

This commit is contained in:
Josh Holtrop 2011-07-19 11:08:48 -04:00
parent e8918895f4
commit 5c714a69c4

View File

@ -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