mirror of https://github.com/kivy/kivy.git
Page:
Android style menu app skeleton
Pages
A draggable scrollbar using a slider
AdBuddiz Android advertisements integration for Kivy apps
Advanced Graphics: In Progress
An example of background Twisted server running on Android
Android Background Services
Android SDK NDK Information
Android SDK NDK Informations
Android native embedded browser
Android style menu app skeleton
Background Service using P4A android.service
Batch installer for windows(KivyInstaller)
Breaking changes in Kivy
Building Portable Package
Button(s) in settings panel
Buttons in Settings panel
Community Guidelines
Connecting Kivy with Anaconda (OSX)
Contextual Menus
Contextual menus
Control alpha of all the children
Create source distribution release on PyPI
Creating a Release APK
Data driven variables with kivy properties
Debugging widget sizes
Deep Linking with iOS and Android
Delayed Work using Clock
Drag and Drop Widgets
Dragable Widget
Draggable Scalable Button
Editable ComboBox
Editable Label
Embedding a Carousel inside a TabbedPanel
GestureBox
Home
Implementing Android Adaptive Icons
KEP001: Instantiate things other than widgets from kv
Kivy 2.0 api breaks
Kivy Blogs and Blog Posts
Kivy Python 2 Support Timeline
Kivy Technical FAQ
Kv language preprocessing
Linking ScreenManager to a different Widget
List of Kivy Projects
Markup Summary
Menu on long touch
Migration guide from legacy garden packages
Moving kivy.garden.xxx to kivy_garden.xxx and kivy.deps.xxx to kivy_deps.xxx
On touch current widget
On touch on current widget
Packaging Kivy apps written in Python 3, targeting Windows using Nuitka
Pyjnius Vibrator Example
Release Checklist
Release notes for 1.10.0
Release notes for 1.11.0
Sample Gestures
Scaler for Retina screen
Scollable Options in Settings panel
Scrollable Label
Setting Up Kivy with various popular IDE's
Setting up Pycharm on OSX (older versions)
Setting up garden with Mac Ports
Setting up kivy with various popular IDE
Simple slider with value in label
Snippet template
Snippets awaiting moderation
Snippets
Starting Kivy App and Service on bootup on Android
Styling a Spinner and SpinnerOption in KV
Talks and tutorials
Theming Kivy
Tiled Maps & Tile Based Movement
Tiling the background of a widget with an image, pixel perfect
Ubuntu Touch
Updating widget content from a items list
User Snippets
Using Asynchronous programming inside a Kivy application
Using Buildozer on windows 10 using WSL
Viewport with fixed resolution autofit to window
Windows RT
Working with Python threads inside a Kivy application
rand0m app
wiki_proposed
2
Android style menu app skeleton
Aron Barreira Bordin edited this page 2015-07-10 19:56:52 -03:00
Table of Contents
Summary
- author: ilochab
- kivy: >= 1.8
Code skeleton to implement an Android app with kivy's ActionBar and side panel menu using Alexander Taylor's work downloaded from https://github.com/kivy-garden/garden.navigationdrawer.
Files
main.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# Name: androidApp.py
# Purpose: Simple example of a android application skeleton that manages
# application menu using ActionBar and SidePanelMenu that slides
# over the main panel
#
# Author: Licia Leanza
#
# Created: 13-04-2014
# Copyright: (c) Licia Leanza: 2014
# Licence: GPL v2
#-------------------------------------------------------------------------------
__author__ = 'licia'
#--------------------------------------------------------------------------
'''dictionary that contains the correspondance between items descriptions
and methods that actually implement the specific function and panels to be
shown instead of the first main_panel
'''
SidePanel_AppMenu = {'voce uno':['on_uno',None],
'voce due':['on_due',None],
'voce tre':['on_tre',None],
}
id_AppMenu_METHOD = 0
id_AppMenu_PANEL = 1
#--------------------------------------------------------------------------
import kivy
kivy.require('1.8.0')
from kivy.app import App
from navigationDrawer import NavigationDrawer
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.actionbar import ActionBar, ActionButton, ActionPrevious
from kivy.properties import ObjectProperty
RootApp = None
class SidePanel(BoxLayout):
pass
class MenuItem(Button):
def __init__(self, **kwargs):
super(MenuItem, self).__init__( **kwargs)
self.bind(on_press=self.menuitem_selected)
def menuitem_selected(self, *args):
print self.text, SidePanel_AppMenu[self.text], SidePanel_AppMenu[self.text][id_AppMenu_METHOD]
try:
function_to_call = SidePanel_AppMenu[self.text][id_AppMenu_METHOD]
except:
print 'errore di configurazione dizionario voci menu'
return
getattr(RootApp, function_to_call)()
#
class AppActionBar(ActionBar):
pass
class ActionMenu(ActionPrevious):
def menu(self):
print 'ActionMenu'
RootApp.toggle_sidepanel()
class ActionQuit(ActionButton):
pass
def menu(self):
print 'App quit'
RootApp.stop()
class MainPanel(BoxLayout):
pass
class AppArea(FloatLayout):
pass
class PaginaUno(FloatLayout):
pass
class PaginaDue(FloatLayout):
pass
class PaginaTre(FloatLayout):
pass
class AppButton(Button):
nome_bottone = ObjectProperty(None)
def app_pushed(self):
print self.text, 'button', self.nome_bottone.state
class NavDrawer(NavigationDrawer):
def __init__(self, **kwargs):
super(NavDrawer, self).__init__( **kwargs)
def close_sidepanel(self, animate=True):
if self.state == 'open':
if animate:
self.anim_to_state('closed')
else:
self.state = 'closed'
class AndroidApp(App):
def build(self):
global RootApp
RootApp = self
# NavigationDrawer
self.navigationdrawer = NavDrawer()
# SidePanel
side_panel = SidePanel()
self.navigationdrawer.add_widget(side_panel)
# MainPanel
self.main_panel = MainPanel()
self.navigationdrawer.anim_type = 'slide_above_anim'
self.navigationdrawer.add_widget(self.main_panel)
return self.navigationdrawer
def toggle_sidepanel(self):
self.navigationdrawer.toggle_state()
def on_uno(self):
print 'UNO... exec'
self._switch_main_page('voce uno', PaginaUno)
def on_due(self):
print 'DUE... exec'
self._switch_main_page('voce due', PaginaDue)
def on_tre(self):
print 'TRE... exec'
self._switch_main_page('voce tre', PaginaTre)
def _switch_main_page(self, key, panel):
self.navigationdrawer.close_sidepanel()
if not SidePanel_AppMenu[key][id_AppMenu_PANEL]:
SidePanel_AppMenu[key][id_AppMenu_PANEL] = panel()
main_panel = SidePanel_AppMenu[key][id_AppMenu_PANEL]
self.navigationdrawer.remove_widget(self.main_panel) # FACCIO REMOVE ED ADD perchè la set_main_panel
self.navigationdrawer.add_widget(main_panel) # dà un'eccezione e non ho capito perchè
self.main_panel = main_panel
if __name__ == '__main__':
AndroidApp().run()
androidapp.kv
#:kivy 1.8.0
<SidePanel>:
orientation: 'vertical'
spacing: 1
MenuItem:
text: 'voce uno'
MenuItem:
text: 'voce due'
MenuItem:
text: 'voce tre'
<AppActionBar>:
pos_hint: {'top':1}
ActionView:
use_separator: True
ActionMenu:
title: 'AndroidApp'
with_previous: False
app_icon: 'atlas://data/images/defaulttheme/splitter_grip'
on_press: self.menu()
ActionOverflow:
ActionQuit:
text: 'Fine'
icon: 'atlas://data/images/defaulttheme/close'
on_press: self.menu()
<MainPanel>:
orientation: 'vertical'
spacing: 1
AppActionBar:
size_hint: (1., 0.1)
AppButton:
id: bottone
nome_bottone: bottone
text: 'AppExec'
on_press: self.app_pushed()
on_release: self.app_pushed()
<PaginaTre>:
orientation: 'vertical'
spacing: 1
AppActionBar:
size_hint: (1., 0.1)
Image:
source: 'kivy.jpg'
<PaginaDue>:
orientation: 'vertical'
spacing: 1
AppActionBar:
size_hint: (1., 0.1)
Label:
text: 'due'
<PaginaUno>:
orientation: 'vertical'
spacing: 1
AppActionBar:
size_hint: (1., 0.1)
Label:
text: 'applicazione'
navigationDrawer.py
downloaded from https://github.com/kivy-garden/garden.navigationdrawer
##Comments