abce.gui package

Submodules

abce.gui.basiclayout module

abce.gui.bokehwidget module

Simple example:

class abce.gui.bokehwidget.BokehWidget(**kwargs)[source]

Bases: flexx.ui._widget.Widget

A widget that shows a Bokeh plot object.

For Bokeh 0.12 and up. The plot’s sizing_mode property is set to stretch_both unless it was set to something other than fixed. Other responsive modes are ‘scale_width’, ‘scale_height’ and ‘scale_both`, which all keep aspect ratio while being responsive in a certain direction.

class Both

Bases: object

CSS = '\n .flx-BokehWidget > .plotdiv {\n overflow: hidden;\n }\n '
class JS(*args)

Bases: flexx.event._hasevents.JS

CODE = 'flexx.classes.BokehWidget = function () {\n _pyfunc_instantiate(this, arguments);\n}\nflexx.classes.BokehWidget.prototype = Object.create(flexx.classes.Widget.prototype);\nflexx.classes.BokehWidget.prototype._base_class = flexx.classes.Widget.prototype;\nflexx.classes.BokehWidget.prototype._class_name = "BokehWidget";\n\nflexx.classes.BokehWidget.prototype.__emitters__ = ["key_down", "key_press", "key_up", "mouse_down", "mouse_move", "mouse_up", "mouse_wheel"];\nflexx.classes.BokehWidget.prototype.__handlers__ = ["_BokehWidget__resize_plot", "_BokehWidget__set_plot_components", "_Widget__children_changed", "_Widget__container_changed", "_Widget__make_singleton_container_widgets_work", "_Widget__style_changed", "_Widget__title_changed", "_Widget__update_tabindex", "check_size"];\nflexx.classes.BokehWidget.prototype.__local_properties__ = ["parent", "plot", "size"];\nflexx.classes.BokehWidget.prototype.__properties__ = ["base_size", "children", "container", "flex", "parent", "plot", "pos", "size", "style", "tabindex", "title"];\n\nflexx.classes.BokehWidget.prototype._BokehWidget__resize_plot = function () {\n var events;\n events = Array.prototype.slice.call(arguments);\n if ((_pyfunc_truthy(this.plot) && _pyfunc_truthy(this.parent))) {\n this.plot.resize();\n }\n return null;\n};\nflexx.classes.BokehWidget.prototype._BokehWidget__resize_plot.nobind = true;\nflexx.classes.BokehWidget.prototype._BokehWidget__resize_plot._connection_strings = ["size"];\n\nflexx.classes.BokehWidget.prototype._BokehWidget__set_plot_components = function () {\n var el, ev, events, getplot;\n events = Array.prototype.slice.call(arguments);\n ev = events[events.length -1];\n this.node.innerHTML = ev.div;\n el = window.document.createElement("script");\n el.innerHTML = ev.script;\n this.node.appendChild(el);\n getplot = (function () {\n var canvas;\n this.plot = Bokeh.index[ev.id];\n canvas = this.plot.plot_canvas_view;\n canvas.reset_dimensions();\n return null;\n }).bind(this);\n\n window.setTimeout(getplot, 100);\n return null;\n};\nflexx.classes.BokehWidget.prototype._BokehWidget__set_plot_components.nobind = true;\nflexx.classes.BokehWidget.prototype._BokehWidget__set_plot_components._connection_strings = ["_plot_components"];\n\nflexx.classes.BokehWidget.prototype._plot_func = function (plot) {\n plot = (plot === undefined) ? null: plot;\n return plot;\n};\nflexx.classes.BokehWidget.prototype._plot_func.nobind = true;\nflexx.classes.BokehWidget.prototype._plot_func.default = null;\nflexx.classes.BokehWidget.prototype._plot_func.emitter_type = "Property";\n\n'
plot

property: plot

init()[source]

Overload this to initialize a cusom widget. When called, this widget is the current parent.

plot

property: The Bokeh plot object to display. In JS, this prop provides the corresponding backbone model.

abce.gui.dockpanel module

class abce.gui.dockpanel.DockPanel(**kwargs)[source]

Bases: flexx.ui.layouts._layout.Layout

A layout that displays its children as dockable widgets.

This is a high level layout allowing the user to layout the child widgets as he/she likes. The title of each child is used for its corresponding tab label.

the widget’s style property ‘location’ determines where to place the next new widget.

location = N, S, W, or E:
for absolute placement.
location = L(eft), R(ight), U(nder), O(ver) B(efore) A(fter):
for relative placement.
relative:
Relative to the last widget or to the widget set with set_relative
class Both[source]

Bases: object

set_relative(widget)[source]

The next attached widget will be placed relative to this one

CSS = '\n\n div.p-TabBar {\n border: 1px solid #ccc;\n width: 20% !important;\n height: 100% !important;\n overflow-y: scroll;\n border-color: blue !important;\n }\n\n div.p-TabBar-body {\n border-color: blue !important;\n }\n\n ul.p-TabBar-content {\n display: block !important;\n background-color: blue !important;\n }\n\n span.p-TabBar-tabText {\n color: white !important;\n }\n\n span.p-TabBar-tabText:hover {\n color: black !important;\n }\n\n li.p-TabBar-tab {\n border-color: blue !important;\n background-color: blue !important;\n }\n\n li.p-TabBar-tab:hover {\n border-color: black !important;\n border: 2px solid #ccc;\n background-color: DodgerBlue !important;\n }\n\n li.p-mod-current {\n background-color: DodgerBlue !important;\n }\n div.p-TabBar-tab button {\n display: block !important;\n background-color: red !important;\n color: black;\n padding: 22px 16px;\n width: 20% !important;\n border: none;\n outline: none;\n text-align: left !important;\n cursor: pointer !important;\n transition: 0.3s;\n }\n\n div.p-StackedPanel {\n top: 0px !important;\n padding: 0px 12px;\n border: 1px solid #ccc;\n width: 80% !important;\n border-left: none !important;\n left: 20% !important;\n height: 100% !important;\n }\n '
class JS(*args)

Bases: flexx.event._hasevents.JS

CODE = 'flexx.classes.DockPanel = function () {\n _pyfunc_instantiate(this, arguments);\n}\nflexx.classes.DockPanel.prototype = Object.create(flexx.classes.Layout.prototype);\nflexx.classes.DockPanel.prototype._base_class = flexx.classes.Layout.prototype;\nflexx.classes.DockPanel.prototype._class_name = "DockPanel";\n\nflexx.classes.DockPanel.prototype.__emitters__ = ["key_down", "key_press", "key_up", "mouse_down", "mouse_move", "mouse_up", "mouse_wheel"];\nflexx.classes.DockPanel.prototype.__handlers__ = ["_Widget__children_changed", "_Widget__container_changed", "_Widget__make_singleton_container_widgets_work", "_Widget__style_changed", "_Widget__title_changed", "_Widget__update_tabindex", "check_size", "myselectWidget"];\nflexx.classes.DockPanel.prototype.__local_properties__ = ["parent", "size"];\nflexx.classes.DockPanel.prototype.__properties__ = ["base_size", "children", "container", "flex", "parent", "pos", "size", "style", "tabindex", "title"];\n\nflexx.classes.DockPanel.prototype._add_child = function (widget) {\n var after, location;\n after = _pymeth_split.call(widget.style, "location:")[1];\n try {\n location = _pymeth_split.call(after, ";")[0];\n } catch(err_2) {\n if (err_2 instanceof Error && err_2.name === "TypeError") {\n location = "";\n }\n }\n location = _pymeth_upper.call(location);\n if (_pyfunc_contains("W", location)) {\n this.phosphor.insertLeft(widget.phosphor);\n } else if (_pyfunc_contains("N", location)) {\n this.phosphor.insertTop(widget.phosphor);\n } else if (_pyfunc_contains("E", location)) {\n this.phosphor.insertRight(widget.phosphor);\n } else if (_pyfunc_contains("S", location)) {\n this.phosphor.insertBottom(widget.phosphor);\n } else if ((this.relative === null)) {\n this.phosphor.insertLeft(widget.phosphor);\n } else if (_pyfunc_contains("L", location)) {\n try {\n this.phosphor.insertLeft(widget.phosphor, this.relative);\n this.lastworking = this.relative;\n } catch(err_3) {\n {\n this.phosphor.insertLeft(widget.phosphor, this.lastworking);\n }\n }\n } else if (_pyfunc_contains("O", location)) {\n try {\n this.phosphor.insertTop(widget.phosphor, this.relative);\n this.lastworking = this.relative;\n } catch(err_3) {\n {\n this.phosphor.insertTop(widget.phosphor, this.lastworking);\n }\n }\n } else if (_pyfunc_contains("R", location)) {\n try {\n this.phosphor.insertRight(widget.phosphor, this.relative);\n this.lastworking = this.relative;\n } catch(err_3) {\n {\n this.phosphor.insertRight(widget.phosphor, this.lastworking);\n }\n }\n } else if (_pyfunc_contains("U", location)) {\n try {\n this.phosphor.insertBottom(widget.phosphor, this.relative);\n this.lastworking = this.relative;\n } catch(err_3) {\n {\n this.phosphor.insertBottom(widget.phosphor, this.lastworking);\n }\n }\n } else if (_pyfunc_contains("B", location)) {\n try {\n this.phosphor.insertTabBefore(widget.phosphor, this.relative);\n this.lastworking = this.relative;\n } catch(err_3) {\n {\n this.phosphor.insertTabBefore(widget.phosphor, this.lastworking);\n }\n }\n } else if (_pyfunc_contains("A", location)) {\n try {\n this.phosphor.insertTabAfter(widget.phosphor, this.relative);\n this.lastworking = this.relative;\n } catch(err_3) {\n {\n this.phosphor.insertTabAfter(widget.phosphor, this.lastworking);\n }\n }\n } else {\n this.phosphor.insertLeft(widget.phosphor);\n }\n this.relative = widget.phosphor;\n return null;\n};\n\nflexx.classes.DockPanel.prototype._init_phosphor_and_node = function () {\n this.phosphor = new window.phosphor.dockpanel.DockPanel();\n this.node = this.phosphor.node;\n this.relative = null;\n return null;\n};\n\nflexx.classes.DockPanel.prototype.myselectWidget = function (event) {\n this.phosphor.selectWidget(event["widget"].phosphor);\n return null;\n};\nflexx.classes.DockPanel.prototype.myselectWidget.nobind = true;\nflexx.classes.DockPanel.prototype.myselectWidget._connection_strings = ["myselectWidget"];\n\nflexx.classes.DockPanel.prototype.set_relative = function (widget) {\n this.relative = widget.phosphor;\n return null;\n};\n\n'
myselectWidget

event handler: myselectWidget

set_relative(widget)

The next attached widget will be placed relative to this one

selectWidget(widget)[source]
set_relative(widget)

The next attached widget will be placed relative to this one

abce.gui.form module

Form to input parameters acording to the parameter_mask

abce.gui.form.assert_all_of_the_same_type(values)[source]
abce.gui.form.form(parameter_mask, names)[source]

Gererates Form class instance with parameter_mask and names

abce.gui.loadform module

class abce.gui.loadform.LoadForm(**kwargs)[source]

Bases: flexx.ui._widget.Widget

class Both

Bases: object

CSS = ''
class JS(*args)

Bases: flexx.event._hasevents.JS

CODE = 'flexx.classes.LoadForm = function () {\n _pyfunc_instantiate(this, arguments);\n}\nflexx.classes.LoadForm.prototype = Object.create(flexx.classes.Widget.prototype);\nflexx.classes.LoadForm.prototype._base_class = flexx.classes.Widget.prototype;\nflexx.classes.LoadForm.prototype._class_name = "LoadForm";\n\nflexx.classes.LoadForm.prototype.__emitters__ = ["key_down", "key_press", "key_up", "mouse_down", "mouse_move", "mouse_up", "mouse_wheel"];\nflexx.classes.LoadForm.prototype.__handlers__ = ["_Widget__children_changed", "_Widget__container_changed", "_Widget__make_singleton_container_widgets_work", "_Widget__style_changed", "_Widget__title_changed", "_Widget__update_tabindex", "check_size"];\nflexx.classes.LoadForm.prototype.__local_properties__ = ["parent", "size"];\nflexx.classes.LoadForm.prototype.__properties__ = ["base_size", "children", "container", "flex", "parent", "pos", "size", "style", "tabindex", "title"];\n'
delete(event)[source]
init()[source]

Overload this to initialize a cusom widget. When called, this widget is the current parent.

update(event)[source]
wdg(event)[source]

abce.gui.make_graphs module

abce.gui.webtext module

Describes ABCE on GUI, if no other text is given

Module contents

ABCE can be started with a gui or provide visual data output

abce.gui.graphs(parameter_mask=None, names=None)[source]

After the simulation simulation.graphs displays all logged data, this can not be use in conjuncture with @gui.

Args:

parameter_mask (optional):
simulation parameters to display
names (optional):
a dictionary with the parameter name as key and an alternative text to be displayed instead.
abce.gui.gui(parameter_mask, names=None, header=None, story=None, title='Agent-Based Computational Economics', texts=None, pages=None, histograms=None, serve=False, runtime='browser-X', truncate_rounds=0, hostname='0.0.0.0', port=80, pypy=None)[source]

gui is a decorator that can be used to add a graphical user interface to your simulation.

Args:

parameter_mask:

a dictionary with the parameter name as key and an example value as value. Instead of the example value you can also put a tuple: (min, default, max)

parameters can be:
  • float:

    {‘exponent’: (0.0, 0.5, 1.1)}

  • int:

    {‘num_firms’: (0, 100, 100000)}

  • dict or list, which should be strings of a dict or a list (see example):

    {‘list_to_edit’: “[‘brd’, ‘mlk’, ‘add’]”}

  • a list of options:

    {‘several_options’: [‘opt_1’, ‘opt_2’, ‘opt_3’]}

  • a string:

    {‘name’: ‘2x2’}

names (optional):
a dictionary with the parameter name as key and an alternative text to be displayed instead.
title:
a string with the name of the simulation.
header:
html string for a bar on the top
story:
a dictionary with text to be displayed alongeside the graphs. Key must be the graphs title, value can be text or html.
pages:
A dictinoary with title as key and links to external websites as values, which are displayed on the right hand side.
truncate_rounds:
Does not display the initial x rounds, in the result graphs
runtime:
webbrowser to start the simulation in, can be ‘xui’ or python’s webbrowser module’s webrowser string.
histograms:
specifies in which round histograms are generated. If it is not specified rounds from the menu is used. Alternatively you can create ‘histogram’ parameter in parameter_mask.
serve:
If you run this on your local machine serve must be False. If used as a web server must be True
hostname:
Hostname if serve is active, defaults to ‘0.0.0.0’
port:
Port if serve is active, defaults to 80
pypy:
Name of the pypy interpreter to run ABCE super fast. e.G. ‘pypy’ or ‘pypy3’. The mainfile needs to be run with cpython e.G.: python3 start.py

Example:

parameter_mask = {'name': 'name',
                  'random_seed': None,
                  'rounds': 40,
                  'num_firms': (0, 100, 100000),
                  'num_households': (0, 100, 100000),
                  'exponent': (0.0, 0.5, 1.1),
                  'several_options': ['opt_1', 'opt_2', 'opt_3']
                  'list_to_edit': "['brd', 'mlk', 'add']",
                  'dictionary_to_edit': "{'v1': 1, 'v2': 2}"}

names = {'num_firms': 'Number of Firms'}

@gui(parameter_mask, names,
     title="Agent-Based Computational Economics",
     serve=False)
def main(simulation_parameters):
    parameter_list = eval(simulation_parameters['list_to_edit'])
    simulation = Simulation()
    firms = simulation.build_agents(Firm,
        simulation_parameters['num_firms'])
    households = simulation.build_agents(Household,
        simulation_parameters['num_households'])

    for r in range(simulation_parameters['rounds']):
        simulation.advance_round(r)
        firms.work()
        households.buy()

if __name__ == '__main__':
    main(simulation_parameters)