Пример #1
0
def multiWebGL():
    """Export the current scene as a model in a multiscene WebGL

    The user is asked for a file name to store the exported model,
    and after export, whether to load the model in the browser.
    """
    global last_exported_webgl
    last_exported_webgl = None
    if draw.the_multiWebGL is None:
        print("NO CURRENT EXPORT")
    else:
        print("CURRENTLY EXPORTED: %s" % draw.the_multiWebGL.scenes)

    if draw.the_multiWebGL is None:
        fn = draw.askNewFilename(pf.cfg['workdir'], 'html')
        if fn:
            print("Exporting multiscene WebGL to %s" % fn)
            draw.multiWebGL(fn=fn)
            print(draw.the_multiWebGL)

    if draw.the_multiWebGL is not None:
        res = draw.askItems([
            _I('name',draw.the_multiWebGL.name,text='Name of the scene',tooltip='An empty name will skip the export of the current scene'),
            _I('finish',False,text='Finish the export'),
            ])
        if res['name']:
            draw.multiWebGL(res['name'])
        if res['finish']:
            last_exported_webgl = draw.multiWebGL()
Пример #2
0
def importProject():
    """Import an existing project.

    Ask the user to select an existing project file, and then import
    all or selected data from it into the current project.
    """
    proj = openProject(exist=True, access='r')
    if proj: # only if non-empty
        keys = proj.contents()
        res = draw.askItems(
            [   _I('mode', choices=['All', 'Defined', 'Undefined', 'Selected', 'None'], itemtype='radio'),
                _I('selected', choices=keys, itemtype='list'),
                ],
            caption='Select variables to import',
            )
        if res:
            mode = res['mode'][0]
            if mode == 'A':
                pass
            elif mode == 'D':
                proj = utils.selectDict(proj, pf.PF)
            elif mode == 'U':
                proj = utils.removeDict(proj, pf.PF)
            elif mode == 'S':
                proj = utils.selectDict(proj, res['selected'])
            elif mode == 'N':
                return
            print("Importing symbols: %s" % proj.contents())
            pf.PF.update(proj)
            listProject()
Пример #3
0
def createMovieInteractive():
    """Create a movie from a saved sequence of images.

    """
    if not image.multisave:
        pf.warning('You need to start multisave mode first!')
        return

    names = image.multisave[0]
    glob = names.glob()

    res = draw.askItems(
        [ _I('files', glob),
          _I('encoder', choices=['mencoder', 'convert', 'ffmpeg']),
          _G('Mencoder', [
              _I('fps', 10),
              _I('vbirate', 800),
              ]),
          _G('Convert', [
              _I('delay', 1),
              _I('colors', 256),
              ]),
          ],
        enablers = [
            ('encoder', 'mencoder', 'Mencoder'),
            ('encoder', 'convert', 'Convert'),
          ])
    if not res:
        return

    pf.GUI.setBusy()
    image.createMovie(**res)
    pf.GUI.setBusy(False)
Пример #4
0
def drawOptions(d={}):
    """Set the Drawing options.

    A dictionary may be specified to override the current defaults.
    """
    draw.setDrawOptions(d)
    print(pf.canvas.drawoptions)
    res = draw.askItems(
        store=pf.canvas.drawoptions,
        items=[
            _I('view',
               choices=['None'] + pf.canvas.view_angles.keys(),
               tooltip="Camera viewing direction"),
            _I('bbox',
               choices=['auto', 'last'],
               tooltip="Automatically focus/zoom on the last drawn object(s)"),
            _I('clear', tooltip="Clear the canvas on each drawing action"),
            _I('shrink',
               tooltip=
               "Shrink all elements to make their borders better visible"),
            _I('shrink_factor'),
            _I('marksize'),
        ],
        enablers=[('shrink', True, 'shrink_factor')])
    if not res:
        return
    if res['view'] == 'None':
        res['view'] = None
    draw.setDrawOptions(res)
Пример #5
0
def viewportLayout():
    """Set the viewport layout."""
    directions = ['rowwise', 'columnwise']
    if pf.GUI.viewports.rowwise:
        current = directions[0]
    else:
        current = directions[1]
    res = draw.askItems([
        _I('Number of viewports', len(pf.GUI.viewports.all)),
        _I('Viewport layout direction', current, choices=directions),
        _I('Number of viewports per row/column', pf.GUI.viewports.ncols),
    ],
                        caption='Config Dialog')

    if res:
        pf.debug(res)
        nvps = res['Number of viewports']
        rowwise = res['Viewport layout direction'] == 'rowwise'
        ncols = res['Number of viewports per row/column']
        if rowwise:
            nrows = None
        else:
            nrows = ncols
            ncols = None
        pf.GUI.viewports.changeLayout(nvps, ncols, nrows)
