The vizdragdrop module allows you to drag and drop files on the Vizard graphics window. It supports dropping one or more files at the same time. When a file is dropped an event is generated that provides the pathname of the file and the mouse position to the registered callback function. This can used as a way to add models and other types of resources to the scene at runtime.
To see how this works, run the following script and drop the vcc_male.cfg file (found in the resources folder of the Vizard installation) on the graphics window:
The following commands enable and disable file drag/drop:
Command |
Description |
vizdragdrop.enable() |
Enables file drag/drop on the Vizard window. |
vizdragdrop.disable() |
Disables file drag/drop on the Vizard window. |
When drap/drop is enabled and a file is dragged on the graphics window a drag/drop marker with "+" sign will appear that follows the mouse cursor. Once the file is dropped a vizdragdrop.DROP_FILE_EVENT is generated. Use the following command for registering a callback function to handle this event:
Command |
Description |
vizdragdrop.onDropFile(pattern, func, *args, **kw) |
Registers the function that gets called when a filename matching the specified pattern is dropped. If pattern is None, then all dropped files will be passed to the function.
func: The function being registered. An event object e, described in the table below, will be passed to this callback function.
*args: Optional arguments to pass to the registered function.
**kw: Optional keyword arguments to pass to the registered function. |
The drop event provides a single event object e that gets passed to the callback function. The table below lists the object's attributes:
Attribute |
Description |
e.filenames |
A list that holds the pathname(s) of the file(s) dropped |
e.pos_normalized |
Mouse position in normalized window coordinates |
e.pos_pixels |
Mouse position in pixel window coordinates |
e.pos |
Same as e.pos_normalized |
The following example uses the mouse position at drop time to determine where an avatar should be placed. Run the script and individually drop the vcc_male.cfg and vcc_female.cfg files on the graphics window (These files can be found in the resources folder of the Vizard installation). To change the position of an avatar drop it's .cfg file again in a new location: