Common interface for Simulator classes

Simulator classes are derived from either PySide.QtCore.QObject, PyQt.QtCore.QObject, so that the signals-and-slots mechanism can be used.

See also

The tutorial section handles the simulator and target classes in more detail in the tutorial about creating custom StepFunc objects

A Simulator object holds together information about and functionality of cellular automaton simulators.

class zasim.simulator.TargetProxy(target, attrs)[source]

Bases: object

class zasim.simulator.SimulatorInterface[source]

Bases: PySide.QtCore.QObject

This class serves as the base for simulator objects.

Note

If you ever derive from this class and you get an error like “PySide.QtCore.Signal object has no attribute ‘emit’”, then you have most likely forgotten to call super’s __init__.

shape = ()

The shape of the cellular space of this automaton.

It’s a tuple with the size of each dimension as entries.

Note

This excludes any borders that have redundant cells in them.

step_number = 0

The number of the current step, beginning with the initial configuration being step 0.

available_history = 0

How many steps back the simulator can go.

prepared = True

Wether the simulator needs to run any kind of preparation before being able to perform steps

palette_info = {}

Dictionary fro different display options and their extra data.

colors32: list or dictionary of 32bit padded RGB values, like QImage::Format_RGB32 qcolors: list or dictionary of QColor values tiles: dictionary with ‘images’, an image map and ‘rects’, a dictionary of rects chars: list or dictionary of ascii/unicode values cboxes: list or dictionary of multiline ascii/unicode values hexcols: list or dictionary of colors usable in css-like color definitions.

updated = <PySide.QtCore.Signal object at 0x3175ab0>

Is emitted when the conf has changed as result of a step.

changed = <PySide.QtCore.Signal object at 0x38ccae8>

Is emitted when the configuration has changed, but there was no step.

started = <PySide.QtCore.Signal object at 0x38ccb20>

Is emitted when continuous updating has been started.

stopped = <PySide.QtCore.Signal object at 0x38ccb58>

Is emitted when continuous updating has been stopped.

shapshot_taken = <PySide.QtCore.Signal object at 0x38ccb90>

Is emitted when a snapshot has been taken.

snapshot_restored = <PySide.QtCore.Signal object at 0x38ccbc8>

Is emitted when a snapshot is restored or a completely new configuration has been set.

target_attrs = []

The extra-attributes the target has to offer, such as histogram.

t = <zasim.simulator.TargetProxy object at 0x38cd450>

A proxy object to access the target_attrs.

changeinfo = None

Information about the last configuration change.

May be 1. a rectangle (x, y, w, h) that has been changed 2. None, if everything changed.

get_config()[source]

Returns a copy of the configuration space as a numpy array. Its shape matches up with shape, so it also does not include any borders.

set_config(config)[source]

Sets a new config for the simulator.

Emits snapshot_restored

set_config_value(pos, value=None)[source]

Set the config value at pos to value.

If value is None, flip the value instead.

step()[source]

Step the simulator once.

copy()[source]

Duplicate the simulator.

start()[source]

Call this to notify views, that continuous updates have been started.

stop()[source]

Call this to notify views, that continuous updates have been stopped.

snapshot()[source]

Get a lightweight snapshot of this simulator, that can be restored again later on.

Note

This emits the snapshot_taken signal.

restore(snapshot)[source]

Restore the simulator to an earlier state.

Note

This emits the sanpshot_restored signal.

reset(configurator=None)[source]

Reset the simulator by using the same generator that was initially used, if it’s still available, or set a new configurator for the future and reset the configuration with it once.

See also cagen.config

limit_palette()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object at 0x317a170>
class zasim.simulator.CagenSimulator(step_func)[source]

Bases: zasim.simulator.SimulatorInterface

This Simulator takes a StepFunc instance and packs it in an interface compatible with SimulatorInterface.

staticMetaObject = <PySide.QtCore.QMetaObject object at 0x317a1b8>
get_config()[source]

Return the config, sans borders.

set_config(config)[source]
set_config_value(pos, value=None)[source]
step()[source]

Delegate the stepping to the StepFunc.step() method, then emit updated.

step_inline()[source]

Step the simulator using the weave.inline version of the code.

step_pure_py()[source]

Step the simulator using the pure python code version.

reset(configurator=None)[source]
class zasim.simulator.ElementaryCagenSimulator(step_func, rule_nr)[source]

Bases: zasim.simulator.CagenSimulator

This Simulator has a few special options available only if you have an elementary step func with a rule number.

staticMetaObject = <PySide.QtCore.QMetaObject object at 0x317a248>
rule_number = 0

The rule number of the target.

Using Simulator without Qt

The module isn’t dependent on Qt, as the lightweight_signal module supplies a simple compatible Signal implementation.

File: lightweight_signal.py Author: Thiago Marcos P. Santos Created: August 28, 2008

Purpose: A signal/slot implementation

This code was taken from http://code.activestate.com/recipes/576477/ It’s supposed to serve as a drop-in replacement for PyQt/PySide Signals.

Modifications have been made to it to make them behave more like Signals from Qt4.

class zasim.lightweight_signal.Signal(*types)[source]

Bases: object

A lightweight Signal class when Qt is not installed.

Create the Signal object. The type signatures are ignored.

emit(*args, **kwargs)[source]

Emit the signal, call all slots that are connected.

connect(slot)[source]

Connect this signal to a slot.

disconnect(slot)[source]

Disconnect this signal from a slot.

Table Of Contents

Previous topic

Using zasim in GUI

Next topic

zasim.config - Generate configs from different sources

This Page