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 gtk
import gobject import gobject
import imaplib import imaplib
import math import math
from datetime import datetime, timedelta from datetime import datetime, timedelta
from subprocess import *
class Window(object): class Window(object):
def __init__(self, title, conf): def __init__(self, title, conf):
@ -29,6 +31,14 @@ class Window(object):
self.conf['flash_rate'] = 3000 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
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.font_sz = int(1024 * self.conf['font_size'])
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']))
@ -138,9 +148,18 @@ class Window(object):
return False return False
def button_release(self, widget, event): def button_release(self, widget, event):
if event.button == 2: try:
self.disconnect() btn_name = {1: 'left', 2: 'middle', 3: 'right'}[event.button]
self.connect() action = self.conf['mouse'][btn_name]
elif event.button == 3: m = re.match(r'\s*cmd:\s*(.*)', action)
self.destroy_event() 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 return True