Skip to content

Instantly share code, notes, and snippets.

@jsbain

jsbain/big_button.py Secret

Created Sep 1, 2015
Embed
What would you like to do?
big_button.py
# coding: utf-8
import ui,console,random
# tricky way to get to instance from within ui editor
def this():
import inspect
fb=inspect.currentframe().f_back
while fb.f_back.f_code.co_name != 'load_view_str':
fb=fb.f_back
return fb.f_locals['v']
class MyView(ui.View):
def __init__(self):
self.counter=0
def did_load(self):
# you could also set up button callbacks here... the more traditional way
pass
def button_callback(self,sender):
try:
console.hud_alert(sender.name.split('|')[self.counter],duration=2)
self.counter+=1
except IndexError:
self.close()
v=ui.load_view('big_button')
# note that type(v)==MyView
v.present('sheet')
[
{
"class" : "View",
"attributes" : {
"custom_class" : "MyView",
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)",
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)",
"enabled" : true,
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)",
"flex" : ""
},
"frame" : "{{0, 0}, {200, 200}}",
"selected" : false,
"nodes" : [
{
"class" : "Button",
"attributes" : {
"background_color" : "RGBA(1.000000,0.033333,0.033333,1.000000)",
"frame" : "{{80, 104}, {80, 32}}",
"font_size" : 26,
"title" : "DO NOT PUSH",
"tint_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)",
"action" : "this().button_callback",
"font_bold" : true,
"name" : "Hey can't you read?| Don't do that again| HARDDRIVE FORMAT COMPLETE|Just kidding|Are you still here!|You have been eaten by a grue.| πŸ‘Ή|πŸ‘ΉπŸ‘Ή|πŸ‘ΉπŸ‘ΉπŸ‘ΉπŸ‘Ή|βŽβŒπŸš«βŒβŒβŒβŒπŸš«βŽβŽβŒπŸš«βŒβŽβŒβŒβŒβŽβŒβŒπŸš«βŒπŸš«πŸš«βŒπŸš«βŒπŸŒžπŸ˜“πŸ˜™πŸ˜šπŸ˜‚πŸ˜πŸ˜‘πŸ˜‹πŸ˜œπŸ˜ΆπŸ˜‘πŸ˜°πŸ˜‘πŸ˜²",
"corner_radius" : 100,
"uuid" : "26E52FCA-27E9-49BE-B245-A64865FBE536",
"border_width" : 3,
"class" : "Button"
},
"frame" : "{{0, 6}, {194, 194}}",
"selected" : false,
"nodes" : [
]
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment