The draw module provides the basic user interface to the OpenGL rendering capabilities of pyFormex. The full contents of this module is available to scripts running in the pyFormex GUI without the need to import it.
Classes defined in module draw
Functions defined in module draw
Close the GUI.
Calling this function from a script closes the GUI and terminates pyFormex.
Close the named dialog.
Closes the InputDialog with the given name. If multiple dialogs are open with the same name, all these dialogs are closed.
This only works for dialogs owned by the pyFormex GUI.
Show a short message widget and wait for user acknowledgement.
There are three levels of messages: ‘info’, ‘warning’ and ‘error’. They differ only in the icon that is shown next to the test. By default, the message widget has a single button with the text ‘OK’. The dialog is closed if the user clicks a button. The return value is the button text.
Show an informational message and wait for user acknowledgement.
Show a warning message and wait for user acknowledgement.
Show an error message and wait for user acknowledgement.
Ask a question and present possible answers.
Return answer if accepted or default if rejected. The remaining arguments are passed to the InputDialog getResult method.
Show a Yes/No question and return True/False depending on answer.
Display a text in a dialog window.
Creates a dialog window displaying some text. The dialog can be modal (blocking user input to the main window) or modeless. Scrollbars are added if the text is too large to display at once. By default, the dialog has a single button to close the dialog.
Parameters:
Returns:
Modal dialog: | the result of the dialog after closing. The result is a dictionary with a single key: ‘text’ having the displayed text as a value. If an itemtype ‘text’ was used, this may be a changed text. |
---|---|
Modeless dialog: | |
the open dialog window itself. |
Display a text file.
This will use the showText() function to display a text read from a file. By default this uses a monospaced font. Other arguments may also be passed to ShowText.
Show the docstring of an object.
Parameters:
Load a file into the editor.
Parameters:
Loading a file in the editor is done by executing an external command with the filename as argument. The command to be used can be set in the configuration. If none is set, pyFormex will try to lok at the EDITOR and VISUAL environment settings.
The main author of pyFormex uses ‘emacsclient’ as editor command, to load the files in a running copy of Emacs.
Ask the value of some items to the user.
Create an interactive widget to let the user set the value of some items. The items are specified as a list of dictionaries. Each dictionary contains the input arguments for a widgets.InputItem. It is often convenient to use one of the _I, _G, ot _T functions to create these dictionaries. These will respectively create the input for a simpleInputItem, a groupInputItem or a tabInputItem.
For convenience, simple items can also be specified as a tuple. A tuple (key,value) will be transformed to a dict {‘key’:key, ‘value’:value}.
See the widgets.InputDialog class for complete description of the available input items.
A timeout (in seconds) can be specified to have the input dialog interrupted automatically and return the default values.
The remaining arguments are keyword arguments that are passed to the widgets.InputDialog.getResult method.
Returns a dictionary with the results: for each input item there is a (key,value) pair. Returns an empty dictionary if the dialog was canceled. Sets the dialog timeout and accepted status in global variables.
Returns the current dialog widget.
This returns the dialog widget created by the askItems() function, while the dialog is still active. If no askItems() has been called or if the user already closed the dialog, None is returned.
Returns True if the last askItems() dialog was accepted.
Returns True if the last askItems() dialog was rejected.
Returns True if the last askItems() dialog timed out.
Ask for a file name or multiple file names using a file dialog.
cur is a directory or filename. All the files matching the filter in that directory (or that file’s directory) will be shown. If cur is a file, it will be selected as the current filename.
Unless the user cancels the operation, or the change parameter was set to False, the parent directory of the selected file will become the new working directory.
Ask a single new filename.
This is a convenience function for calling askFilename with the arguments exist=False.
Interactively select a directory and change the current workdir.
The user is asked to select a directory through the standard file dialog. Initially, the dialog shows all the subdirectories in the specified path, or by default in the current working directory.
The selected directory becomes the new working directory, unless the user canceled the operation, or the change parameter was set to False.
Ask the user to change the current workdir if it is not writable.
Returns True if the new workdir is writable.
Print a message on the message board.
If a logfile was opened, the message is also written to the log file.
Print a message on the message board.
If a logfile was opened, the message is also written to the log file.
Flatten a list of geometric objects.
Each item in the list should be either:
This function will flatten the lists and replace the string items with the object they point to. The result is a single list of drawable objects. This function does not enforce the objects to be drawable. That should be done by the caller.
Filters the drawable objects from a list.
The input is a list, usually of drawable objects. For each item in the list, the following is done:
The result is a list of drawable objects (since a Formex is drawable).
Draw object(s) with specified settings and options.
This is the main drawing function to get geometry rendered on the OpenGL canvas. It has a whole slew of arguments, but in most cases you will only need to use a few of them. We divide the arguments in three groups: geometry, settings, options.
Geometry: specifies what objects will be drawn.
F: all geometry to be drawn is specified in this single argument. It can be one of the following:
The possibility of a nested list means that any complex collections of geometry can be drawn in a single operations. The (nested) list is recursively flattened, replacing string values by the corresponding value from the pyFormex global variables dictionary, until a single list of drawable objects results. Next the undrawable items are removed from the list. The resulting list of drawable objects will then be drawn using the remaining settings and options arguments.
be passed to the corresponding Actor for the object. The Actor is the graphical representation of the geometry. Not all Actors use all of the settings that can be specified here. But they all accept specifying any setting even if unused. The settings hereafter are thus a superset of the settings used by the different Actors. Settings have a default value per viewport, and if unspecified, most Actors will use the viewport default for that value.
If None, they are filled in from the current viewport drawing options. These can be changed with the setDrawOptions() function. The initial defaults are: view=’last’, bbox=’auto’, shrink=False, clear=False, shrinkfactor=0.8.
Specifying color:
Color specification can take many different forms. Some Actors recognize up to six different color modes and the draw function adds even another mode (property color)
Element and vertex color modes are usually only used with a single object in the F parameter, because they require a matching set of colors. Though the color set will be automatically resized if not matching, the result will seldomly be what the user expects. If single colors are specified as a tuple of three float values (see below), the correct size of a color array for an object with nelems elements of plexitude nplex would be: (nelems,3) in element color mode, and (nelems,nplex,3) in vertex color mode. In the index modes, color would then be an integer array with shape respectively (nelems,) and (nelems,nplex). Their values are indices in the colormap array, which could then have shape (ncolors,3), where ncolors would be larger than the highest used value in the index. If the colormap is insufficiently large, it will again be wrapped around. If no colormap is specified, the current viewport colormap is used. The default contains eight colors: black=0, red=1, green=2, blue=3, cyan=4, magenta=5, yellow=6, white=7.
A color value can be specified in multiple ways, but should be convertible to a normalized OpenGL color using the colors.GLcolor() function. The normalized color value is a tuple of three values in the range 0.0..1.0. The values are the contributions of the red, green and blue components.
Move the camera thus that object comes fully into view.
object can be anything having a bbox() method or a list thereof. if no view is given, the default is used.
The camera is moved with fixed axis directions to a place where the whole object can be viewed using a 45. degrees lens opening. This technique may change in future!
Set default values for the draw options.
Draw options are a set of options that hold default values for the draw() function arguments and for some canvas settings. The draw options can be specified either as a dictionary, or as keyword arguments.
reset the canvas
Set shrinking on or off, and optionally set shrink factor
Draw a set of vectors.
If size==None, draws the vectors v at the points P. If size is specified, draws the vectors size*normalize(v) P, v and size are single points or sets of points. If sets, they should be of the same size.
Other drawoptions can be specified and will be passed to the draw function.
Draw a list of marks at points X.
X is a Coords array. M is a list with the same length as X. The string representation of the marks are drawn at the corresponding 3D coordinate.
Draw the feature edges of a Mesh
Draw numbers on all elements of F.
numbers is an array with F.nelems() integer numbers. If no numbers are given, the range from 0 to nelems()-1 is used. Normally, the numbers are drawn at the centroids of the elements. A translation may be given to put the numbers out of the centroids, e.g. to put them in front of the objects to make them visible, or to allow to view a mark at the centroids. If an offset is specified, it is added to the shown numbers.
Draw property numbers on all elements of F.
This calls drawNumbers to draw the property numbers on the elements. All arguments of drawNumbers except numbers may be passed. If the object F thus not have property numbers, -1 values are drawn.
Draw (local) numbers on all vertices of F.
Normally, the numbers are drawn at the location of the vertices. A translation may be given to put the numbers out of the location, e.g. to put them in front of the objects to make them visible, or to allow to view a mark at the vertices.
Draw the bounding box of the geometric object F.
F is any object that has a bbox method. Returns the drawn Annotation.
Draw the principal axes of the geometric object F.
F is any object that has a coords attribute. If specified, weight is an array of weights attributed to the points of F. It should have the same length as F.coords.
Draw a text at a 3D point P.
Draw the axes of a CoordinateSystem.
CS is a CoordinateSystem. If not specified, the global coordinate system is used. Other arguments can be added just like in the AxesActor class.
While you can draw a CoordinateSystem using the draw() function, this function gives a better result because it has specialized color and annotation settings and provides reasonable deafults.
Draw an image as a colored Formex
Draws a raster image as a colored Formex. While there are other and better ways to display an image in pyFormex (such as using the imageView widget), this function allows for interactive handling the image using the OpenGL infrastructure.
Parameters:
Returns the drawn Actor.
See also drawImage().
Draws an image as a viewport decoration.
Parameters:
Returns the Decoration drawn.
Note that the Decoration has a fixed size (and position) on the canvas and will not scale when the viewport size is changed. The bgcolor() function can be used to draw an image that completely fills the background.
Draw two viewport axes at a 3D position.
Draw an actor and update the screen.
Draw an Actor/Annotation/Decoration and update the screen.
Remove an item or a number of items from the canvas.
Use the return value from one of the draw... functions to remove the item that was drawn from the canvas. A single item or a list of items may be specified.
Show a named view, either a builtin or a user defined.
This shows the current scene from another viewing angle. Switching views of a scene is much faster than redrawing a scene. Therefore this function is prefered over draw() when the actors in the scene remain unchanged and only the camera viewpoint changes.
Just like draw(), this function obeys the drawing lock mechanism, and by default it will restart the lock to retard the next draing operation.
Toggle the display of the global axes on or off.
If on is True, the axes triade is displayed, if False it is removed. The default (None) toggles between on and off.
Show a text at position x,y using font.
Draw an annotation.
Draw a decoration.
Create a new named view (or redefine an old).
The angles are (longitude, latitude, twist). By default, the view is local to the script’s viewport. If gui is True, it is also added to the GUI.
Set the default view for future drawing operations.
If no angles are specified, the name should be an existing view, or the predefined value ‘last’. If angles are specified, this is equivalent to createView(name,angles) followed by setView(name).
Change the background color and image.
Parameters:
Set the default foreground color.
Set the highlight color.
Gets/Sets the current canvas color map
Return the index of a color in the current colormap
Return a list of predefined render profiles.
Change the rendering profile to a predefined mode.
Currently the following modes are defined:
Change the wire rendering mode.
Currently the following modes are defined: ‘none’, ‘border’, ‘feature’,’all’
Set the lights on or off
Set the transparency mode on or off.
Set the value of one of the material lighting parameters
typ is one of ‘ambient’,’specular’,’emission’,’shininess’ val is a value between 0.0 and 1.0
Set the linewidth to be used in line drawings.
Set the linewidth to be used in line drawings.
Set the size to be used in point drawings.
Resize the canvas to (width x height).
If a negative value is given for either width or height, the corresponding size is set equal to the maximum visible size (the size of the central widget of the main window).
Note that changing the canvas size when multiple viewports are active is not approved.
Clear the canvas.
This is a low level function not intended for the user.
Clear the canvas.
Removes everything from the current scene and displays an empty background.
This function waits for the drawing lock to be released, but will not reset it.
Get/Set the draw delay time.
Returns the current setting of the draw wait time (in seconds). This drawing delay is obeyed by drawing and viewing operations.
A parameter may be given to set the delay time to a new value. It should be convertable to a float. The function still returns the old setting. This may be practical to save that value to restore it later.
Wait until the drawing lock is released.
This uses the drawing lock mechanism to pause. The drawing lock ensures that subsequent draws are retarded to give the user the time to view. The use of this function is prefered over that of pause() or sleep(), because it allows your script to continue the numerical computations while waiting to draw the next screen.
This function can be used to retard other functions than draw and view.
Start the current script or if already running, continue it.
Replay the current app.
This works pretty much like the play() function, but will reload the current application prior to running it. This function is especially interesting during development of an application. If the current application is a script, then it is equivalent with play().
Releases the drawing lock mechanism indefinely.
Releasing the drawing lock indefinely means that the lock will not be set again and your script will execute till the end.
Pause the execution until an external event occurs or timeout.
When the pause statement is executed, execution of the pyformex script is suspended until some external event forces it to proceed again. Clicking the PLAY, STEP or CONTINUE button will produce such an event.
Zoom a rectangle selected by the user.
Zoom thus that the specified bbox becomes visible.
Zoom thus that all actors become visible.
Fly through the current scene along the specified path.
This function moves the camera through the subsequent elements of the Formex. For each element the first point is used as the center of the camera and the second point as the eye (the center of the scene looked at). For a 3-plex Formex, the third point is used to define the upvector (i.e. the vertical axis of the image) of the camera. For a 2-plex Formex, the upvector is constant as specified in the arguments.
Select the current viewport.
n is an integer number in the range of the number of viewports, or is one of the viewport objects in pyformex.GUI.viewports
if n is None, selects the current GUI viewport for drawing
Return the number of viewports.
Set the viewports layout.
Add a new viewport.
Remove the last viewport.
Link viewport vp to viewport tovp.
Both vp and tovp should be numbers of viewports.
Update the GUI.
Highlight an actor in the scene.
Remove the highlights from the current viewport
Enter interactive picking mode and return selection.
See viewport.py for more details. This function differs in that it provides default highlighting during the picking operation, a button to stop the selection operation
Parameters:
Set the drawing edit mode.
Enter interactive drawing mode and return the line drawing.
See viewport.py for more details. This function differs in that it provides default displaying during the drawing operation and a button to stop the drawing operation.
The drawing can be edited using the methods ‘undo’, ‘clear’ and ‘close’, which are presented in a combobox.
Show a line drawing.
L is usually the return value of an interactive draw operation, but might also be set by the user.
Export the current scene to WebGL.
fn is the (relative or absolute) pathname of the .html and .js files to be created.
Returns the absolute pathname of the generated .html file.
Show an URL in the browser
Show a local .html file in the browser
Reset the GUI to its default operating mode.
When an exception is raised during the execution of a script, the GUI may be left in a non-consistent state. This function may be called to reset most of the GUI components to their default operating mode.