zasim.display.qt - QImage based display renderers

Inheritance diagram of zasim.display.qt

This module offers the BaseQImageRenderer base class and its two subclasses OneDimQImageRenderer for rendering one-dimensional configs and TwoDimQImageRenderer for rendering two-dimensional configs to QImages.

These classes also offer a _repr_png_ method, that is used by IPython to display configurations in-line.

zasim.display.qt.generate_tile_atlas(filename_map, common_prefix='')[source]

From a mapping to state value to filename, create a texture atlas from the given filenames. Those should all be as big as the first one.

Returns:The tile atlas as a QPixmap and a mapping from value to a QRect into the image.
zasim.display.qt.make_palette_qc(pal)[source]

Turn a 32bit color palette into a QColor palette.

zasim.display.qt.make_palette_32(pal)[source]

Turn a qcolor palette into a 32bit color palette.

zasim.display.qt.make_gray_palette(number_or_values)[source]

Generates a grayscale with number entries. Alternatively, accept a list or dictionary with values.

Returns:the RGB_32 palette and the QColor palette
zasim.display.qt.mix_colors(colors)[source]
zasim.display.qt.normalize_palette(pal)[source]

Sometimes palettes that are automatically generated are too dark. This fixes that problem.

zasim.display.qt.make_multiaxis_palette(values)[source]

From a list of tuples of the form

(possible_values, hue_for_axis)

generate a palette for cells that are made up of multiple components. Each component contributes a bit of color to the result.

zasim.display.qt.qimage_to_pngstr(image)[source]
zasim.display.qt.render_state_array(states, palette={0: 4278190080, 1: 4294967295, 2: 4294901760, 3: 4278190335, 4: 4278255360, 5: 4294967040, 6: 4278255615, 7: 4294902015}, region=None)[source]
zasim.display.qt.render_state_array_tiled(states, palette, rects, region=None, painter=None)[source]

Using a texture atlas and a dictionary of pixmap fragment “factories”, draw a configuration using graphical tiles.

Parameters:
  • states – The array of states to render.
  • palette – The image to use.
  • rects – A dictionary from state value to rect in the image.
  • region – What part of the config to render (x, y, w, h).
class zasim.display.qt.BaseQImagePainter(width, height, queue_size=1, scale=1, connect=True, frame_duration=0.02, **kwargs)[source]

Bases: PySide.QtCore.QObject

This is a base class for implementing renderers for configs based on QImage.

Initialize the BaseQImagePainter.

Parameters:
  • width – The width of the image to build.
  • height – The height of the image to build.
  • queue_size – The amount of histories that may pile up before forcing a redraw.
  • scale – The scale for the image.
  • connect – Connect the update signals from the simulator?
  • frame_duration – How long a frame ideally takes. If there are too many frames per second, skip some.
update = <PySide.QtCore.Signal object at 0x3c68768>

This signal will be emitted when the configuration has changed.

Its first argument is the area of change as a QRect.

begin_skip_frames()[source]
end_skip_frames()[source]
Frameskip(*args, **kwds)[source]
create_image_surf()[source]

Create the image surface when the display is created.

set_scale(scale)[source]

Change the scale of the display.

after_step(update_step=True)[source]

Implement this in a subclass to fetch the config from the simulator.

Parameters:update_step – Was this update caused by a step or just a change?
draw_conf()[source]

Get the conf/confs enqueued/set by after_step and draw them to _image.

connect_simulator()[source]
conf_changed()[source]

React to a change in the configuration that was not caused by a step of the cellular automaton - by a user interaction for instance.

conf_replaced()[source]

React to snapshot_restored.

This implementation just calls conf_changed.

export(filename)[source]
skip_frame()[source]

Returns True, if the frame is supposed to be skipped to reach the desired framerate.

staticMetaObject = <PySide.QtCore.QMetaObject object at 0x493b998>
class zasim.display.qt.OneDimQImagePainter(simulator, lines=None, connect=True, **kwargs)[source]

Bases: zasim.display.qt.BaseQImagePainter

This class offers drawing for one-dimensional cellular automata, which will fill up the display with a line that moves downwards and wraps at the bottom.

Initialise the OneDimQImagePainter.

Parameters:
  • simulator – The simulator to use.
  • lines – The number of lines to display at once.
  • connect – Should the painter be connected to the simulators change signals?
image_wrapped = <PySide.QtCore.Signal object at 0x453a420>

Emitted whenever the drawing position wraps around.

draw_conf()[source]
after_step(update_step=True)[source]
conf_replaced()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object at 0x4b33dd0>
class zasim.display.qt.TwoDimQImagePainterBase(width, height, queue_size=1, scale=1, connect=True, frame_duration=0.02, **kwargs)[source]

Bases: zasim.display.qt.BaseQImagePainter

This class offers rendering a two-dimensional simulator config to a QImage

Initialize the BaseQImagePainter.

Parameters:
  • width – The width of the image to build.
  • height – The height of the image to build.
  • queue_size – The amount of histories that may pile up before forcing a redraw.
  • scale – The scale for the image.
  • connect – Connect the update signals from the simulator?
  • frame_duration – How long a frame ideally takes. If there are too many frames per second, skip some.
after_step(update_step=True)[source]
create_image_surf()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object at 0x4b33b48>
class zasim.display.qt.TwoDimQImagePainter(simulator, connect=True, **kwargs)[source]

Bases: zasim.display.qt.TwoDimQImagePainterBase

Initialise the TwoDimQImagePainter.

Parameters:
  • simulator – The simulator to use.
  • connect – Connect the painter to the simulators change signals?
draw_conf()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object at 0x4b33f80>
class zasim.display.qt.TwoDimQImagePalettePainter(simulator, scale=0.1, **kwargs)[source]

Bases: zasim.display.qt.TwoDimQImagePainterBase

draw_conf()[source]
staticMetaObject = <PySide.QtCore.QMetaObject object at 0x4b33e60>
class zasim.display.qt.HistogramPainter(simulator, attribute, width, height, queue_size=1, connect=True, **kwargs)[source]

Bases: zasim.display.qt.BaseQImagePainter

The HistogramPainter draws an attribute from the simulator that’s an array of constant length as stacked, colored bars, so that the horizontal axis is the time and the vertical axis is the amount.

image_wrapped = <PySide.QtCore.Signal object at 0x4ac1810>

Emitted whenever the drawing position wraps around.

staticMetaObject = <PySide.QtCore.QMetaObject object at 0x4b33710>
draw_conf()[source]
after_step(update_step=True)[source]
conf_replaced()[source]
zasim.display.qt.display_table(images, columns=1, captions=None, transparent=True)[source]

Previous topic

zasim.display - Package for displaying configs

Next topic

zasim.display.console - Painting ascii art

This Page