diff options
author | Igor Kotrasiński <ikk_pl@yahoo.co.uk> | 2013-06-06 22:29:30 +0200 |
---|---|---|
committer | Igor Kotrasiński <ikk_pl@yahoo.co.uk> | 2013-06-06 22:29:30 +0200 |
commit | 7ae22c7455f996d2d29440fc3ea9f80ea5bb3857 (patch) | |
tree | 81f1dcd4dda94c8e1d0929e2a44eab9538a7d087 /urwid | |
parent | 3672372a924e2c08c5de0f16cfa709eacfe0bde9 (diff) | |
download | urwid-7ae22c7455f996d2d29440fc3ea9f80ea5bb3857.tar.gz |
Incorporated support for double and triple clicks into raw and curses displays.
Diffstat (limited to 'urwid')
-rwxr-xr-x | urwid/curses_display.py | 22 | ||||
-rw-r--r-- | urwid/escape.py | 14 | ||||
-rw-r--r-- | urwid/raw_display.py | 29 |
3 files changed, 63 insertions, 2 deletions
diff --git a/urwid/curses_display.py b/urwid/curses_display.py index dba940b..f922159 100755 --- a/urwid/curses_display.py +++ b/urwid/curses_display.py @@ -85,6 +85,10 @@ class Screen(BaseScreen, RealTerminal): | curses.BUTTON2_PRESSED | curses.BUTTON2_RELEASED | curses.BUTTON3_PRESSED | curses.BUTTON3_RELEASED | curses.BUTTON4_PRESSED | curses.BUTTON4_RELEASED + | curses.BUTTON1_DOUBLE_CLICKED | curses.BUTTON1_TRIPLE_CLICKED + | curses.BUTTON2_DOUBLE_CLICKED | curses.BUTTON2_TRIPLE_CLICKED + | curses.BUTTON3_DOUBLE_CLICKED | curses.BUTTON3_TRIPLE_CLICKED + | curses.BUTTON4_DOUBLE_CLICKED | curses.BUTTON4_TRIPLE_CLICKED | curses.BUTTON_SHIFT | curses.BUTTON_ALT | curses.BUTTON_CTRL) @@ -397,6 +401,24 @@ class Screen(BaseScreen, RealTerminal): append_button( 64 + escape.MOUSE_RELEASE_FLAG ) next &= ~ 8 + if bstate & curses.BUTTON1_DOUBLE_CLICKED: + append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + if bstate & curses.BUTTON2_DOUBLE_CLICKED: + append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + if bstate & curses.BUTTON3_DOUBLE_CLICKED: + append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + if bstate & curses.BUTTON4_DOUBLE_CLICKED: + append_button( 64 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + + if bstate & curses.BUTTON1_TRIPLE_CLICKED: + append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + if bstate & curses.BUTTON2_TRIPLE_CLICKED: + append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + if bstate & curses.BUTTON3_TRIPLE_CLICKED: + append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + if bstate & curses.BUTTON4_TRIPLE_CLICKED: + append_button( 64 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + self.last_bstate = next return l diff --git a/urwid/escape.py b/urwid/escape.py index 6df3d86..bf34921 100644 --- a/urwid/escape.py +++ b/urwid/escape.py @@ -180,6 +180,8 @@ class KeyqueueTrie(object): if b & 4: prefix = prefix + "shift " if b & 8: prefix = prefix + "meta " if b & 16: prefix = prefix + "ctrl " + if (b & MOUSE_MULTIPLE_CLICK_MASK)>>9 == 1: prefix = prefix + "double " + if (b & MOUSE_MULTIPLE_CLICK_MASK)>>9 == 2: prefix = prefix + "triple " # 0->1, 1->2, 2->3, 64->4, 65->5 button = ((b&64)/64*3) + (b & 3) + 1 @@ -191,6 +193,8 @@ class KeyqueueTrie(object): action = "release" elif b & MOUSE_DRAG_FLAG: action = "drag" + elif b & MOUSE_MULTIPLE_CLICK_MASK: + action = "click" else: action = "press" @@ -251,6 +255,16 @@ class KeyqueueTrie(object): # and raw_display when we know which button was released. NON-STANDARD MOUSE_RELEASE_FLAG = 2048 +# This 2-bit mask is used to check if the mouse release from curses or gpm +# is a double or triple release. 00 means single click, 01 double, +# 10 triple. NON-STANDARD +MOUSE_MULTIPLE_CLICK_MASK = 1536 + +# This is added to button value at mouse release to differentiate between +# single, double and triple press. Double release adds this times one, +# triple release adds this times two. NON-STANDARD +MOUSE_MULTIPLE_CLICK_FLAG = 512 + # xterm adds this to the button value to signal a mouse drag event MOUSE_DRAG_FLAG = 32 diff --git a/urwid/raw_display.py b/urwid/raw_display.py index 74ec840..5c3e12c 100644 --- a/urwid/raw_display.py +++ b/urwid/raw_display.py @@ -480,7 +480,18 @@ class Screen(BaseScreen, RealTerminal): b |= mod l.extend([ 27, ord('['), ord('M'), b+32, x+32, y+32 ]) - if ev == 20: # press + def determine_button_release( flag ): + if b & 4 and last & 1: + append_button( 0 + flag ) + next |= 1 + if b & 2 and last & 2: + append_button( 1 + flag ) + next |= 2 + if b & 1 and last & 4: + append_button( 2 + flag ) + next |= 4 + + if ev == 20 or ev == 36 or ev == 52: # press if b & 4 and last & 1 == 0: append_button( 0 ) next |= 1 @@ -507,7 +518,21 @@ class Screen(BaseScreen, RealTerminal): if b & 1 and last & 4: append_button( 2 + escape.MOUSE_RELEASE_FLAG ) next &= ~ 4 - + if ev == 40: # double click (release) + if b & 4 and last & 1: + append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + if b & 2 and last & 2: + append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + if b & 1 and last & 4: + append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG ) + elif ev == 52: + if b & 4 and last & 1: + append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + if b & 2 and last & 2: + append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + if b & 1 and last & 4: + append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 ) + self.last_bstate = next return l |