Пример #1
0
def read(fname):
    import camelot
    from camelot.core.resources import resource_string
    return resource_string(
        camelot.__name__,
        'art/%s' % fname,
    )
Пример #2
0
def read(fname):
    import camelot
    from camelot.core.resources import resource_string
    return resource_string(
        camelot.__name__,
        'art/%s' % fname,
    )
Пример #3
0
def read(fname):
    import camelot
    from camelot.core.resources import resource_string
    return resource_string(
        camelot.__name__,
        'art/%s' % fname,
        'CAMELOT_MAIN_DIRECTORY'
    )
Пример #4
0
 def getQPixmap(self):
     """QPixmaps can only be used in the gui thread"""
     if self._cached_pixmap:
         return self._cached_pixmap
     from camelot.core.resources import resource_string
     from PyQt4.QtGui import QPixmap
     qpm = QPixmap()
     success = qpm.loadFromData(resource_string(self._module_name,
                                                'art/%s'%(self._path),
                                                'CAMELOT_MAIN_DIRECTORY'))
     if not success:
         msg = u'Could not load pixmap %s from camelot art library'
         logger.warn(msg % self._path)
     self._cached_pixmap = qpm
     return qpm
Пример #5
0
 def getQPixmap(self):
     """QPixmaps can only be used in the gui thread"""
     if self._cached_pixmap:
         return self._cached_pixmap
     from camelot.core.resources import resource_string
     from PyQt4.QtGui import QPixmap
     qpm = QPixmap()
     p = os.path.join('art', self._path)
     try:
         # For some reason this throws a unicode error if the path contains an accent (cf windows username)
         #  this happens only here, not for icons further on in the application
         #  so they see no splash screen, tant pis
         r = resource_string(self._module_name, p)
         qpm.loadFromData(r)
     except Exception, e:
         logger.warn(u'Could not load pixmap "%s" from module: %s, encountered exception' % (p, self._module_name), exc_info=e)
Пример #6
0
 def getQPixmap(self):
     """QPixmaps can only be used in the gui thread"""
     if self._cached_pixmap:
         return self._cached_pixmap
     from camelot.core.resources import resource_string
     from PyQt4.QtGui import QPixmap
     qpm = QPixmap()
     p = os.path.join('art', self._path)
     try:
         # For some reason this throws a unicode error if the path contains an accent (cf windows username)
         #  this happens only here, not for icons further on in the application
         #  so they see no splash screen, tant pis
         r = resource_string(self._module_name, p)
         qpm.loadFromData(r)
     except Exception, e:
         logger.warn(
             u'Could not load pixmap "%s" from module: %s, encountered exception'
             % (p, self._module_name),
             exc_info=e)
Пример #7
0
    def _load_translator_from_file( self, 
                                    module_name, 
                                    file_name, 
                                    directory = '', 
                                    search_delimiters = '_', 
                                    suffix = '.qm' ):
        """
        Tries to create a translator based on a file stored within a module.
        The file is loaded through the pkg_resources, to enable loading it from
        within a Python egg.  This method tries to mimic the behavior of
        :meth:`QtCore.QTranslator.load` while looking for an appropriate
        translation file.
        
        :param module_name: the name of the module in which to look for
            the translation file with pkg_resources.
        :param file_name: the filename of the the tranlations file, without 
            suffix
        :param directory: the directory, relative to the module in which
            to look for translation files
        :param suffix: the suffix of the filename
        :param search_delimiters: list of characters by which to split the file
            name to search for variations of the file name
        :return: :keyword:None if unable to load the file, otherwise a
            :obj:`QtCore.QTranslator` object.
            
        This method tries to load all file names with or without suffix, and
        with or without the part after the search delimiter.
        """
        from camelot.core.resources import resource_string

        #
        # split the directory names and file name
        #
        file_name_parts = [ file_name ]
        head, tail = os.path.split( file_name_parts[0] )
        while tail:
            file_name_parts[0] = tail
            file_name_parts = [ head ] + file_name_parts
            head, tail = os.path.split( file_name_parts[0] )
        #
        # for each directory and file name, generate all possibilities
        #
        file_name_parts_possibilities = []
        for file_name_part in file_name_parts:
            part_possibilities = []
            for search_delimiter in search_delimiters:
                delimited_parts = file_name_part.split( search_delimiter )
                for i in range( len( delimited_parts ) ):
                    part_possibility = search_delimiter.join( delimited_parts[:len(delimited_parts)-i] )
                    part_possibilities.append( part_possibility )
            file_name_parts_possibilities.append( part_possibilities )
        #
        # make the combination of all those possibilities
        #
        file_names = []
        for parts_possibility in itertools.product( *file_name_parts_possibilities ):
            file_name = os.path.join( *parts_possibility )
            file_names.append( file_name )
            file_names.append( file_name + suffix )
        #
        # now try all file names
        #
        translations = None
        for file_name in file_names:
            try:
                logger.debug( u'try %s'%file_name )
                translations = resource_string( module_name, os.path.join(directory,file_name) )
                break
            except IOError:
                pass
        if translations:
            _translations_data_.append( translations ) # keep the data alive
            translator = QtCore.QTranslator()
            # PySide workaround for missing loadFromData method
            if not hasattr( translator, 'loadFromData' ):
                return
            if translator.loadFromData( translations ):
                logger.info("add translation %s" % (directory + file_name))
                return translator
Пример #8
0
    def _load_translator_from_file( self, 
                                    module_name, 
                                    file_name, 
                                    directory = '', 
                                    search_delimiters = '_', 
                                    suffix = '.qm' ):
        """
        Tries to create a translator based on a file stored within a module.
        The file is loaded through the pkg_resources, to enable loading it from
        within a Python egg.  This method tries to mimic the behavior of
        :meth:`QtCore.QTranslator.load` while looking for an appropriate
        translation file.
        
        :param module_name: the name of the module in which to look for
            the translation file with pkg_resources.
        :param file_name: the filename of the the tranlations file, without 
            suffix
        :param directory: the directory, relative to the module in which
            to look for translation files
        :param suffix: the suffix of the filename
        :param search_delimiters: list of characters by which to split the file
            name to search for variations of the file name
        :return: :keyword:None if unable to load the file, otherwise a
            :obj:`QtCore.QTranslator` object.
            
        This method tries to load all file names with or without suffix, and
        with or without the part after the search delimiter.
        """
        from camelot.core.resources import resource_string

        #
        # split the directory names and file name
        #
        file_name_parts = [ file_name ]
        head, tail = os.path.split( file_name_parts[0] )
        while tail:
            file_name_parts[0] = tail
            file_name_parts = [ head ] + file_name_parts
            head, tail = os.path.split( file_name_parts[0] )
        #
        # for each directory and file name, generate all possibilities
        #
        file_name_parts_possibilities = []
        for file_name_part in file_name_parts:
            part_possibilities = []
            for search_delimiter in search_delimiters:
                delimited_parts = file_name_part.split( search_delimiter )
                for i in range( len( delimited_parts ) ):
                    part_possibility = search_delimiter.join( delimited_parts[:len(delimited_parts)-i] )
                    part_possibilities.append( part_possibility )
            file_name_parts_possibilities.append( part_possibilities )
        #
        # make the combination of all those possibilities
        #
        file_names = []
        for parts_possibility in itertools.product( *file_name_parts_possibilities ):
            file_name = os.path.join( *parts_possibility )
            file_names.append( file_name )
            file_names.append( file_name + suffix )
        #
        # now try all file names
        #
        translations = None
        for file_name in file_names:
            try:
                logger.debug( u'try %s'%file_name )
                translations = resource_string( module_name, os.path.join(directory,file_name) )
                break
            except IOError:
                pass
        if translations:
            _translations_data_.append( translations ) # keep the data alive
            translator = QtCore.QTranslator()
            # PySide workaround for missing loadFromData method
            if not hasattr( translator, 'loadFromData' ):
                return
            if translator.loadFromData( translations ):
                logger.info("add translation %s" % (directory + file_name))
                return translator