Exemplo n.º 1
0
def test_compareVersions_ignorePoint():

    tests = [

        ('0.0.0', '0.0.0',   0),
        ('0.0.0', '0.0.5',   0),
        ('0.0.0', '0.1.0',  -1),
        ('0.0.0', '0.1.5',  -1),

        ('0.1.0', '0.1.10',  0),
        ('0.1.0', '0.2.0',  -1),
        ('0.1.0', '0.2.10', -1),

        ('1.0.0', '1.0.10',  0),
        ('1.0.0', '1.0.10',  0),
        ('1.0.0', '1.1.0',  -1),
        ('1.0.0', '1.1.10', -1),
        ('1.0.0', '2.0.0',  -1),
        ('1.0.0', '2.0.10', -1),
    ]


    for v1, v2, expected in tests:
        assert fslversion.compareVersions(v1, v2, ignorePoint=True) ==  expected
        assert fslversion.compareVersions(v2, v1, ignorePoint=True) == -expected
Exemplo n.º 2
0
def test_compareVersions():
    tests = [
        ('0.0.0',    '0.0.0',    0),
        ('0.0.10',   '0.0.10',   0),
        ('0.10.0',   '0.10.0',   0),
        ('10.0.0',   '10.0.0',   0),
        ('10.0.10',  '10.0.10',  0),
        ('10.10.0',  '10.10.0',  0),
        ('10.10.10', '10.10.10', 0),

        ('0.0.0',  '0.0.1',  -1),
        ('0.0.0',  '0.1.0',  -1),
        ('0.0.5',  '0.1.0',  -1),
        ('0.0.5',  '0.1.5',  -1),
        ('0.0.5',  '0.1.10', -1),

        ('0.0.0',  '1.0.0',  -1),
        ('0.0.5',  '1.0.0',  -1),
        ('0.0.5',  '1.0.5',  -1),
        ('0.0.5',  '1.0.10', -1),

        ('0.1.0',  '0.1.1',  -1),
        ('0.1.1',  '0.1.2',  -1),
        ('0.1.10', '0.2.0',  -1),

        ('0.9.9', '1.0.0', -1),
        ('0.9.9', '1.9.9', -1),
        ('1.9.9', '2.0.0', -1),
    ]

    for v1, v2, expected in tests:
        assert fslversion.compareVersions(v1, v2) ==  expected
        assert fslversion.compareVersions(v2, v1) == -expected
Exemplo n.º 3
0
    def __checkForUpdates(self,
                          showUpToDateMessage=True,
                          showErrorMessage=True,
                          ignorePoint=False):
        """Run this action. Downloads a text file from a URL which contains
        the latest available version of FSLeyes. Compares that version with
        the running version. Displays a message to the user.

        :arg showUpToDateMessage: Defaults to ``True``. If ``False``, and
                                  the current version of FSLeyes is up to
                                  date, the user is not informed.

        :arg showErrorMessage:    Defaults to ``True``. If ``False``, and
                                  some error occurs while checking for
                                  updates, the user is not informed.

        :arg ignorePoint:         Defaults to ``False``. If ``True``, the
                                  point release number is ignored in the
                                  comparison.
        """

        errMsg = strings.messages[self, 'newVersionError']
        errTitle = strings.titles[self, 'newVersionError']

        with status.reportIfError(errTitle, errMsg, report=showErrorMessage):

            log.debug('Checking for FSLeyes updates ({})'.format(
                _FSLEYES_VERSION_URL))

            f = request.urlopen(_FSLEYES_VERSION_URL)
            latest = f.read().decode('utf-8').strip()
            current = version.__version__
            upToDate = fslversion.compareVersions(latest, current,
                                                  ignorePoint) <= 0

            log.debug('This version of FSLeyes ({}) is '
                      '{} date (latest: {})'.format(
                          current, 'up to' if upToDate else 'out of', latest))

            if upToDate and not showUpToDateMessage:
                return

            urlMsg = strings.messages[self, 'updateUrl']

            if upToDate:
                title = strings.titles[self, 'upToDate']
                msg = strings.messages[self, 'upToDate']
                msg = msg.format(current)

            else:
                title = strings.titles[self, 'newVersionAvailable']
                msg = strings.messages[self, 'newVersionAvailable']
                msg = msg.format(current, latest, _FSLEYES_URL)

            parent = wx.GetTopLevelWindows()[0]
            dlg = UrlDialog(parent, title, msg, urlMsg, _FSLEYES_URL)

            dlg.CentreOnParent()
            dlg.ShowModal()
