Support "mouse over" groups
Add a type factory func which returns mixin-able types for creating mutex highlight-able groups of widgets.kivy_mainline_and_py3.8
parent
fd94a24d84
commit
eee19048f0
|
@ -1,15 +1,16 @@
|
||||||
"""Hoverable Behaviour (changing when the mouse is on the widget by O. Poyen.
|
"""Mouse over behaviour.
|
||||||
License: LGPL
|
|
||||||
|
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.properties import BooleanProperty, ObjectProperty
|
||||||
from kivy.core.window import Window
|
from kivy.core.window import Window
|
||||||
|
|
||||||
|
|
||||||
class HoverBehavior(object):
|
class MouseOverBehavior(object):
|
||||||
"""Hover behavior.
|
"""Mouse over behavior.
|
||||||
|
|
||||||
:Events:
|
:Events:
|
||||||
`on_enter`
|
`on_enter`
|
||||||
|
@ -28,8 +29,8 @@ class HoverBehavior(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.register_event_type('on_enter')
|
self.register_event_type('on_enter')
|
||||||
self.register_event_type('on_leave')
|
self.register_event_type('on_leave')
|
||||||
HoverBehavior._widgets.append(self)
|
MouseOverBehavior._widgets.append(self)
|
||||||
super(HoverBehavior, self).__init__(**kwargs)
|
super(MouseOverBehavior, self).__init__(**kwargs)
|
||||||
Window.bind(mouse_pos=self.on_mouse_pos)
|
Window.bind(mouse_pos=self.on_mouse_pos)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -69,3 +70,15 @@ class HoverBehavior(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def on_leave(cls):
|
def on_leave(cls):
|
||||||
pass
|
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,),
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
|
@ -23,8 +23,10 @@ from async_generator import aclosing
|
||||||
|
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .pager import PagerView
|
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')
|
log = get_logger('monitor')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue