| 1 |
# vim:fileencoding=utf-8 |
| 2 |
# License: GPL v3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net> |
| 3 |
from __python__ import bound_methods, hash_literals |
| 4 |
|
| 5 |
from gettext import gettext as _ |
| 6 |
|
| 7 |
from read_book.settings import opts |
| 8 |
from read_book.touch import GESTURE |
| 9 |
|
| 10 |
|
| 11 |
def get_action_descriptions(): |
| 12 |
if not get_action_descriptions.ans: |
| 13 |
get_action_descriptions.ans = { |
| 14 |
'prev_page': { |
| 15 |
'short': _('Previous page'), |
| 16 |
'long': _('Scroll to the previous page, if more than one page is displayed on the screen only a single page is scrolled') |
| 17 |
}, |
| 18 |
'next_page': { |
| 19 |
'short': _('Next page'), |
| 20 |
'long': _('Scroll to the next page, if more than one page is displayed on the screen only a single page is scrolled') |
| 21 |
}, |
| 22 |
'prev_screen': { |
| 23 |
'short': _('Previous screen'), |
| 24 |
'long': _('Scroll to the previous screen, if more than one page is displayed on the screen all pages are scrolled') |
| 25 |
}, |
| 26 |
'next_screen': { |
| 27 |
'short': _('Next screen'), |
| 28 |
'long': _('Scroll to the next screen, if more than one page is displayed on the screen all pages are scrolled') |
| 29 |
}, |
| 30 |
'show_chrome': { |
| 31 |
'short': _('Show controls'), |
| 32 |
'long': _('Show the controls for the viewer including Preferences, Go to, etc.') |
| 33 |
}, |
| 34 |
'highlight_or_inspect': { |
| 35 |
'short': _('Highlight or inspect'), |
| 36 |
'long': _('Highlight the word under the tap point or view the image under the tap or select the highlight under the tap') |
| 37 |
}, |
| 38 |
'decrease_font_size': { |
| 39 |
'short': _('Make text smaller'), |
| 40 |
'long': _('Decrease the font size') |
| 41 |
}, |
| 42 |
'increase_font_size': { |
| 43 |
'short': _('Make text bigger'), |
| 44 |
'long': _('Increase the font size') |
| 45 |
}, |
| 46 |
'next_section': { |
| 47 |
'short': _('Next chapter'), |
| 48 |
'long': _('Scroll to the start of the next section or chapter in the book') |
| 49 |
}, |
| 50 |
'prev_section': { |
| 51 |
'short': _('Previous chapter'), |
| 52 |
'long': _('Scroll to the start of the previous section or chapter in the book') |
| 53 |
}, |
| 54 |
'pan': { |
| 55 |
'short': _('Pan the contents'), |
| 56 |
'long': _('Scroll the screen contents in tandem with finger movement') |
| 57 |
}, |
| 58 |
'animated_scroll': { |
| 59 |
'short': _('Flick scroll'), |
| 60 |
'long': _('Scroll the screen contents with momentum based on how fast you flick your finger') |
| 61 |
}, |
| 62 |
'none': { |
| 63 |
'short': _('No action'), |
| 64 |
'long': _('Ignore this gesture performing no action in response to it') |
| 65 |
}, |
| 66 |
} |
| 67 |
return get_action_descriptions.ans |
| 68 |
|
| 69 |
only_flow_swipe_mode_actions = {'pan': True, 'animated_scroll': True} |
| 70 |
only_tap_actions = {'highlight_or_inspect': True} |
| 71 |
default_actions_for_gesture = { |
| 72 |
'common': { |
| 73 |
GESTURE.back_zone_tap: 'prev_page', |
| 74 |
GESTURE.forward_zone_tap: 'next_page', |
| 75 |
GESTURE.control_zone_tap: 'show_chrome', |
| 76 |
GESTURE.long_tap: 'highlight_or_inspect', |
| 77 |
GESTURE.two_finger_tap: 'show_chrome', |
| 78 |
GESTURE.pinch_in: 'decrease_font_size', |
| 79 |
GESTURE.pinch_out: 'increase_font_size', |
| 80 |
}, |
| 81 |
'flow_mode': { |
| 82 |
GESTURE.swipe_inline_backward_in_progress: 'pan', |
| 83 |
GESTURE.swipe_inline_forward_in_progress: 'pan', |
| 84 |
GESTURE.swipe_block_backward_in_progress: 'pan', |
| 85 |
GESTURE.swipe_block_forward_in_progress: 'pan', |
| 86 |
GESTURE.flick_block_forward: 'animated_scroll', |
| 87 |
GESTURE.flick_block_backward: 'animated_scroll', |
| 88 |
GESTURE.flick_inline_forward: 'animated_scroll', |
| 89 |
GESTURE.flick_inline_backward: 'animated_scroll', |
| 90 |
}, |
| 91 |
'paged_mode': { |
| 92 |
GESTURE.flick_block_forward: 'next_section', |
| 93 |
GESTURE.flick_block_backward: 'prev_section', |
| 94 |
GESTURE.flick_inline_forward: 'next_screen', |
| 95 |
GESTURE.flick_inline_backward: 'prev_screen', |
| 96 |
GESTURE.swipe_inline_forward_hold: 'next_screen', |
| 97 |
GESTURE.swipe_inline_backward_hold: 'prev_screen', |
| 98 |
}, |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
def current_action_for_gesture_type(overrides, gesture_type, in_flow_mode): |
| 103 |
mode = 'flow_mode' if in_flow_mode else 'paged_mode' |
| 104 |
mode_overrides = overrides[mode] or {} |
| 105 |
if mode_overrides[gesture_type]: |
| 106 |
return mode_overrides[gesture_type] |
| 107 |
common_overrides = overrides.common or {} |
| 108 |
if common_overrides[gesture_type]: |
| 109 |
return common_overrides[gesture_type] |
| 110 |
if default_actions_for_gesture[mode][gesture_type]: |
| 111 |
return default_actions_for_gesture[mode][gesture_type] |
| 112 |
return default_actions_for_gesture.common[gesture_type] or 'none' |
| 113 |
|
| 114 |
|
| 115 |
def action_for_gesture(gesture, in_flow_mode): |
| 116 |
return current_action_for_gesture_type(opts.gesture_overrides, gesture.type, in_flow_mode) |
| 117 |
|
| 118 |
|
| 119 |
def allowed_actions_for_tap(): |
| 120 |
return [ac for ac in Object.keys(get_action_descriptions()) if not only_flow_swipe_mode_actions[ac]] |
| 121 |
|
| 122 |
|
| 123 |
def allowed_actions_for_paged_mode_swipe(): |
| 124 |
return [ac for ac in Object.keys(get_action_descriptions()) if not only_flow_swipe_mode_actions[ac] and not only_tap_actions[ac]] |
| 125 |
allowed_actions_for_two_fingers = allowed_actions_for_paged_mode_swipe |
| 126 |
|
| 127 |
|
| 128 |
def allowed_actions_for_flow_mode_flick(): |
| 129 |
return [ac for ac in Object.keys(get_action_descriptions()) if not only_tap_actions[ac]] |
| 130 |
|
| 131 |
|
| 132 |
def allowed_actions_for_flow_mode_drag(): |
| 133 |
return ['pan', 'none'] |