Пример #1
0
def pixmap_cache(name, path=None):
    """ Return the QPixmap corresponding to a filename. If the filename does not
        contain a path component, 'path' is used (or if 'path' is not specified,
        the local 'images' directory is used).
    """
    if name[:1] == '@':
        image = convert_image(name.replace(' ', '_').lower())
        if image is not None:
            return image.create_image()

    name_path, name = os.path.split(name)
    name = name.replace(' ', '_').lower()
    if name_path:
        filename = os.path.join(name_path, name)
    else:
        if path is None:
            filename = os.path.join(os.path.dirname(__file__), 'images', name)
        else:
            filename = os.path.join(path, name)
    filename = os.path.abspath(filename)

    pm = QtGui.QPixmap()
    if not QtGui.QPixmapCache.find(filename, pm):
        pm.load(filename)
        QtGui.QPixmapCache.insert(filename, pm)
    return pm
Пример #2
0
def pixmap_cache(name, path=None):
    """ Return the QPixmap corresponding to a filename. If the filename does not
        contain a path component, 'path' is used (or if 'path' is not specified,
        the local 'images' directory is used).
    """
    if name[:1] == '@':
        image = convert_image(name.replace(' ', '_').lower())
        if image is not None:
            return image.create_image()

    name_path, name = os.path.split(name)
    name = name.replace(' ', '_').lower()
    if name_path:
        filename = os.path.join(name_path, name)
    else:
        if path is None:
            filename = os.path.join(os.path.dirname(__file__), 'images', name)
        else:
            filename = os.path.join(path, name)
    filename = os.path.abspath(filename)

    pm = QtGui.QPixmap()
    if not QtGui.QPixmapCache.find(filename, pm):
        pm.load(filename)
        QtGui.QPixmapCache.insert(filename, pm)
    return pm
Пример #3
0
def bitmap_cache(name, standard_size, path=None):
    """ Converts an image file name to a cached bitmap.
    """
    global app_path, traits_path

    if name[:1] == "@":
        image = convert_image(name.replace(" ", "_").lower())
        if image is not None:
            return image.create_image().ConvertToBitmap()

    if path is None:
        if traits_path is None:
            import traitsui.wx

            traits_path = join(dirname(traitsui.wx.__file__), "images")
        path = traits_path
    elif path == "":
        if app_path is None:
            app_path = join(dirname(sys.argv[0]), "..", "images")
        path = app_path

    filename = abspath(join(path, name.replace(" ", "_").lower() + ".gif"))
    bitmap = _bitmap_cache.get(filename + ("*"[not standard_size:]))
    if bitmap is not None:
        return bitmap

    std_bitmap = bitmap = wx.Bitmap(wx.Image(filename))
    _bitmap_cache[filename] = bitmap

    dx = bitmap.GetWidth()
    if dx < standard_bitmap_width:
        dy = bitmap.GetHeight()
        std_bitmap = wx.Bitmap(standard_bitmap_width, dy)
        dc1 = wx.MemoryDC()
        dc2 = wx.MemoryDC()
        dc1.SelectObject(std_bitmap)
        dc2.SelectObject(bitmap)
        dc1.SetPen(wx.TRANSPARENT_PEN)
        dc1.SetBrush(wx.WHITE_BRUSH)
        dc1.DrawRectangle(0, 0, standard_bitmap_width, dy)
        dc1.Blit((standard_bitmap_width - dx) // 2, 0, dx, dy, dc2, 0, 0)

    _bitmap_cache[filename + "*"] = std_bitmap

    if standard_size:
        return std_bitmap

    return bitmap
Пример #4
0
def bitmap_cache ( name, standard_size, path = None ):
    """ Converts an image file name to a cached bitmap.
    """
    global app_path, traits_path

    if name[:1] == '@':
        image = convert_image( name.replace( ' ', '_' ).lower() )
        if image is not None:
            return image.create_image().ConvertToBitmap()

    if path is None:
        if traits_path is None:
           import  traitsui.wx
           traits_path = join( dirname( traitsui.wx.__file__ ),
                               'images' )
        path = traits_path
    elif path == '':
        if app_path is None:
            app_path = join( dirname( sys.argv[0] ), '..', 'images' )
        path = app_path

    filename = abspath( join( path, name.replace( ' ', '_' ).lower() + '.gif' ))
    bitmap   = _bitmap_cache.get( filename + ('*'[ not standard_size: ]) )
    if bitmap is not None:
        return bitmap

    std_bitmap = bitmap = wx.BitmapFromImage( wx.Image( filename ) )
    _bitmap_cache[ filename ] = bitmap

    dx = bitmap.GetWidth()
    if dx < standard_bitmap_width:
        dy = bitmap.GetHeight()
        std_bitmap = wx.EmptyBitmap( standard_bitmap_width, dy )
        dc1 = wx.MemoryDC()
        dc2 = wx.MemoryDC()
        dc1.SelectObject( std_bitmap )
        dc2.SelectObject( bitmap )
        dc1.SetPen( wx.TRANSPARENT_PEN )
        dc1.SetBrush( wx.WHITE_BRUSH )
        dc1.DrawRectangle( 0, 0, standard_bitmap_width, dy )
        dc1.Blit( (standard_bitmap_width - dx) / 2, 0, dx, dy, dc2, 0, 0 )

    _bitmap_cache[ filename + '*' ] = std_bitmap

    if standard_size:
        return std_bitmap

    return bitmap