Skip to content

Instantly share code, notes, and snippets.

@tomthorogood
Created September 22, 2012 15:09
Show Gist options
  • Select an option

  • Save tomthorogood/3766464 to your computer and use it in GitHub Desktop.

Select an option

Save tomthorogood/3766464 to your computer and use it in GitHub Desktop.
Mogu Slideshow Recipe:
# This is a complete example of how to build a slideshow in mogu. For more information,
# check out the mogu wiki at http://www.github.com/tomthorogood/mogu/wiki
widgets["slidestack"] = \
{
type : container,
styles : "width_400 height_300"
name : "slidestack" #for event bindings
}
tree["slidestack"] = [] #we're going to populate this programatically
data["slide:titles"] = [
"Molly at the Beach",
"Johnny petting a shark",
"Harrison eating a banana",
"Kiesha catching a wave",
"Grandma looking for shells"
]
def create_image(filename, title):
from syntax import * #let Mogu syntax work in this function
return {
type : image,
source: "/resources/mogu/images/%s" % filename,
content: title, #this is the ALT tag for the image
}
# Now, a quick loop to create the images and add them to the slidestack:
num = 0
for title in data["slide:titles"]:
filename = "img%d.jpg" % num #the file names will img0.jpg, img1.jpg...
widget_name = "slidestack:%d" % num #"slidestack:0", etc.
widgets[widget_name] = new_image(filename, title)
tree["slidestack"].append(widget_name) #add the widget as a child to the slidestack!
num += 1
widgets["nav_container"] = { type : container }
tree["nav_container"] = ["nav_container:prev", "nav_container:next"]
widgets["nav_container:prev"] = \
{
type : text,
content : "Previous",
styles : "linkified inline red_text"
}
widgets["nav_container:next"] = \
{
type : text,
content : "Next",
styles : "linkified inline red_text"
}
widgets["slide_title"] = \
{
type : text,
content: " " #empty for now
styles: "pretty_font",
name: "title" #for event bindings
}
widgets["slideshow"] = { type : container }
tree["slideshow"] = ["slide_title", "slidestack', "nav_container"]
events["nav_container:prev"] = [
{
action : decrement.index,
trigger : click,
listener : "slidestack",
message : Number(1),
signal : Number(225) #this is going away soon, I promise!
}]
events["nav_container:next"] = [
{
action : increment.index,
trigger : click,
listener : "slidestack",
message : Number(1),
signal : Number(225)
}]
events["slidestack"] = [
{
action : change.text,
trigger: index.changed,
listener: "title",
message: "@data.slide:titles@ $current_index$"
signal : Number(225)
}
tree["wrapper"] = ["slideshow"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment