File: utils.py

package info (click to toggle)
mayavi2 4.8.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,892 kB
  • sloc: python: 49,447; javascript: 32,885; makefile: 129; fortran: 60
file content (36 lines) | stat: -rw-r--r-- 1,417 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Collection of utility functions common to different toolkits.
"""

def popup_save(parent=None):
    """Popup a dialog asking for an image name to save the scene to.
    This is used mainly to save a scene in full screen mode. Returns a
    filename, returns empty string if action was cancelled. `parent` is
    the parent widget over which the dialog will be popped up.
    """
    from pyface.api import FileDialog, OK

    extensions = ['*.png', '*.jpg', '*.tiff', '*.bmp', '*.ps',
                  '*.eps', '*.pdf', '*.tex', '*.rib', '*.wrl',
                  '*.oogl', '*.vrml', '*.obj', '*.iv', '*.pov',
                  '*.x3d']
    descriptions = ["PNG", "JPG", "TIFF", "Bitmap", "PostScript",
                    "EPS", "PDF", "Tex", "RIB", "WRL",
                    "Geomview", "VRML", "Wavefront", "Open Inventor",
                    "Povray", "X3D"]
    wildcard = ""
    for description, extension in zip(descriptions, extensions):
        wildcard += "{} ({})|{}|".format(description,
                                         extension,
                                         extension)
    wildcard += "Determine by extension (*.*)|(*.*)"

    dialog = FileDialog(
        parent=parent, title='Save scene to image',
        action='save as', default_filename="snapshot.png",
        wildcard=wildcard
    )
    if dialog.open() == OK:
        return dialog.path
    else:
        return ''