Introduction

Installation

Limitations of the "file" protocol

Frequently asked questions

Syntax, keywords and built-in functions

Standard distribution

import implementation

Brython packages

Browser interface

Introduction - DOM API
Creating a document
Accessing elements
Attributes, properties and methods

Events
Mouse events
Keyboard events
Focus events
Drag events

Query string

Interactions with Javascript

Brython-specific built-in modules

browser
browser.aio
browser.ajax
browser.html
browser.local_storage
browser.markdown
browser.object_storage
browser.session_storage
browser.svg
browser.template
browser.timer
browser.webcomponent
browser.websocket
browser.worker

Widgets
browser.widgets.dialog
browser.widgets.menu

interpreter
javascript

Working with Brython

Execution options
Testing and debugging
Deploying an application

Cookbook

Hello world !
Insert content in an element
HTML markup (bold,italic...)
HTML table
Bind and unbind events
Handle options in a SELECT
Drag and drop
Get the content of an element
Read the content of a file
Store objects locally
Example of onmouseover
 

Problem

Store objects locally, using HTML5 Local Storage

Solution

Brython provides a built-in module browser.local_storage that stores string values associated to string keys

Store value in input field

from browser import document as doc
from browser.local_storage import storage
storage['brython_test'] = doc['zone'].value

Show stored value

from browser import alert
from browser.local_storage import storage
alert(storage['brython_test'])

If a Python object can be serialized by the json module, you can store the serialized version, then retrieve the original object :

from browser import alert
from browser.local_storage import storage
import json

a = {'foo':1,1515:'Marignan'}

storage["brython_test"] = json.dumps(a)

b = json.loads(storage['brython_test'])
alert(b['foo'])
alert(b['1515'])

Beware that json converts dictionary keys to their string value, this is why we use b['1515'] instead of b[1515]