def create_user_cards(user_list: list): """ Method for creating a stack of cards to render in the application Parameters: user_list (list): A list of User objects Returns: stack(list): On success, returns a list of Pypercard Cards. On failure, logs error output """ stack = [] len_users = len(user_list) for i in range(len_users): user = user_list[i] img_file = f"./img/image{i}.jpg" urllib.request.urlretrieve(user.photo, img_file) buttons = ( [{"label": "Next", "target": f"Card{i+1}"}] if i < len_users - 1 else None ) text = f"Name: {user.name.capitalize()}\nAge: {user.age}\nBio: {user.bio}\n{user.number}" card = Card( title=f"Card{i}", background=img_file, text=text, text_color="whitesmoke", buttons=buttons, text_size=25, ) stack.append(card) return stack
""" Gets the name of the user from the form field and stores it in the data_store. If no name is given, causes an error to be displayed. """ if form_value: data_store["name"] = form_value return "hello" else: return "error" stack = [ Card( "get_value", form=Inputs.TEXTBOX, text="What is your name..?", buttons=[ {"label": "OK", "target": get_name} # Use the function! ] ), Card( "hello", text="Hello {name}!", buttons=[ {"label": "OK", "target": "get_value"} ] ), Card( "error", text="ERROR\n\nPlease enter a name!", text_color="white", background="red",
trees = pagetree.xpath('//div[@class="counter"]/@data-count')[0] # Store the number of trees in the data_store d['trees'] = str(trees) # Target = 20 million trees. Store remaining trees in the data_store d['remaining'] = str(20000000 - int(trees)) return 'displayTrees' except: # go to the 'error' card if there is no internet return 'error' AppCards = [ # The first card has a very short auto-advance and just runs the grabData() function. Card( "init", auto_advance= 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, auto_target=grabData, background="green"), # Displays trees planted and trees remaining, with a lot of extra BBcode. (Human readable: "Trees planted: {trees} Trees remaining: {remaining} Donate at teamtrees.org $1 = 1 tree # Reloads the 'init' card to get the latest number of trees every 2.5 seconds. Card( "displayTrees", text= "[font=assets/JFWilwod][size=80]Trees planted:[/size]\n[size=120]{trees}[/size]\n[size=55]Trees left to plant:[/size]\n[size=120]{remaining}[/size]\n[size=30]Donate at teamtrees[/font].[font=assets/JFWilwod]org\n[/font]$[font=assets/JFWilwod]1 [/font]=[font=assets/JFWilwod] 1 tree[/size][/font]", background="green", text_color="black", auto_advance=2.5, auto_target='init'), # The card that is displayed if there is an Internet error. Tries again after 5 seconds. Card("error", text="Error getting trees",
from pypercard import Inputs, Card, CardApp cards = [ Card( "TextBox", form=Inputs.TEXTBOX, text="A single line textbox", buttons=[{ "label": "Next", "target": "TextArea" }], ), Card( "TextArea", form=Inputs.TEXTAREA, text="A multi line text area", buttons=[{ "label": "Next", "target": "MultiChoice" }], ), Card( "MultiChoice", form=Inputs.MULTICHOICE, options=["Ham", "Eggs", "Bacon", "Sausage"], text="A multiple choice selection", buttons=[{ "label": "Next", "target": "Select" }], ),
if data_store['tower'] >= 100: return 'TowerFinished' if data_store['hair'] <= 0: return 'Hairpocalypse' return 'Move' def end(data_store, form_value): app.stop() app = CardApp(name='Rapunzel, Rapunzel …', data_store=state, stack=[ Card( 'TheStorySoFar', text='Parents, blah, salad, foo …', buttons=[{'label': 'Next', 'target': 'Move'}], ), Card( 'Move', text='Build me a tower!\nCompletion: {tower}%', form=Inputs.SLIDER, options=(0, 10, 1), buttons=[{'label': 'Next', 'target': move}], ), Card( 'TowerFinished', text='The tower is built, Rapunzel is safe.', buttons=[{'label': 'Yay?', 'target': 'Thanks'}], ), Card(
if data["instructions"]: if not data["locked"]: return "finale" else: return "waiting" else: data["instructions"] = True return "instruct" cards = [ Card("hello", text="Hello, please enter your forename...", form=Inputs.TEXTBOX, buttons=[ { "label": "OK", "target": name_entry }, ]), Card("nameerror", text="Please enter your name.", auto_advance=3, auto_target="hello"), Card( "intro1", text_size=text_size, text= "Hello, {name}.\n\nPlease ensure you have sound turned on, or headphones plugged in. Use buttons and forms to proceed through the game.\n\nIf there are no buttons visible, it means the screen will advance after a pre-determined period of time.\n\nCan you solve the riddle of the Alchemist's Tower?", buttons=[{ "label": "OK",
val = float(form_value) data_store["result"] = 9.0 / 5.0 * val + 32 return "Result" except Exception: return "Error" cards = [ Card( "GetValue", form=Inputs.TEXTBOX, text="Enter a number to convert...", buttons=[ { "label": "Convert to Celsius", "target": to_c }, { "label": "Convert to Farenheit", "target": to_f }, ], ), Card( "Error", text="[b]ERROR[/b]\n\nPlease enter a number.", text_color="white", background=palette("red"), auto_advance=3, auto_target="GetValue", ),