コード例 #1
0
def parseArgs(argv):
    """Parses the given ``fsleyes`` command line arguments. See the
    :mod:`.parseargs` module for details on the ``fsleyes`` command
    line interface.

    :arg argv: command line arguments for ``fsleyes``.
    """

    import fsleyes.parseargs as parseargs
    import fsleyes.layouts as layouts
    import fsleyes.version as version

    parser = parseargs.ArgumentParser(
        add_help=False, formatter_class=parseargs.FSLeyesHelpFormatter)

    serveraction = ft.partial(cliserver.CLIServerAction, allArgs=argv)

    parser.add_argument('-r',
                        '--runscript',
                        metavar='SCRIPTFILE',
                        help='Run custom FSLeyes script')
    parser.add_argument('-cs',
                        '--cliserver',
                        action=serveraction,
                        help='Pass all command-line arguments '
                        'to a single FSLeyes instance')

    # We include the list of available
    # layouts in the help description
    allLayouts  = list(layouts.BUILT_IN_LAYOUTS.keys()) + \
                  list(layouts.getAllLayouts())
    name = 'fsleyes'
    prolog = 'FSLeyes version {}\n'.format(version.__version__)
    description = textwrap.dedent("""\
        FSLeyes - the FSL image viewer.

        Use the '--scene' option to load a saved layout ({layouts}).

        If no '--scene' is specified, a default layout is shown or the
        previous layout is restored. If a script is provided via
        the '--runscript' argument, it is assumed that the script sets
        up the scene.
        """.format(layouts=', '.join(allLayouts)))

    # Options for configuring the scene are
    # managed by the parseargs module
    return parseargs.parseArgs(parser,
                               argv,
                               name,
                               prolog=prolog,
                               desc=description,
                               argOpts=['-r', '--runscript'])
コード例 #2
0
    def __saveLayout(self):
        """Save the current :class:`.FSLeyesFrame` layout.  The user is
        prompted to enter a name, and the current frame layout is saved
        via the :func:`.layouts.saveLayout` function.
        """

        import wx

        builtIns = list(layouts.BUILT_IN_LAYOUTS.keys())
        saved = layouts.getAllLayouts()

        while True:
            dlg = wx.TextEntryDialog(self.__frame,
                                     message=strings.messages[self,
                                                              'enterName'])

            if dlg.ShowModal() != wx.ID_OK:
                return

            name = dlg.GetValue()

            if name.strip() == '':
                return

            # Not allowed to use built-in layout names
            if name in builtIns:
                dlg = wx.MessageDialog(
                    self.__frame,
                    message=strings.messages[self,
                                             'nameIsBuiltIn'].format(name),
                    style=(wx.ICON_EXCLAMATION | wx.OK))
                dlg.ShowModal()
                continue

            # Name collision - confirm overwrite
            if name in saved:
                dlg = wx.MessageDialog(
                    self.__frame,
                    message=strings.messages[self,
                                             'confirmOverwrite'].format(name),
                    style=(wx.ICON_QUESTION | wx.YES_NO | wx.NO_DEFAULT))

                if dlg.ShowModal() == wx.ID_NO:
                    continue

            break

        layouts.saveLayout(self.__frame, name)

        self.__frame.refreshLayoutMenu()
コード例 #3
0
    def __clearLayouts(self):
        """Deletes all saved layouts. Gets the user to confirm that
        they want to proceed before doing so.
        """

        import wx

        dlg = wx.MessageDialog(wx.GetTopLevelWindows()[0],
                               message=strings.messages[self, 'confirmClear'],
                               caption=strings.titles[self, 'confirmClear'],
                               style=(wx.ICON_WARNING | wx.YES_NO
                                      | wx.NO_DEFAULT))

        if dlg.ShowModal() != wx.ID_YES:
            return

        for l in layouts.getAllLayouts():
            layouts.removeLayout(l)

        self.__frame.refreshLayoutMenu()