From eee19048f0f58dd9a91a663c5893f9354beea9ab Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 1 Dec 2018 19:01:36 -0500 Subject: [PATCH] Support "mouse over" groups Add a type factory func which returns mixin-able types for creating mutex highlight-able groups of widgets. --- piker/ui/kivy/mouse_over.py | 27 ++++++++++++++++++++------- piker/ui/monitor.py | 4 +++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/piker/ui/kivy/mouse_over.py b/piker/ui/kivy/mouse_over.py index fda4452f..88d0b108 100644 --- a/piker/ui/kivy/mouse_over.py +++ b/piker/ui/kivy/mouse_over.py @@ -1,15 +1,16 @@ -"""Hoverable Behaviour (changing when the mouse is on the widget by O. Poyen. -License: LGPL +"""Mouse over behaviour. + +Based on initial LGPL work by O. Poyen. here: +https://gist.github.com/opqopq/15c707dc4cffc2b6455f """ -__author__ = 'Olivier Poyen' from kivy.properties import BooleanProperty, ObjectProperty from kivy.core.window import Window -class HoverBehavior(object): - """Hover behavior. +class MouseOverBehavior(object): + """Mouse over behavior. :Events: `on_enter` @@ -28,8 +29,8 @@ class HoverBehavior(object): def __init__(self, **kwargs): self.register_event_type('on_enter') self.register_event_type('on_leave') - HoverBehavior._widgets.append(self) - super(HoverBehavior, self).__init__(**kwargs) + MouseOverBehavior._widgets.append(self) + super(MouseOverBehavior, self).__init__(**kwargs) Window.bind(mouse_pos=self.on_mouse_pos) @classmethod @@ -69,3 +70,15 @@ class HoverBehavior(object): @classmethod def on_leave(cls): pass + + +def new_mouse_over_group(): + """Return a new *mouse over group*, a class that can be mixed + in to a group of widgets which can be mutex highlighted based + on the mouse position. + """ + return type( + 'MouseOverBehavior', + (MouseOverBehavior,), + {}, + ) diff --git a/piker/ui/monitor.py b/piker/ui/monitor.py index ed478aa9..d9568135 100644 --- a/piker/ui/monitor.py +++ b/piker/ui/monitor.py @@ -23,8 +23,10 @@ from async_generator import aclosing from ..log import get_logger from .pager import PagerView -from .kivy.mouse_over import HoverBehavior +from .kivy.mouse_over import new_mouse_over_group + +HoverBehavior = new_mouse_over_group() log = get_logger('monitor')