Пример #6
0
def setCanvasSize():
    """Save the current viewport size"""
    res = draw.askItems(
        [_I('w', pf.canvas.width()),
         _I('h', pf.canvas.height())],
        caption='Set Canvas Size')
    if res:
        draw.canvasSize(res['w'], res['h'])
Пример #7
0
def setOptions():
    options = [ 'redirect', 'debuglevel', 'rst2html']
    options = [ o for o in options if hasattr(pf.options, o) ]
    items = [ _I(o, getattr(pf.options, o)) for o in options ]
    res = draw.askItems(items)
    if res:
        print(res)
        for o in options:
            setattr(pf.options, o, res[o])
            print("Options: %s" % pf.options)
            if o == 'redirect':
                pf.GUI.board.redirect(pf.options.redirect)
Пример #8
0
def setDebug():
    options = [ o for o in dir(pf.DEBUG) if o[0] != '_' ]
    options.remove('ALL')
    options.remove('NONE')
    values = [ getattr(pf.DEBUG, o) for o in options ]
    items = [ _I(o, bool(pf.options.debuglevel & v)) for o, v in zip(options, values) ]
    res = draw.askItems(items)
    if res:
        print(res)
        debug = 0
        for o, v in zip(options, values):
            if res[o]:
                debug |= v
        print("debuglevel = %s" % debug)
        pf.options.debuglevel = debug
Пример #9
0
def actorDialog(actorids):
    """Create an actor dialog for the specified actors (by index)

    """
    from pyformex.gui.draw import _T, _G, _I, askItems
    print("actorDialog %s" % actorids)
    actors = [ pf.canvas.actors[i] for i in actorids ]
    items = [ _T("actor_%s" % i, [
        _I('name', str(a.name)),
        _I('type', str(a.getType()), readonly=True),
        _I('visible', bool(a.visible)),
        _I('alpha', float(a.alpha)),
        _I('objcolor', str(a.objcolor), itemtype='color'),
        ]) for i, a in zip(actorids, actors) ]
    res = askItems(items)
    print(res)
Пример #10
0
def setTriade():
    try:
        pos = pf.canvas.triade.pos
        size = pf.canvas.triade.size
    except:
        pos = 'lb'
        size = 50
    res = draw.askItems([
        _I('triade', True),
        _I('pos',
           pos,
           choices=['lt', 'lc', 'lb', 'ct', 'cc', 'cb', 'rt', 'rc', 'rb']),
        _I('size', size),
    ])
    if res:
        draw.setTriade(res['triade'], res['pos'], res['size'])
Пример #11
0
 def runAllApps(self):
     from pyformex.gui import draw
     res = draw.askItems([
         ('timeout', True),
         ('random', False),
         ('recursive', True),
         ('count', -1),
     ])
     if not res:
         return
     from pyformex.gui.toolbar import timeout
     timeout(res['timeout'])
     del res['timeout']
     self.runAll(**res)
     timeout(False)
     print("Finished running all examples")
Пример #12
0
def searchIndex():
    """Search text in pyFormex refman index.

    Asks a pattern from the user and searches for it the index of the
    local pyFormex documentation. Displays the results in the browser.
    """
    from pyformex.gui.draw import _I
    res = draw.askItems([
        _I('text', '', text='String to search'),
    ])

    if res:
        print(
            "file://%s/doc/html/search.html?q=%s&check_keywords=yes&area=default"
            % (pf.cfg['pyformexdir'], res['text']))
        showURL(
            "file://%s/doc/html/search.html?q=%s&check_keywords=yes&area=default"
            % (pf.cfg['pyformexdir'], res['text']))
Пример #13
0
def searchText():
    """Search text in pyFormex source files.

    Asks a pattern from the user and searches for it through all
    the pyFormex source files.
    """
    from pyformex.gui.draw import _I
    res = draw.askItems([
        _I('pattern', '', text='String to grep'),
        _I('options',
           '',
           text='Options',
           tooltip=
           "Some cool options: -a (extended search), -i (ignore case), -f (literal string), -e (extended regexp)"
           ),
    ])

    if res:
        out = utils.grepSource(relative=False, **res)
        draw.showText(out, mono=True, modal=False)
Пример #14
0
def setLineWidth():
    """Change the default line width."""
    res = draw.askItems([_I('Line Width', pf.canvas.settings.linewidth)],
                        'Choose default line width')
    if res:
        pf.canvas.setLineWidth(res['Line Width'])