Ejemplo n.º 1
0
def getQFile(name):
    """Create a QFile from an icon name. Filename is found
    according to supported Qt formats.

    :param str name: Name of the icon, in one of the defined icons
                     in this module.
    :return: Corresponding QFile
    :rtype: qt.QFile
    :raises: ValueError when name is not known
    """
    global _supported_formats
    if _supported_formats is None:
        _supported_formats = []
        supported_formats = qt.supportedImageFormats()
        order = ["mng", "gif", "svg", "png", "jpg"]
        for format_ in order:
            if format_ in supported_formats:
                _supported_formats.append(format_)
        if len(_supported_formats) == 0:
            _logger.error("No format supported for icons")
        else:
            _logger.debug("Format %s supported", ", ".join(_supported_formats))

    for format_ in _supported_formats:
        format_ = str(format_)
        filename = resource_filename('gui/icons/%s.%s' % (name, format_))
        qfile = qt.QFile(filename)
        if qfile.exists():
            return qfile

    qfile = silx_icons.getQFile(name)
    if qfile.exists():
        return qfile

    raise ValueError('Not an icon name: %s' % name)
Ejemplo n.º 2
0
def getQFile(name):
    """Create a QFile from an icon name. Filename is found
    according to supported Qt formats.

    :param str name: Name of the icon, in one of the defined icons
                     in this module.
    :return: Corresponding QFile
    :rtype: qt.QFile
    :raises: ValueError when name is not known
    """
    global _supported_formats
    if _supported_formats is None:
        _supported_formats = []
        supported_formats = qt.supportedImageFormats()
        order = ["mng", "gif", "svg", "png", "jpg"]
        for format_ in order:
            if format_ in supported_formats:
                _supported_formats.append(format_)
        if len(_supported_formats) == 0:
            _logger.error("No format supported for icons")
        else:
            _logger.debug("Format %s supported", ", ".join(_supported_formats))

    for format_ in _supported_formats:
        format_ = str(format_)
        filename = resource_filename('gui/icons/%s.%s' % (name, format_))
        qfile = qt.QFile(filename)
        if qfile.exists():
            return qfile
    raise ValueError('Not an icon name: %s' % name)
Ejemplo n.º 3
0
 def testSvgIcon(self):
     if "svg" not in qt.supportedImageFormats():
         self.skipTest("SVG not supported")
     icon = icons.getQIcon("test:gui/icons/zoom-out")
     self.assertIsNotNone(icon)
Ejemplo n.º 4
0
 def testMovieIconExists(self):
     if "mng" not in qt.supportedImageFormats():
         self.skipTest("MNG not supported")
     icon = icons.MovieAnimatedIcon("process-working")
     self.assertIsNotNone(icon)
Ejemplo n.º 5
0
 def testSvgIcon(self):
     if "svg" not in qt.supportedImageFormats():
         self.skipTest("SVG not supported")
     icon = icons.getQIcon("test:gui/icons/zoom-out")
     self.assertIsNotNone(icon)
Ejemplo n.º 6
0
 def testMovieIconExists(self):
     if "mng" not in qt.supportedImageFormats():
         self.skipTest("MNG not supported")
     icon = icons.MovieAnimatedIcon("process-working")
     self.assertIsNotNone(icon)