Create 3D graphical representations.
The draw module provides the basic user interface to the OpenGL rendering capabilities of pyFOrmex.
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.
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.
Display a text and wait for user response.
This can display a large text and will add scrollbars when needed.
Ask the value of some items to the user.
Create an interactive widget to let the user set the value of some items. Input is a list of input items (basically [key,value] pairs). See the widgets.InputDialog class for complete description of the available input items.
The remaining arguments are keyword arguments that are passed to the InputDialog.getResult method. A timeout (in seconds) can be specified to have the input dialog interrupted automatically.
Return 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.
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.
Ask for an existing directory name.
The dialog pops up where the user can interactively select a directory. Initially, the dialog will show all the subdirectories in the specified path, or by default in the current workdir.
Unless the user cancels the operation, or the change parameter was set to False, the selected directory will become the new working directory.
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.
Draw object(s) with specified settings and direct camera to it.
The first argument is an object to be drawn. All other arguments are settings that influence how the object is being drawn.
F is either a Formex or a TriSurface object, or a name of such object (global or exported), or a list thereof. If F is a list, the draw() function is called repeatedly with each of ithe items of the list as first argument and with the remaining arguments unchanged.
The remaining arguments are drawing options. If None, they are filled in from the current viewport drawing options.
view is either the name of a defined view or ‘last’ or None. Predefined views are ‘front’,’back’,’top’,’bottom’,’left’,’right’,’iso’. With view=None the camera settings remain unchanged (but might be changed interactively through the user interface). This may make the drawn object out of view! With view=’last’, the camera angles will be set to the same camera angles as in the last draw operation, undoing any interactive changes. The initial default view is ‘front’ (looking in the -z direction).
bbox specifies the 3D volume at which the camera will be aimed (using the angles set by view). The camera position wil be set so that the volume comes in view using the current lens (default 45 degrees). bbox is a list of two points or compatible (array with shape (2,3)). Setting the bbox to a volume not enclosing the object may make the object invisible on the canvas. The special value bbox=’auto’ will use the bounding box of the objects getting drawn (object.bbox()), thus ensuring that the camera will focus on these objects. The special value bbox=None will use the bounding box of the previous drawing operation, thus ensuring that the camera’s target volume remains unchanged.
color,colormap,linewidth,alpha,marksize are passed to the creation of the 3D actor.
shrink is a floating point shrink factor that will be applied to object before drawing it.
If the Formex has properties and a color list is specified, then the the properties will be used as an index in the color list and each member will be drawn with the resulting color. If color is one color value, the whole Formex will be drawn with that color. Finally, if color=None is specified, the whole Formex is drawn in black.
Each draw action activates a locking mechanism for the next draw action, which will only be allowed after drawdelay seconds have elapsed. This makes it easier to see subsequent images and is far more elegant that an explicit sleep() operation, because all script processing will continue up to the next drawing instruction. The value of drawdelay is set in the config, or 2 seconds by default. The user can disable the wait cycle for the next draw operation by specifying wait=False. Setting drawdelay=0 will disable the waiting mechanism for all subsequent draw statements (until set >0 again).
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!
Interactively ask the Drawing options from the user.
A dictionary may be specified to override the current defaults.
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).
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 numbers on all elements of F.
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 (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.
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.
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.
Create a new named view (or redefine an old).
The angles are (longitude, latitude, twist). If the view name is new, and there is a views toolbar, a view button will be added to it.
Change the background color (and redraw).
If one color is given, the background is a solid color. If two colors are given, the background color will get a vertical gradient with color on top and color2 at the bottom.
Set the value of one of the lighting parameters for the currrent view
typ is one of ‘ambient’,’specular’,’emission’,’shininess’ val is a value between 0.0 and 1.0
Clear the canvas.
This is a low level function not intended for the user.
Pause the execution until an external event occurs.
When the pause statement is executed, execution of the pyformex script is suspended until some external event forces it to proceed again. Clicking the STEP or CONTINUE button will produce such an event.
Perform one step of a script.
A step is a set of instructions until the next draw operation. If a script is running, this just releases the draw lock. Else, it starts the script in step mode.
Wake up from the sleep function.
This is the only way to exit the sleep() function. Default is to wake up from the current sleep. A mode > 0 forces wakeup for longer period.
Link viewport vp to viewport tovp.
Both vp and tovp should be numbers of viewports.
Highlight a selection of actors on the canvas.
K is Collection of actors as returned by the pick() method. colormap is a list of two colors, for the actors not in, resp. in the Collection K.
Highlight a selection of actor elements on the canvas.
K is Collection of actor elements as returned by the pick() method. colormap is a list of two colors, for the elements not in, resp. in the Collection K.
Highlight a selection of actor edges on the canvas.
K is Collection of TriSurface actor edges as returned by the pick() method. colormap is a list of two colors, for the edges not in, resp. in the Collection K.
Highlight a selection of actor elements on the canvas.
K is Collection of actor elements as returned by the pick() method.
Highlight a selection of partitions on the canvas.
K is a Collection of actor elements, where each actor element is connected to a collection of property numbers, as returned by the partitionCollection() method.
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
If no filter is given, the available filters are presented in a combobox.
Highlight a Collection of actor/elements.
K is usually the return value of a pick operation, but might also be set by the user. mode is one of the pick modes.
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.