WxPython: wx.grid.Grid load buggy images

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

WxPython: wx.grid.Grid load buggy images

Barb-Cr33k

I use a custom renderer to add an image to grid but the end result is really buggy and I was wondering if that was related to the error message I receive when running the script: NotImplementedError: GridCellRenderer.GetBestSize() is abstract and must be overridden If not, What should I do to have a clean display?

In the capture below you can see that:

  • The images load with a gray background (line 1)
  • The background disappears if the cell get clicked 2 times as to edit, and one click away from the cell (line 2)
  • In line 3 I tried to expand the row vertically and it's like the content of the following rows got imprinted on the expanded row.

Ccw36.png


Here is the code I use:

import wx
import wx.grid as gridlib

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, -1, title = "wx.Grid - Bitmap example", size=(800, 600))
        gridlib = wx.grid.Grid(frame)
        gridlib.CreateGrid(17,17)

        gridlib.SetColLabelValue(0, "Source")
        gridlib.SetColLabelValue(1, "Campaign")
        gridlib.SetColLabelValue(2, "") 
        gridlib.SetColLabelValue(3, "")
        gridlib.SetColLabelValue(4, "IMPR.")
        gridlib.SetColLabelValue(5, "Clicks.")
        gridlib.SetColLabelValue(6, "CTR")
        gridlib.SetColLabelValue(7, "Spent")
        gridlib.SetColLabelValue(8, "CPM")
        gridlib.SetColLabelValue(9, "CPC")
        gridlib.SetColLabelValue(10, "GA REV.")
        gridlib.SetColLabelValue(11, "GA IMPR.")
        gridlib.SetColLabelValue(12, "GA CLICKS")
        gridlib.SetColLabelValue(13, "GA CTR")
        gridlib.SetColLabelValue(14, "GA RPM")
        gridlib.SetColLabelValue(15, "Margin")
        gridlib.SetColLabelValue(16, "Target CPC")
        gridlib.SetColLabelValue(17, "Change CPC")

        uk = wx.Bitmap(r"E:\Python\img\uk.png", wx.BITMAP_TYPE_ANY)
        desktop = wx.Bitmap(r"E:\Python\img\dk.png", wx.BITMAP_TYPE_ANY)

        def RenderImage(col, row, img):
            gridlib.SetCellRenderer(col,row,MyImageRenderer(img))
            gridlib.SetRowSize(col,img.GetHeight()+2)
            gridlib.SetColSize(row,img.GetWidth()+2)

        for i in range(0,17):
            RenderImage(i,2,uk)
            RenderImage(i,3,desktop)

        frame.Show(True)
        return True

class MyImageRenderer(wx.grid.GridCellRenderer):
    def __init__(self, img):
        wx.grid.GridCellRenderer.__init__(self)
        self.img = img
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        image = wx.MemoryDC()
        image.SelectObject(self.img)
        dc.SetBackgroundMode(wx.SOLID)
        if isSelected:
            dc.SetBrush(wx.Brush(wx.BLUE, wx.SOLID))
            dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID))
        else:
            dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
            dc.SetPen(wx.Pen(wx.WHITE, 1, wx.SOLID))
        #dc.DrawRectangleRect(rect)
        width, height = self.img.GetWidth(), self.img.GetHeight()
        if width > rect.width-2:
            width = rect.width-2
        if height > rect.height-2:
            height = rect.height-2
        dc.Blit(rect.x+1, rect.y+1, width, height, image, 0, 0, wx.COPY, True)

app = MyApp(0)
app.MainLoop()


Thank you,

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/32a6617a-f74b-42c2-8285-f2fbdc5d311f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Tim Roberts
On May 19, 2019, at 2:39 PM, Youn-Bo <[hidden email]> wrote:

I use a custom renderer to add an image to grid but the end result is really buggy and I was wondering if that was related to the error message I receive when running the script: NotImplementedError: GridCellRenderer.GetBestSize() is abstract and must be overridden If not, What should I do to have a clean display?

You have a line of code in there to clear the entire cell before drawing the image, but you have it commented out.  Why?  I would think that's exactly what you are lacking here.
— 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/5DE5D415-F512-41A0-95F4-FE3B46D7A7B2%40probo.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Barb-Cr33k


On Monday, 20 May 2019 01:24:38 UTC-4, Tim Roberts wrote:
On May 19, 2019, at 2:39 PM, Youn-Bo <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="lmhs1CN3AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">younes...@...> wrote:

I use a custom renderer to add an image to grid but the end result is really buggy and I was wondering if that was related to the error message I receive when running the script: NotImplementedError: GridCellRenderer.GetBestSize() is abstract and must be overridden If not, What should I do to have a clean display?

You have a line of code in there to clear the entire cell before drawing the image, but you have it commented out.  Why?  I would think that's exactly what you are lacking here.

When I uncomment that line the images get deleted.

Capture.PNG

 

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/a4d3ea43-cdf9-4dca-afc0-87e505eca37f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Scott Talbert
In reply to this post by Barb-Cr33k
On Sun, 19 May 2019, Youn-Bo wrote:

>
> I use a custom renderer to add an image to grid but the end result is really
> buggy and I was wondering if that was related to the error message I receive
> when running the script: NotImplementedError: GridCellRenderer.GetBestSize()
> is abstract and must be overridden If not, What should I do to have a clean
> display?

You're getting that error message because your MyImageRenderer doesn't
implement the GetBestSize() method.  This method is required.

Scott

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/alpine.DEB.2.21.1905200907530.8444%40bear.techie.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Barb-Cr33k
Ok, thank you. Any help on how to implement this method in my code. Maybe it will solve my problem. 

On Monday, 20 May 2019 09:09:40 UTC-4, Scott Talbert wrote:
On Sun, 19 May 2019, Youn-Bo wrote:

>
> I use a custom renderer to add an image to grid but the end result is really
> buggy and I was wondering if that was related to the error message I receive
> when running the script: NotImplementedError: GridCellRenderer.GetBestSize()
> is abstract and must be overridden If not, What should I do to have a clean
> display?

You're getting that error message because your MyImageRenderer doesn't
implement the GetBestSize() method.  This method is required.

Scott

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/5f62eb2f-e80b-4405-a7a2-7a7d7b98af73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Scott Talbert
Here's an example from the demos:
https://github.com/wxWidgets/Phoenix/blob/master/demo/GridStdEdRend.py#L37

On Mon, 20 May 2019, Youn-Bo wrote:

> Ok, thank you. Any help on how to implement this method in my code. Maybe it
> will solve my problem. 
>
> On Monday, 20 May 2019 09:09:40 UTC-4, Scott Talbert wrote:
>       On Sun, 19 May 2019, Youn-Bo wrote:
>
>       >
>       > I use a custom renderer to add an image to grid but the end
>       result is really
>       > buggy and I was wondering if that was related to the error
>       message I receive
>       > when running the script: NotImplementedError:
>       GridCellRenderer.GetBestSize()
>       > is abstract and must be overridden If not, What should I do to
>       have a clean
>       > display?
>
>       You're getting that error message because your MyImageRenderer
>       doesn't
>       implement the GetBestSize() method.  This method is required.
>
>       Scott
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To view this discussion on the web visithttps://groups.google.com/d/msgid/wxpython-users/5f62eb2f-e80b-4405-a7a2-7a
> 7d7b98af73%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/alpine.DEB.2.21.1905201048300.10926%40bear.techie.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Barb-Cr33k
Now I receive: NotImplementedError: GridCellRenderer.Draw() is abstract and must be overridden

This problem is killing me. I have no idea what I'm doing. I'm a beginner and I bearly understand oop concepts so reading documentation is hard for me. Please, can someone take a few minutes of his time to test the script on his PC and see what is wrong with it? It would be greatly appreciated.
 

On Monday, 20 May 2019 10:49:07 UTC-4, Scott Talbert wrote:
Here's an example from the demos:
<a href="https://github.com/wxWidgets/Phoenix/blob/master/demo/GridStdEdRend.py#L37" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FwxWidgets%2FPhoenix%2Fblob%2Fmaster%2Fdemo%2FGridStdEdRend.py%23L37\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHQmukBvhna67WbXPWepGNNy5RyQQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FwxWidgets%2FPhoenix%2Fblob%2Fmaster%2Fdemo%2FGridStdEdRend.py%23L37\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHQmukBvhna67WbXPWepGNNy5RyQQ&#39;;return true;">https://github.com/wxWidgets/Phoenix/blob/master/demo/GridStdEdRend.py#L37

On Mon, 20 May 2019, Youn-Bo wrote:

> Ok, thank you. Any help on how to implement this method in my code. Maybe it
> will solve my problem. 
>
> On Monday, 20 May 2019 09:09:40 UTC-4, Scott Talbert wrote:
>       On Sun, 19 May 2019, Youn-Bo wrote:
>
>       >
>       > I use a custom renderer to add an image to grid but the end
>       result is really
>       > buggy and I was wondering if that was related to the error
>       message I receive
>       > when running the script: NotImplementedError:
>       GridCellRenderer.GetBestSize()
>       > is abstract and must be overridden If not, What should I do to
>       have a clean
>       > display?
>
>       You're getting that error message because your MyImageRenderer
>       doesn't
>       implement the GetBestSize() method.  This method is required.
>
>       Scott
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="BSsyk_GVAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpytho...@googlegroups.com.
> To view this discussion on the web visithttps://<a href="http://groups.google.com/d/msgid/wxpython-users/5f62eb2f-e80b-4405-a7a2-7a" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/d/msgid/wxpython-users/5f62eb2f-e80b-4405-a7a2-7a&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/d/msgid/wxpython-users/5f62eb2f-e80b-4405-a7a2-7a&#39;;return true;">groups.google.com/d/msgid/wxpython-users/5f62eb2f-e80b-4405-a7a2-7a
> 7d7b98af73%<a href="http://40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2F40googlegroups.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEjt8k9OhR10y0jYLX0ZgJix1hnBQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2F40googlegroups.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEjt8k9OhR10y0jYLX0ZgJix1hnBQ&#39;;return true;">40googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
>
>

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/168b231c-8677-4b2b-87b2-29bc00d71e39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Tim Roberts
In reply to this post by Barb-Cr33k
Youn-Bo wrote:

On Monday, 20 May 2019 01:24:38 UTC-4, Tim Roberts wrote:
You have a line of code in there to clear the entire cell before drawing the image, but you have it commented out.  Why?  I would think that's exactly what you are lacking here.

When I uncomment that line the images get deleted.

That's because you have a typo.  You have DrawRectangleRect instead of DrawRectangle, so it fails with an error and the image never gets drawn.  If you had run this from a command line, you would have seen the errors:

Traceback (most recent call last):
  File "x.py", line 58, in Draw
    dc.DrawRectangleRect(rect)
AttributeError: 'PaintDC' object has no attribute 'DrawRectangleRect'
Traceback (most recent call last):
  File "x.py", line 58, in Draw
    dc.DrawRectangleRect(rect)
AttributeError: 'PaintDC' object has no attribute 'DrawRectangleRect'
Traceback (most recent call last):
  File "x.py", line 58, in Draw
    dc.DrawRectangleRect(rect)

-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/b0fecaf1-cffa-140c-16c5-e7d9265720b5%40probo.com.
For more options, visit https://groups.google.com/d/optout.

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: WxPython: wx.grid.Grid load buggy images

Barb-Cr33k
Thank a lot that was the error indeed.

On Monday, 20 May 2019 12:49:05 UTC-4, Tim Roberts wrote:
Youn-Bo wrote:

On Monday, 20 May 2019 01:24:38 UTC-4, Tim Roberts wrote:
You have a line of code in there to clear the entire cell before drawing the image, but you have it commented out.  Why?  I would think that's exactly what you are lacking here.

When I uncomment that line the images get deleted.

That's because you have a typo.  You have DrawRectangleRect instead of DrawRectangle, so it fails with an error and the image never gets drawn.  If you had run this from a command line, you would have seen the errors:

Traceback (most recent call last):
  File "x.py", line 58, in Draw
    dc.DrawRectangleRect(rect)
AttributeError: 'PaintDC' object has no attribute 'DrawRectangleRect'
Traceback (most recent call last):
  File "x.py", line 58, in Draw
    dc.DrawRectangleRect(rect)
AttributeError: 'PaintDC' object has no attribute 'DrawRectangleRect'
Traceback (most recent call last):
  File "x.py", line 58, in Draw
    dc.DrawRectangleRect(rect)

-- 
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="MNGebX2cAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/46cb5e3a-ade7-4df8-b6d2-a50f3533fde5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.