PopupWindow¶
Screenshot¶
Example¶
from enamlnative.core.api import *
from enamlnative.widgets.api import *
enamldef ContextMenu(PopupWindow): popup:
attr items = []
attr result = lambda r:r
ScrollView:
LinearLayout:
orientation = 'vertical'
background_color = "#FFF"
Looper:
iterable << popup.items
Button:
flat = True
text = loop_item
clicked ::
popup.result(self.text)
popup.show = False
enamldef ContentView(LinearLayout): drawer:
orientation = 'vertical'
AppBarLayout: app_bar:
height = "wrap_content"
Toolbar:
height = "wrap_content"
content_padding = (0,0,0,0)
Flexbox:
justify_content = "space_between"
Button:
flat = True
text = "Menu"
clicked :: self.children[0].show = True
ContextMenu:
gravity="bottom|right"
x=-20
items = ["One", "Two", "Three"]
Button:
flat = True
text = "Settings"
clicked :: ContextMenu(
parent=self,
x=-20,
items=["A", "B"]).popup()
Button:
text = "Popup in center"
clicked :: self.children[0].show = True
PopupWindow:
gravity = "center_horizontal|center_vertical"
position = 'absolute'
LinearLayout:
padding = (20, 20, 20, 20)
TextView:
text = "Volume"
SeekBar:
width = 200
Declaration¶
- class enamlnative.widgets.popup_window.PopupWindow(parent=None, **kwargs)[source]¶
Bases:
enaml.widgets.toolkit_object.ToolkitObject
A popup window that may contain a view.
- width¶
Width and height or a string “match_parent” or “fill_parent”
- gravity¶
Layout gravity
- x¶
Position
- focusable¶
Set whether the popup window can be focused
- touchable¶
Set whether the popup is touchable
- outside_touchable¶
Controls whether the pop-up will be informed of touch events outside of its window.
- show¶
Start the popup and display it on screen (or hide if False)
- background_color¶
Background color of the window (white by default)
- position¶
If relative, show as a dropdown on the parent view, otherwise show at the position given by x and y.
- animation¶
Animation style for the PopupWindow using the @style format (ex. @style/MyAnimation
- style¶
PopupWindow style using the @style format (ex. @style/Theme_Light_NoTitleBar_Fullscreen
- proxy¶
A reference to the proxy object.
- popup()[source]¶
Show the window from code. This will initialize and activate if needed.
Examples
>>> enamldef ContextMenu(PopupWindow): popup: attr result: lambda text: None Button: text = "One" clicked :: dialog.show = False dialog.result(self.text) Button: text = "Two" clicked :: dialog.show = False dialog.result(self.text) def on_result(value): print("User clicked: {}".format(value)) ContextMenu(result=on_result).popup()
Notes
This does NOT block. Callbacks should be used to handle click events or the show state should be observed to know when it is closed.
Android Implementation¶
- class enamlnative.android.android_popup_window.AndroidPopupWindow[source]¶
Bases:
enamlnative.android.android_toolkit_object.AndroidToolkitObject
,enamlnative.widgets.popup_window.ProxyPopupWindow
An Android implementation of an Enaml ProxyPopupWindow.
- window¶
A reference to the widget created by the proxy.
- showing¶
Whether the popup has been shown
No iOS implementation found.