Created
July 12, 2015 04:03
-
-
Save aron-bordin/c0ce571c0db850d0e6c8 to your computer and use it in GitHub Desktop.
Kivy ContextualActionView example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.base import runTouchApp | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.factory import Factory | |
from kivy.lang import Builder | |
from kivy.uix.actionbar import ContextualActionView | |
if __name__ == "__main__": | |
# XXX clean the first registration done from '__main__' here. | |
# otherwise kivy.uix.actionbar.ActionPrevious != __main__.ActionPrevious | |
# Factory.unregister('ActionPrevious') | |
Builder.load_string(''' | |
<Project>: | |
id: contextual | |
ActionPrevious: | |
title: "Project" | |
width: 100 | |
with_previous: True | |
ActionOverflow: | |
ActionButton: | |
text: 'Run...' | |
on_release: root.show_contextual_options() | |
ActionButton: | |
text: 'Save' | |
ActionButton: | |
text: 'Export' | |
<RunOptions>: | |
id: contextual | |
ActionPrevious: | |
title: "Run" | |
width: 100 | |
with_previous: True | |
ActionOverflow: | |
ActionButton: | |
text: 'Run' | |
on_release: print('run') | |
ActionButton: | |
text: 'Stop' | |
ActionButton: | |
text: 'Restart' | |
<MainWindow>: | |
action_bar: action_bar | |
ActionBar: | |
id: action_bar | |
pos_hint: {'top':1} | |
ActionView: | |
use_separator: True | |
ActionPrevious: | |
title: 'Action Bar' | |
with_previous: False | |
ActionOverflow: | |
ActionButton: | |
text: 'Project' | |
on_release: root.show_contextual_run() | |
ActionButton: | |
text: 'Exit' | |
''') | |
class Project(ContextualActionView): | |
def show_contextual_options(self, *args): | |
self.parent.add_widget(RunOptions()) | |
class RunOptions(ContextualActionView): | |
pass | |
class MainWindow(FloatLayout): | |
def show_contextual_run(self, *args): | |
self.action_bar.add_widget(Project()) | |
float_layout = MainWindow() | |
runTouchApp(float_layout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment