Ashiba seeks to be an app building framework, allowing you to define layout with HTML or Enaml and write logic in Python. No Javascript needed!
- The only hard dependencies are Python 2.7 and pyyaml.
- To run all of the examples, you should also have numpy and pandas installed.
- In order to make use of the
build
functionality, you need conda. - For the best overall experience, use the Anaconda Python distribution
- Clone this repo.
- Execute
python setup.py install
orpython setup.py develop
, as desired.
The examples
folder contains several prewritten apps which showcase the workflow and capabilities of Ashiba.
After you have Ashiba installed, just run
ashiba start path/to/app
for example, from the root of this repo:
ashiba start examples/dataframes
- Navigate to a directory where you want your app to live.
- Execute
ashiba init app_name
, where app_name can be whatever you want. This will create a skeleton project in a directory with the same name. - There are three important files in the folder that you will edit:
- myapp.html
- handlers.py
- settings.py
This file contains app settings such as:
- Name of the app
- Icon to use for the app
- CSS theme to use
- Data files, if any
Since settings.py is a Python file, you can use python code (e.g. os.path.whatever) when setting the values.
- This is where the GUI for the app is laid out.
- An app template is used to wrap the HTML in this file, so you don't need to write boilerplate
<html>
or<head>
tags. - Everything in this file will end up inside a
<body><div class="container">
- Bootstrap 2.3.2 is included in the wrapper template. You are encouraged to make use of its grid system to lay out columns, etc.
- If you need to include additional CSS/JS/etc., you can access the header and footers of the wrapper template.
See
examples/dataframes/myapp.html
for an example. - Any element whose state you want to be able to get or set in Python must have an id attribute.
- In addition, any non-form elements* that you want to access in Python should have a
data-visible="true"
attribute.- *Form elements include
input
s andselect
s. These are always accessible from Python, even withoutdata-visible
.
- *Form elements include
- From Python, you can set DOM properties for any object, even those without
data-visible
. However, in order to get object-specific Python methods such asset_image
oradd_tab
, you must include thedata-visible
attribute.
- This is where the application logic is laid out.
- Function names that match the pattern /_?.+__.+\(dom\)/ define event handlers.
- For example, if I want to handle the 'click' event on an HTML object with 'btn_foo', the function definition would be
def btn_foo__click(dom):
. - Names with a leading underscore refer to classes. Thus, to bind an action to the click event on all controls with class 'control_widget', the function definition would be
def _control_widget__click(dom):
.
- For example, if I want to handle the 'click' event on an HTML object with 'btn_foo', the function definition would be
- These handlers accept a single argument, the
dom
object. This contains the state of all of theinput
s,select
s, and DOM elements with adata-visible
attribute in the DOM. - The
dom
object is dict-like, so changing the state of a DOM element is done like so:dom['object']['property'] = value
- Some items in the
dom
object will have special methods. For example, ifselect_stock
is aselect
tag in the HTML, one can calldom['select_stock'].add_item('aapl', "Apple")
to add an item to the dropdown.- These subclasses of GenericDomElement are defined in
ashiba/dom.py
- These subclasses of GenericDomElement are defined in