21. viewport — Interactive OpenGL Canvas embedded in a Qt4 widget.

Interactive OpenGL Canvas embedded in a Qt4 widget.

This module implements user interaction with the OpenGL canvas defined in module canvas. QtCanvas is a single interactive OpenGL canvas, while MultiCanvas implements a dynamic array of multiple canvases.

class viewport.CursorShapeHandler(widget)

A class for handling the mouse cursor shape on the Canvas.

Methods

Create a CursorHandler for the specified widget.

Methods

CursorShapeHandler objects have the following methods:

setCursorShape(shape)
Set the cursor shape to shape
setCursorShapeFromFunc(func)
Set the cursor shape to shape
class viewport.CanvasMouseHandler

A class for handling the mouse events on the Canvas.

Methods

CanvasMouseHandler objects have the following methods:

setMouse(button, func, mod=NONE)
resetMouse(button, mod=NONE)
getMouseFunc()
Return the mouse function bound to self.button and self.mod
class viewport.QtCanvas(*args)

A canvas for OpenGL rendering.

This class provides interactive functionality for the OpenGL canvas provided by the canvas.Canvas class.

Interactivity is highly dependent on Qt4. Putting the interactive functions in a separate class makes it esier to use the Canvas class in non-interactive situations or combining it with other GUI toolsets.

Methods

Initialize an empty canvas with default settings.

Methods

QtCanvas objects have the following methods:

resetOptions()
Reset the Drawing options to some defaults
setOptions(d)
Set the Drawing options to some values
setCursorShape(shape)
Set the cursor shape to shape
setCursorShapeFromFunc(func)
Set the cursor shape to shape
setMouse(button, func, mod=NONE)
resetMouse(button, mod=NONE)
getMouseFunc()
Return the mouse function bound to self.button and self.mod
start_rectangle_zoom()
finish_rectangle_zoom()
mouse_rectangle_zoom(x, y, action)

Process mouse events during interactive rectangle zooming.

On PRESS, record the mouse position. On MOVE, create a rectangular zoom window. On RELEASE, zoom to the picked rectangle.

setPickable(nrs=None)
Set the list of pickable actors
start_selection(mode, filtr)

Start an interactive picking mode.

If selection mode was already started, mode is disregarded and this can be used to change the filter method.

wait_selection()
Wait for the user to interactively make a selection.
finish_selection()
End an interactive picking mode.
accept_selection(clear=False)

Accept or cancel an interactive picking mode.

If clear == True, the current selection is cleared.

cancel_selection()
Cancel an interactive picking mode and clear the selection.
pick(mode='actor', single=False, func=None, filter=None)

