Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

adding hover over enhancement #172

Merged
merged 4 commits into from Jan 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 62 additions & 3 deletions designer/uix/designer_action_items.py
@@ -1,6 +1,8 @@
from kivy.properties import ObjectProperty, StringProperty, BooleanProperty
from kivy.uix.actionbar import ActionGroup, ActionPrevious, ActionButton, \
ActionItem
from kivy.core.window import Window
import weakref
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.floatlayout import FloatLayout
from designer.uix.contextual import ContextSubMenu
Expand Down Expand Up @@ -81,13 +83,70 @@ class DesignerActionProfileCheck(ActionCheckButton):

config_key = StringProperty('')
'''Dict key to the profile config_parser
:data:`config_key` is a :class:`~kivy.properties.StringProperty`, default
to ''.
:data:`config_key` is a :class:`~kivy.properties.StringProperty`,
default to ''.
'''


class DesignerActionGroup(ActionGroup):
pass

to_open = BooleanProperty(False)
'''To keep check of whether to open the dropdown list or not.
:attr:`to_open` is a :class:`~kivy.properties.BooleanProperty`,
defaults to False.
'''
hovered = BooleanProperty(False)
'''To keep check of hover over each instance of DesignerActionGroup.
:attr:`hovered` is a :class:`~kivy.properties.BooleanProperty`,
defaults to False.
'''
instances = []
'''List to keep the instances of DesignerActionGroup.
'''

def __init__(self, **kwargs):
super(DesignerActionGroup, self).__init__(**kwargs)
self.__class__.instances.append(weakref.proxy(self))
self.register_event_type('on_enter') # Registering the event
Window.bind(mouse_pos=self.on_mouse_pos)

def on_mouse_pos(self, *args):
try:
pos = args[1]
inside_actionbutton = self.collide_point(*pos)
if self.hovered == inside_actionbutton:
# If mouse is hovering inside the group then return.
return
self.hovered = inside_actionbutton
if inside_actionbutton:
self.dispatch('on_enter')
except:
return

def on_touch_down(self, touch):
'''Used to determine where touch is down and to change values
of to_open.
'''
if self.collide_point(touch.x, touch.y):
DesignerActionGroup.to_open = True
return super(DesignerActionGroup, self).on_touch_down(touch)

if not self.is_open:
DesignerActionGroup.to_open = False

def on_enter(self):
'''Event handler for on_enter event
'''
if not self.disabled:
if all(instance.is_open is False for instance in
DesignerActionGroup.instances):
DesignerActionGroup.to_open = False
for instance in DesignerActionGroup.instances:
if instance.is_open:
instance._dropdown.dismiss()
if DesignerActionGroup.to_open is True:
self.is_open = True
self._toggle_dropdown()


class DesignerSubActionButton(ActionButton):
Expand Down