ShapeHistory Module

Example configuration file: shape-history.xml

Contains The classes

  • ShapeHistory
  • DrawingEvent
  • Shape
  • Point
  • Line.

ShapeHistory keeps track of the current shapes the user has created. The shapes handled are any that inherits the Shape base class. There are currently two shapes implemented Point and Line.

Point is the graphical representation of a centred position. A point can be stored and managed by the ShapeHistory.

Line is a line between two Point objects.

DrawingEvent is an extension of Qub and handles mouse and keyboard events for the Qub canvas. It handles selection and some manipulation of the Shape objects.

class HardwareObjects.ShapeHistory.DrawingEvent(qub_helper)

Bases: Qub.Objects.QubDrawingEvent.QubDrawingEvent

Extension of Qub that handles mouse and keyboard events for the Qub canvas. Handles selection and some manipulation of the Shape objects.

de_select_all()

De selects all shapes.

de_select_current()
delete_selected()

Delete the selected shape.

mouseDblClick(x, y)

Method defined by QubDrawingEvent. Called on mouse click. Checks if a shape is selected and ‘moves to’ the selected position.

mousePressed(x, y)

Selects the shape the mouse is over when clicked, de selects everything if nothing was under the mouse.

mouseReleased(x, y)

Handles the type of selection, multiple shapes or only one.

rawKeyPressed(keyevent)

Method defined by QubDrawingEvent. Called on key press.

rawKeyReleased(keyevent)

Method defined by QubDrawingEvent. Called on key release. Handles removal of a selected shape when delete is pressed.

select_current()

Select the shape referenced by self._current_shape.

set_selected(shape)

Select the shape <shape> (programmatically).

Parameters:shape (Shape) – The shape to select.
class HardwareObjects.ShapeHistory.Line(drawing, start_qub_p, end_qub_p, start_cpos, end_cpos)

Bases: HardwareObjects.ShapeHistory.Shape

draw()
get_centred_positions()
get_hit(x, y)
get_qub_objects()
hide()
highlight()
move(new_positions)
show()
unhighlight()
update_position()
class HardwareObjects.ShapeHistory.Point(drawing, centred_position, screen_pos)

Bases: HardwareObjects.ShapeHistory.Shape

draw(screen_pos)

Draws a qub point in the sample video.

get_centred_positions()
get_hit(x, y)
get_qub_objects()
get_qub_point()
hide()
highlight()
move(new_positions)
show()
unhighlight()
class HardwareObjects.ShapeHistory.Shape

Bases: object

Base class for shapes.

draw()

Draws the shape on its drawing.

get_centred_positions()
Returns:The centred position(s) associated with the shape.
Return type:List of CentredPosition objects.
get_drawing()
Returns:The drawing on which the shape is drawn.
Return type:QDrawing
get_hit(x, y)
Returns:True if the shape was hit by the mouse.
get_qub_objects()
Returns:A list of qub objects.
hide()

Hides the shape.

highlight()

Highlights the shape

move(new_positions)

Moves the shape to the position <new_position>

show()

Shows the shape.

unhighlight()

Removes highlighting.

update_position()
class HardwareObjects.ShapeHistory.ShapeHistory(name)

Bases: HardwareRepository.BaseHardwareObjects.HardwareObject

Keeps track of the current shapes the user has created. The shapes handled are any that inherits the Shape base class.

add_grid(grid_dict)

Adds a grid object to the shape history. The grid/mesh is not yet handled as a Shape object but will be in the future.

This method will disapear when that transition has been made.

add_shape(shape)

Adds the shape <shape> to the list of handled objects.

Parameters:shape (Shape object.) – Shape to add.
clear_all()

Clear the shape history, remove all contents.

delete_shape(shape)

Removes the shape <shape> from the list of handled shapes.

Parameters:shape (Shape object.) – The shape to remove
get_drawing()
Returns:Returns the drawing of the shapes.
Return type:QubDrawing
get_drawing_event_handler()
Returns:The event handler of the drawing.
Return type:QubDrawingEvent
get_grid()

Returns the current grid object.

get_qimage(image, canvas, zoom=1)

Gets the QImage from a parent widget.

Parameters:
  • image (QWidget) – The QWidget that contains the image to extract
  • canvas (QCanvas) – The QCanvas obejct to add as overlay
  • zoom (int.) – Zoom level
Returns:

The QImage contained in the parent widget.

Return type:

QImage

get_shapes()
Returns:All the shapes currently handled.
get_snapshot(qub_objects)

Get a snapshot of the video stream and overlay the objects in qub_objects.

Parameters:qub_objects (QCanvas) – The QCanvas object to add on top of the video.
Returns:The snapshot
Return type:QImage
move_shape(shape, new_positions)

Moves the shape <shape> to the position <new_position>

Parameters:
  • shape (Shape) – The shape to move
  • new_position (<int, int>) – A tuple (X, Y)
set_drawing(drawing)

Sets the drawing the Shape objects that are managed are drawn on.

Parameters:drawing (QubDrawing (used by Qub)) – The drawing that the shapes are drawn on.
Returns:None

Project Versions

Previous topic

Session Module

Next topic

XMLRPCServer Module

This Page