adding an image / picture to a grid cell

Is there a simple function / method that addes an image from a file to
a cell in a grid?

I found a couple of grid examples, and one property grid. but they
were too complicated for me.

Eventually i'd like to have something like:

    mygrid.set_cell_image( x, y, "image.jpg" )
or
   mygrid.appendRow( [str, str, image, str ...] )

thanks!

Make the cell read only and use a custom cell renderer for it.

You can make a bitmap cell renderer with something like this:

class BitmapRenderer(wx.grid.PyGridCellRenderer):
     def Draw(self, grid, attr, dc, rect, row, col, is_selected):
         bmp = get_the_bitmap_based_on_cell_value(grid.GetCellValue(row, col))
         dc.DrawBitmap(bmp, rect.X, rect.Y)

     def Clone(self):
         return self.__class__()

···

On Mon, 26 Mar 2012 20:50:31 +0200, shuki <asafgreenberg@gmail.com> wrote:

Is there a simple function / method that addes an image from a file to
a cell in a grid?

I found a couple of grid examples, and one property grid. but they
were too complicated for me.

Eventually i'd like to have something like:

    mygrid.set_cell_image( x, y, "image.jpg" )
or
   mygrid.appendRow( [str, str, image, str ...] )

thanks!

that's what i said:
it's complicated and I still don't understand it.
how does a "renderer" being used?
what's a renderer anyway?
is there a "single function" that can set a picture to X,Y ?

Thank you

···

On Mar 26, 9:33 pm, Toni Ruža <gmr....@gmail.com> wrote:

On Mon, 26 Mar 2012 20:50:31 +0200, shuki <asafgreenb...@gmail.com> wrote:
> Is there a simple function / method that addes an image from a file to
> a cell in a grid?

> I found a couple of grid examples, and one property grid. but they
> were too complicated for me.

> Eventually i'd like to have something like:

> mygrid.set_cell_image( x, y, "image.jpg" )
> or
> mygrid.appendRow( [str, str, image, str ...] )

> thanks!

Make the cell read only and use a custom cell renderer for it.

You can make a bitmap cell renderer with something like this:

class BitmapRenderer(wx.grid.PyGridCellRenderer):
def Draw(self, grid, attr, dc, rect, row, col, is_selected):
bmp = get_the_bitmap_based_on_cell_value(grid.GetCellValue(row, col))
dc.DrawBitmap(bmp, rect.X, rect.Y)

 def Clone\(self\):
     return self\.\_\_class\_\_\(\)

shuki wrote:

that's what i said:
it's complicated and I still don't understand it.

It's hard to know how it could be any less complicated.

how does a "renderer" being used?
what's a renderer anyway?

To "render" in the graphics world means to draw something. When you
play a movie, the component that eventually draws the pixels on the
screen is the "renderer".

is there a "single function" that can set a picture to X,Y ?

No, because the grid cell object doesn't know how to handle a bitmap.
It doesn't have any place to put the picture, and it doesn't have
instructions on how to draw it. So, YOU have to provide a tiny function
to draw (or "render") the bitmap. That's what Toni's code does. It,
essentially, extends the grid cell object so it understands how to draw
a bitmap.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

ok, got it.

thank you both.

···

On Mar 27, 2:39 am, Tim Roberts <t...@probo.com> wrote:

shuki wrote:
> that's what i said:
> it's complicated and I still don't understand it.

It's hard to know how it could be any less complicated.

> how does a "renderer" being used?
> what's a renderer anyway?

To "render" in the graphics world means to draw something. When you
play a movie, the component that eventually draws the pixels on the
screen is the "renderer".

> is there a "single function" that can set a picture to X,Y ?

No, because the grid cell object doesn't know how to handle a bitmap.
It doesn't have any place to put the picture, and it doesn't have
instructions on how to draw it. So, YOU have to provide a tiny function
to draw (or "render") the bitmap. That's what Toni's code does. It,
essentially, extends the grid cell object so it understands how to draw
a bitmap.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.