boartty/gertty/view/mouse_scroll_decorator.py
Jan Kundrát 2028f8f947 Add mouse wheel scrolling
This is implemented by a callout to the widget's existing handler for
key_up and key_down events, and letting the key_* event propagate into
an appropriate place where it's handled as the user's input. Reusing
that handler makes it possible to work in a generic manner, so the code
has no builtin knowledge of the type or layout of the class it's
operating on. The same code is used for project listing, change listing,
single change history view and a diff view as well.

Change-Id: I14600f9dbdf1c066cf5f497f9afcf4e213f03257
2015-03-16 19:30:18 +01:00

34 lines
1.2 KiB
Python

# coding=utf8
#
# Copyright 2014 Jan Kundrát <jkt@kde.org>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
def mouse_event_scrolling(class_type):
def mouse_event_scrolling(self, size, event, button, col, row, focus):
if event == 'mouse press':
if button == 4:
self.keypress(size, 'up')
return True
if button == 5:
self.keypress(size, 'down')
return True
return super(class_type, self).mouse_event(size, event, button, col,
row, focus)
return mouse_event_scrolling
def ScrollByWheel(original_class):
original_class.mouse_event = mouse_event_scrolling(original_class)
return original_class