Skip to content

Added auto dismiss behavior to Bubble, as an option. Used the modal view dismiss() and the cutcopypaste hide() functions as templates. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 44 additions & 7 deletions kivy/uix/bubble.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@

__all__ = ('Bubble', 'BubbleButton', 'BubbleContent')

from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.scatter import Scatter
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.properties import ObjectProperty, StringProperty, OptionProperty, \
ListProperty, BooleanProperty
from kivy.clock import Clock

from kivy.animation import Animation
from kivy.base import EventLoop
from kivy.clock import Clock
from kivy.metrics import dp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.scatter import Scatter
from kivy.uix.widget import Widget


class BubbleButton(Button):
Expand All @@ -91,6 +93,14 @@ class Bubble(GridLayout):
'''Bubble class. See module documentation for more information.
'''

auto_dismiss = BooleanProperty(True)
'''This property determines if the widget is automatically
removed when the user clicks outside it.

:attr:`auto_dismiss` is a :class:`~kivy.properties.BooleanProperty` and
defaults to True.
'''

background_color = ListProperty([1, 1, 1, 1])
'''Background color, in the format (r, g, b, a). To use it you have to set
either :attr:`background_image` or :attr:`arrow_image` first.
Expand Down Expand Up @@ -235,6 +245,33 @@ def clear_widgets(self, **kwargs):
else:
content.clear_widgets()

def hide(self, *largs, **kwargs):
'''Close the Bubble if it is open.
When the view is dismissed, it will be faded out before being
removed from the parent. If you don't want animation, use::

view.dismiss(animation=False)

'''
parent = self.parent
if not parent:
return

if kwargs.get('animation', True):
anim = Animation(opacity=0, d=.225)
anim.bind(on_complete=lambda *args: parent.remove_widget(self))
anim.start(self)
else:
parent.remove_widget(self)

def on_touch_down(self, touch):
if not self.collide_point(*touch.pos):
if self.auto_dismiss:
self.hide()
return True
super(Bubble, self).on_touch_down(touch)
return True

def on_show_arrow(self, instance, value):
self._arrow_img.opacity = int(value)

Expand Down