Exemplo n.º 4
0
    def __createWXGLContext(self, other=None, target=None):
        """Creates a ``wx.glcanvas.GLContext`` object, assigning it to
        an attribute called ``__context``. Assumes that a
        ``wx.glcanvas.GLCanvas`` has already been created.

        :arg other:  Another `wx.glcanvas.GLContext`` instance with which
                     the new context should share GL state.

        :arg target: If ``other`` is not ``None``, this must be a
                     ``wx.glcanvas.GLCanvas``, the rendering target for the
                     new context.

        .. warning:: This method *must* be called via the ``wx.MainLoop``.
        """

        import                wx
        import wx.glcanvas as wxgl

        # Versions of wxwidgets 3.1 and newer (approximately
        # corresponding to wxpython 4.1 and newer) allow
        # us to select a GL compatibility profile (required,
        # because we rely on GL 1.4/2.1).
        wxver = fwidgets.wxVersion()
        if wxver is not None and \
           fslversion.compareVersions(wxver, '4.1.1') >= 0:
            attrs  = wxgl.GLContextAttrs()
            attrs.CompatibilityProfile()
            attrs.EndList()
            kwargs = {'ctxAttrs' : attrs}
        else:
            kwargs = {}

        log.debug('Creating wx.GLContext')

        if other is not None:
            self.__context = wxgl.GLContext(target, other=other, **kwargs)

        else:
            self.__context = wxgl.GLContext(self.__canvas, **kwargs)

            # We can't set the context target
            # until the dummy canvas is
            # physically shown on the screen.
            while not self.__canvas.IsShownOnScreen():
                wx.GetApp().Yield()

            self.__context.SetCurrent(self.__canvas)
Exemplo n.º 5
0
def _selectPyOpenGLPlatform():
    """Pyopengl sometimes doesn't select a suitable platform, so in some
    circumstances we need to force things (but not if ``PYOPENGL_PLATFORM``
    is already set in the environment).
    """
    if 'PYOPENGL_PLATFORM' in os.environ:
        return

    # If no display, osmesa on all platforms
    if not fwidgets.canHaveGui():
        os.environ['PYOPENGL_PLATFORM'] = 'osmesa'

    # Versions of wxpython 4.1.1 and newer
    # default to using EGL for GL initialisation,
    # but pyopengl doesn't seem to1
    elif fslplatform.os.lower() == 'linux':
        wxver = fwidgets.wxVersion()

        if wxver is not None and \
           fslversion.compareVersions(wxver, '4.1.1') >= 0:
            os.environ['PYOPENGL_PLATFORM'] = 'egl'
Exemplo n.º 6
0
    def displayAttribues():
        """Used within ``__init__`` methods of ``WXGLCanvasTarget``
        sub-classes.

        Return a dict to be passed as keyword arguments to the
        ``wx.glcanvas.GLCanvas.__init__`` method, defining display attributes.
        The ``GLCanvas`` interface changed between wxWidgets 3.0.x and 3.1.x
        (roughly corresponding to wxPython 4.0.x and 4.1.x) - this method
        checks the wxPython version and returns a suitable set of arguments.
        """

        import wx
        import wx.glcanvas as wxgl

        # the format of wx.__version__ is not
        # consistent (e.g. "4.0.7.post2", "4.1.0", etc)
        try:
            version = '.'.join(wx.__version__.split('.')[:3])
        except Exception:
            version = '4.0.0'

        # Use new API for 4.1.0 and newer
        if fslversion.compareVersions(version, '4.1.0') >= 0:
            attrs = wxgl.GLAttributes()
            attrs.MinRGBA(8, 8, 8, 8) \
                 .DoubleBuffer()      \
                 .Depth(24)           \
                 .Stencil(4)          \
                 .EndList()
            kwargs = {'dispAttrs' : attrs}

        else:
            attrs = [wxgl.WX_GL_RGBA,
                     wxgl.WX_GL_DOUBLEBUFFER,
                     wxgl.WX_GL_STENCIL_SIZE, 4,
                     wxgl.WX_GL_DEPTH_SIZE,   24,
                     0,
                     0]
            kwargs = {'attribList' : attrs}
        return kwargs