Interactively pick objects from the viewport.

  • mode: defines what to pick : one of ['actor','element','point','number','edge']

  • single: if True, the function returns as soon as the user ends a picking operation. The default is to let the user modify his selection and only to return after an explicit cancel (ESC or right mouse button).

  • func: if specified, this function will be called after each atomic pick operation. The Collection with the currently selected objects is passed as an argument. This can e.g. be used to highlight the selected objects during picking.

  • filter: defines what elements to retain from the selection: one of [None,'closest,'connected'].

    • None (default) will return the complete selection.

    • ‘closest’ will only keep the element closest to the user.

    • ‘connected’ will only keep elements connected to - the closest element (set picked) - what is already in the selection (add picked).

      Currently this only works when picking mode is ‘element’ and for Actors having a partitionByConnection method.

When the picking operation is finished, the selection is returned. The return value is always a Collection object.

pickNumbers(None)
Go into number picking mode and return the selection.
idraw(mode='point', npoints=1, zplane=0., func=None, coords=None, preview=False)

Interactively draw on the canvas.

This function allows the user to interactively create points in 3D space and collects the subsequent points in a Coords object. The interpretation of these points is left to the caller.

  • mode: one of the drawing modes, specifying the kind of objects you want to draw. This is passed to the specified func.
  • npoints: If -1, the user can create any number of points. When >=0, the function will return when the total number of points in the collection reaches the specified value.
  • zplane: the depth of the z-plane on which the 2D drawing is done.
  • func: a function that is called after each atomic drawing operation. It is typically used to draw a preview using the current set of points. The function is passed the current Coords and the mode as arguments.
  • coords: an initial set of coordinates to which the newly created points should be added. If specified, npoints also counts these initial points.
  • preview: Experimental If True, the preview funcion will also be called during mouse movement with a pressed button, allowing to preview the result before a point is created.

The drawing operation is finished when the number of requested points has been reached, or when the user clicks the right mouse button or hits ‘ENTER’. The return value is a (n,3) shaped Coords array.

start_draw(mode, zplane, coords)
Start an interactive drawing mode.
finish_draw()
End an interactive drawing mode.
accept_draw(clear=False)

Cancel an interactive drawing mode.

If clear == True, the current drawing is cleared.

cancel_draw()
Cancel an interactive drawing mode and clear the drawing.
mouse_draw(x, y, action)

Process mouse events during interactive drawing.

On PRESS, do nothing. On MOVE, do nothing. On RELEASE, add the point to the point list.

start_drawing(mode)
Start an interactive line drawing mode.
wait_drawing()
Wait for the user to interactively draw a line.
finish_drawing()
End an interactive drawing mode.
accept_drawing(clear=False)

Cancel an interactive drawing mode.

If clear == True, the current drawing is cleared.

cancel_drawing()
Cancel an interactive drawing mode and clear the drawing.
edit_drawing(mode)
Edit an interactive drawing.
drawLinesInter(mode='line', single=False, func=None)

Interactively draw lines on the canvas.

  • single: if True, the function returns as soon as the user ends a drawing operation. The default is to let the user draw multiple lines and only to return after an explicit cancel (ESC or right mouse button).
  • func: if specified, this function will be called after each atomic drawing operation. The current drawing is passed as an argument. This can e.g. be used to show the drawing.

When the drawing operation is finished, the drawing is returned. The return value is a (n,2,2) shaped array.

initializeGL()
resizeGL(w, h)
paintGL()
getSize()
dynarot(x, y, action)

Perform dynamic rotation operation.

This function processes mouse button events controlling a dynamic rotation operation. The action is one of PRESS, MOVE or RELEASE.

dynapan(x, y, action)

Perform dynamic pan operation.

This function processes mouse button events controlling a dynamic pan operation. The action is one of PRESS, MOVE or RELEASE.

dynazoom(x, y, action)

Perform dynamic zoom operation.

This function processes mouse button events controlling a dynamic zoom operation. The action is one of PRESS, MOVE or RELEASE.

wheel_zoom(delta)
Zoom by rotating a wheel over an angle delta
emit_done(x, y, action)

Emit a DONE event by clicking the mouse.

This is equivalent to pressing the ENTER button.

emit_cancel(x, y, action)

Emit a CANCEL event by clicking the mouse.

This is equivalent to pressing the ESC button.

draw_state_rect(x, y)
Store the pos and draw a rectangle to it.
mouse_pick(x, y, action)

Process mouse events during interactive picking.

On PRESS, record the mouse position. On MOVE, create a rectangular picking window. On RELEASE, pick the objects inside the rectangle.

pick_actors()
Set the list of actors inside the pick_window.
pick_parts(obj_type, max_objects, store_closest=False)

Set the list of actor parts inside the pick_window.

obj_type can be ‘element’, ‘edge’ or ‘point’ ‘edge’ is only available for mesh type geometry max_objects specifies the maximum number of objects

The picked object numbers are stored in self.picked. If store_closest==True, the closest picked object is stored in as a tuple ( [actor,object] ,distance) in self.picked_closest

A list of actors from which can be picked may be given. If so, the resulting keys are indices in this list. By default, the full actor list is used.

pick_elements()
Set the list of actor elements inside the pick_window.
pick_points()
Set the list of actor points inside the pick_window.
pick_edges()
Set the list of actor edges inside the pick_window.
pick_numbers()
Return the numbers inside the pick_window.
draw_state_line(x, y)
Store the pos and draw a line to it.
mouse_draw_line(x, y, action)

Process mouse events during interactive drawing.

On PRESS, record the mouse position. On MOVE, draw a line. On RELEASE, add the line to the drawing.

classmethod has_modifier(clas, e, mod)
mousePressEvent(e)
Process a mouse press event.
mouseMoveEvent(e)
Process a mouse move event.
mouseReleaseEvent(e)
Process a mouse release event.
wheelEvent(e)
Process a wheel event.
keyPressEvent(e)
class viewport.FramedGridLayout(parent=None)

A QtGui.QGridLayout where each added widget is framed.

Methods

Initialize the multicanvas.

Methods

FramedGridLayout objects have the following methods:

addWidget()
removeWidget(w)
class viewport.MultiCanvas(parent=None)

An OpenGL canvas with multiple viewports and QT interaction.

The MultiCanvas implements a central QT widget containing one or more QtCanvas widgets.

Methods

Initialize the multicanvas.

Methods

MultiCanvas objects have the following methods:

newView(shared=None)
Create a new viewport
addView()
Add a new viewport to the widget
setCurrent(canv)

Make the specified viewport the current one.

canv can be either a viewport or viewport number.

currentView()
showWidget(w)
Show the view w
removeView()
updateAll()
removeAll()
addActor(actor)
printSettings()
changeLayout(nvps=None, ncols=None, nrows=None)

Lay out the viewports.

You can specify the number of viewports and the number of columns or rows.

If a number of viewports is given, viewports will be added or removed to match the number requested. By default they are layed out rowwise over two columns.

If ncols is an int, viewports are laid out rowwise over ncols columns and nrows is ignored. If ncols is None and nrows is an int, viewports are laid out columnwise over nrows rows.

Link viewport vp to to

Functions defined in the module viewport

viewport.dotpr(v, w)
Return the dot product of vectors v and w
viewport.length(v)
Return the length of the vector v
viewport.projection(v, w)
Return the (signed) length of the projection of vector v on vector w.
viewport.modifierName(mod)
viewport.setOpenGLFormat()

Set the correct OpenGL format.

On a correctly installed system, the default should do well. The default OpenGL format can be changed by command line options:

--dri   : use the Direct Rendering Infrastructure
--nodri : do not use the DRI
--alpha : enable the alpha buffer 
viewport.getOpenGLContext()
viewport.OpenGLFormat(fmt=None)
Some information about the OpenGL format.
viewport.printOpenGLContext(ctxt)

Documentation

Previous topic

20. canvas — This implements an OpenGL drawing widget for painting 3D scenes.

Next topic

22. camera — OpenGL camera handling

This Page