Exemplo n.º 1
0
    def get_preview_obj_bitmap(self, bitmap=None):
        """Create a wx.Bitmap or wx.EmptyBitmap from the given statement.
        If no statement is given, the instance variable named "bitmap" is used.

        bitmap: Bitmap definition (str or None)

        see: get_preview_obj_artprovider(), get_preview_obj_emptybitmap()"""
        if bitmap is None:
            bitmap = getattr(self, 'bitmap', None)

        if not bitmap:
            return compat.wx_EmptyBitmap(1, 1)

        if bitmap.startswith('var:') or bitmap.startswith('code:'):
            return compat.wx_EmptyBitmap(16, 16)
        elif bitmap.startswith('empty:'):
            return self.get_preview_obj_emptybitmap(bitmap)
        elif bitmap.startswith('art:'):
            return self.get_preview_obj_artprovider(bitmap)
        else:
            bitmap = misc.get_absolute_path(bitmap)
            return wx.Bitmap(bitmap, wx.BITMAP_TYPE_ANY)
Exemplo n.º 2
0
    def get_preview_obj_emptybitmap(self, bitmap):
        """Create an empty wx.EmptyBitmap instance from the given statement.

        bitmap: Bitmap definition as str or None

        see: wcodegen.BaseWidgetWriter.get_inline_stmt_emptybitmap()"""
        # keep in sync with BaseWidgetWriter.get_inline_stmt_emptybitmap()
        width = 16
        height = 16
        try:
            size = bitmap[6:]
            width, height = [int(item.strip()) for item in size.split(',', 1)]
        except ValueError:
            self._logger.warn( 'Malformed statement to create an empty bitmap: %s', bitmap )
        return compat.wx_EmptyBitmap( max(1,width), max(1,height) )