Graphical Interface


class renderer.Renderer(canvas)[source]

The Renderer class is an abstract class describing a generalized drawing engine. It has to be subclassed to implement the drawing in a way specific to the UI that the program is using.

The base class does not impose any restrictions on the type of the canvas parameter. It is up to a specific implementation to interpret this parameter correctly.


Add a pose transformation to the current transformation


Clears the canvas and draws the grid if necessary

To be implemented in subclasses.

draw_arrow(x1, y1, x2, y2, angle=0.3, ratio=0.1, close=False)[source]

Draw an arrow from (x1, y1) to (x2, y2). You can also specify the arrowhead angle (in radians), the ratio between arrowhead and arrow length and the triangular (close=True) or linear (close=False) arrowhead shape.

draw_ellipse(cx, cy, ra, rb=None)[source]

Draws an ellipse with current pen and fills it with current brush.

The center of the ellipse is at (cx, cy), the half-axes are ra and rb. In the case rb is not specified, the method draws a circle of radius ra.

draw_line(x1, y1, x2, y2)[source]

Draw a line using the current pen from (x1,y1) to (x2, y2)

draw_point(x, y)

Draw a single point using the current pen at (x,y)


Draw a set of points, given as [(x,y)], using the current pen


Draws a polygon with current pen and fills it with current brush

Expects a list of points as a list of tuples or as a numpy array.

draw_rectangle(x, y, width, height)[source]

Draws a rectangle with current pen and fills it with current brush

The bottom-left corner of the rectangle is at (x, y), if the width and height are positive.


Restore the last saved state from the stack

The state includes default pose, pen and brush.

To be implemented in subclasses.


Store the current state on the stack.

Current state includes default pose, pen and brush.

To be implemented in subclasses.


Change canvas size

On canvas rescale the zoom factor will be recalculated: If the view rect was set, the view will be rescaled to fit the rect. If the view rect was not set, the zoom factor and default pose will be kept.


Resets the renderer to default pose and zoom level


Rotate canvas by angle (in radians)

To be implemented in subclasses.


Scale all drawing operations by factor

To be implemented in subclasses.


Zoom up the drawing by an additional factor

Equivalent to set_zoom_level(zoom_level*factor)

The zoom center is at the last set screen pose. This method will clear the canvas.


Sets the fill color.

The color is an integer, interpreted as 0xAARRGGBB. In the case AA == 0 the color is considered fully opaque.

Use None to unset a brush.


Tell the renderer to draw on canvas.

The type of canvas is implementation-dependent

set_pen(color=0, thickness=1)[source]

Sets the line color anf thickness.

Color is interpreted as 0xAARRGGBB. In case AA == 0 the color is considered fully opaque.

Use None to unset a pen.


Set a coordinate transformation based on pose


Set the pose of center of the canvas

The zoom center will switch to canvas center.

Parameters:pose (Pose) – The new pose of the lower-left corner.

Set the pose of the lower-left corner of the canvas.

The zoom center will switch to that corner.

Parameters:pose (Pose) – The new pose of the lower-left corner.
set_view_rect(x, y, width, height)[source]

Zoom on the rectangle to fit it into the view


Zoom up the drawing by a factor of zoom_level

The zoom center is at the last set screen pose.

This method will clear the canvas.


Draw the grid on the canvas background by default.

The grid is adaptive, with minimum interline distance of 40 px, and a maximum of 80 px. In the case the interline distance has to be smaller or larger, it is scaled. The interval is divided either in half, in five parts or in ten parts, to keep the grid decimal.

This method will clear the canvas

translate(dx, dy)[source]

Translate canvas by dx, dy

To be implemented in subclasses.

class qt_renderer.QtRenderer(paint_device)[source]

An implementation of Renderer for PyQt4.

This renderer will draw on any QPaintDevice


Interaction between GUI and the Simulator

The interaction between the UI and the simulator happens through two thread-safe queues. One queue contains the commands for the simulator, the other queue contains messages from the simulator. The communication is implemented in the base ui class, ui.SimUI.

class ui.SimUI(renderer)[source]

The SimUI class defines a front-end for the Simulator. It contains the necessary functions for the frontend-simulator communication and stubs for the message callbacks.

This class manages three important objects:

  • The simulator, as self.simulator_thread
  • The incoming simulator events, as self.in_queue
  • The outgoing simulator commands, as self.sim_queue

The constructor of SimUI takes a Renderer object as parameter. This renderer will be passed to the simulator to draw on.


Pause the simulation.


Processes one or all incoming events from the simulator. A single event is a tuple (name,args). During the processing of the event, the function simulator_name will be called with args as parameters.

It is strongly discouraged to create new class methods with the name starting with simulator_. Such functions could be called from the simulator without your consent.

Unknown or malformed events will lead to an error message printed to the console.


Register a callback that will be executed to process the


Unpause the simulation.

run_simulator_command(command, *args)[source]

Sends the command command to the simulator. All arguments after command are passed to the command processing function on the simulator side.

See Simulator for the available commands.

simulator_exception(e_type, e_value, e_traceback)[source]

An exception was raised in the simulator thread in the attempt to process an incoming command.

simulator_log(message, objclass, objcolor)[source]

A log message was generated by one of the simulation objects of class objclass. The objcolor is the color of the simobject, in the case the object is connected to one, and None otherwise.

simulator_make_param_window(robot_id, name, parameters)[source]

A request from the supervisor to create a parameter window. robot_id is guaranteed to uniquely identify a robot in a simulation. Currently, robot_id is the actual robot object. It can be used e.g. to extract the color of the robot as robot_id.get_color(). name is the desired window name, and parameters is the structure returned by get_ui_description().


A notification that the simulation has been paused.


A notification that the simulation has been reset.


A notification that the simulation has been started.


A notification that the simulation has been stopped.


A request to redraw the simulation window. This notification signifies that the simulation has stopped using the renderer, and is waiting for the UI to process this event.

The simulation will be resumed after this function exits.


Prepare the simulation environment for testing, e.g. disable user controls of the simulation progress.


Advance the simulation one step if it is paused.


Return UI back to normal operation.


Unregister a previously registered event handler.

class ui.uiParameter(elem_type)[source]

uiParameter represents a single GUI element that is used to build a parameter window in the UI (simulator event “make_param_window”).

It has one parameter, type, that defines the type of the parameter. Possible parameter types are GROUP, INT, FLOAT, BOOL and SELECT.

PyQt4 implementation

Table Of Contents

Previous topic

Supervisor/Controller system

Next topic


This Page