Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@TutorialDoctor
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TutorialDoctor/621531650e568169b069 to your computer and use it in GitHub Desktop.
Save TutorialDoctor/621531650e568169b069 to your computer and use it in GitHub Desktop.
Menu Starter.py
import ui
from sound import *
# For Pythonista on IOS
# Adding menu elements is now simple. In the UI section, add a custom view.
# Inside of the custom view, add a button
# Create a variable for the view under 'Create Views' following the format
# Add that variable to the menus list
# Add a switch to the main view with a toggle action
COLOR={'white':'#DBDBDB','black':'#373737'}
#MAIN CODE
# Hides the parent view of the sender
def close_view(sender):
sender.superview.hidden=True
play_effect('Click_1',1,.4) #sound,volume,pitch
# Updates a label with a slider's value
def update(sender):
view4['label1'].text = str(sender.value)
# Toggles menus (hidden/unhidden)
def toggle(sender):
if sender.value:
for each in menus:
each.hidden=False
play_effect('Click_2')
elif not sender.value:
for each in menus:
each.hidden=True
play_effect('Click_1',1,.4) #sound,volume,pitch
# Closes the sender' parent view
def quit(sender):
sender.superview.close()
# Custom Classes
# Create Views
# Load the main view (pyui file)
window = ui.load_view()
view1 = window['view1']
view2 = window['view2']
view3 = window['view3']
view4 = window['view4']
view5= window['view5']
view6= window['view6']
# Add views to the list of menus for toggling
menus=[view1,view2,view3,view4,view5]
# For each object in the list of menus...
for each in menus:
# change properties for the button1 element
each['button1'].action = close_view
each['button1'].tint_color = COLOR['black']
each['button1'].title = 'Close'
each['button1'].font = ('<system-bold>',15)
# A way to set color themes
light_theme=False
if light_theme:
window.background_color=COLOR['white']
for each in menus:
each['button1'].tint_color=COLOR['black']
elif not light_theme:
window.background_color=COLOR['black']
for each in menus:
each['button1'].tint_color=COLOR['white']
# Display the main view.
window.present()
# Unimplemented code
'''
for each in window.subviews:
print each.name
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment