Grayscale overlay

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

Grayscale overlay

steve
Hi,

I would like to get a grayscale screenshot (overlay) of the current window and do drawings on it. I mean, the current window and all widgets, etc on it should lose all their colors and I should do drawings on it. Do you know how to do this?

I use 


odc = wx.DCOverlay(wx.Overlay, dc)


but its not grayscale.

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

Tim Roberts
steve wrote:
>
> I would like to get a grayscale screenshot (overlay) of the current
> window and do drawings on it. I mean, the current window and all
> widgets, etc on it should lose all their colors and I should do
> drawings on it. Do you know how to do this?

Well, an overlay is something that appears over the top of an existing
window, so the controls on the window still show through.   Is that
really what you're after?  It sounds like you want a separate window
contains a converted copy of your current window, so the existing
controls are not visible.

There is nothing in wx that will convert a color bitmap to a grayscale
bitmap, in part because the definition of "grayscale" is not completely
uniform.  You'll have to do that by hand, pixel by pixel, or using
another graphics library.  It's not hard.

Perhaps you should describe what you're trying to in a bit more detail.

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

GadgetSteve
In reply to this post by steve


On 18/09/2017 18:11, steve wrote:

> Hi,
>
> I would like to get a grayscale screenshot (overlay) of the current
> window and do drawings on it. I mean, the current window and all
> widgets, etc on it should lose all their colors and I should do drawings
> on it. Do you know how to do this?
>
> I use
>
>
> odc = wx.DCOverlay(wx.Overlay, dc)
>
>
> but its not grayscale.
>
Just get the screenshot, (in colour), convert to an image with
ConvertToImage() and then use Pillow or Numpy to convert to greyscale.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
http://www.avg.com

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

Robin Dunn
In reply to this post by Tim Roberts
wx.Image has a ConvertToGreyscale method.

Drawing in a layer on top of other widgets will be tricky however.  The overlay classes on OSX use a native implementation that can do that, however the other platforms use a generic overlay based on ClientDC so it can only support drawing on the window performing the overlay which is likely to be the parent of the widgets you want to draw over.

The only approach that comes to mind is to use wx.ScreenDC to blit a snapshot of the window into a bitmap, temporarily replace (or hide) the current contents of the window with one that displays that bitmap and supports drawing like you want. However that won't work on OSX (DC's are one-way there, in most cases you can't easily get their current contents) but you can use the overlay classes there. Also, IIRC the ScreenDC approach may or may not work on Linux, depending on a number of factors.

Robin

On Monday, September 18, 2017 at 10:43:15 AM UTC-7, Tim Roberts wrote:
steve wrote:
>
> I would like to get a grayscale screenshot (overlay) of the current
> window and do drawings on it. I mean, the current window and all
> widgets, etc on it should lose all their colors and I should do
> drawings on it. Do you know how to do this?

Well, an overlay is something that appears over the top of an existing
window, so the controls on the window still show through.   Is that
really what you're after?  It sounds like you want a separate window
contains a converted copy of your current window, so the existing
controls are not visible.

There is nothing in wx that will convert a color bitmap to a grayscale
bitmap, in part because the definition of "grayscale" is not completely
uniform.  You'll have to do that by hand, pixel by pixel, or using
another graphics library.  It's not hard.

Perhaps you should describe what you're trying to in a bit more detail.

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

steve
Sorry for causing misunderstanding,

I have a panel on my frame, and I do drawings on it (rectangles, shapes etc) with wxpython GDI (using methods like dc.DrawRectangle etc). Rectangles and shapes have colors. There are no widgets on the panel. Just shapes.

When I press a button on the toolbar, I want everything on that panel to turn into grayscale (all shapes will lose their colors), and a colored custom progress bar will appear in the middle of that grayscaled panel (and on top of shapes), and it will run (because a lengthy operation will be executed). When the execution is completed, the progress bar will disappear and the shapes on panel will regain its original colors.

I hope I could explain it.

On Monday, September 18, 2017 at 10:43:56 PM UTC+3, Robin Dunn wrote:
wx.Image has a ConvertToGreyscale method.

Drawing in a layer on top of other widgets will be tricky however.  The overlay classes on OSX use a native implementation that can do that, however the other platforms use a generic overlay based on ClientDC so it can only support drawing on the window performing the overlay which is likely to be the parent of the widgets you want to draw over.

The only approach that comes to mind is to use wx.ScreenDC to blit a snapshot of the window into a bitmap, temporarily replace (or hide) the current contents of the window with one that displays that bitmap and supports drawing like you want. However that won't work on OSX (DC's are one-way there, in most cases you can't easily get their current contents) but you can use the overlay classes there. Also, IIRC the ScreenDC approach may or may not work on Linux, depending on a number of factors.

Robin

On Monday, September 18, 2017 at 10:43:15 AM UTC-7, Tim Roberts wrote:
steve wrote:
>
> I would like to get a grayscale screenshot (overlay) of the current
> window and do drawings on it. I mean, the current window and all
> widgets, etc on it should lose all their colors and I should do
> drawings on it. Do you know how to do this?

Well, an overlay is something that appears over the top of an existing
window, so the controls on the window still show through.   Is that
really what you're after?  It sounds like you want a separate window
contains a converted copy of your current window, so the existing
controls are not visible.

There is nothing in wx that will convert a color bitmap to a grayscale
bitmap, in part because the definition of "grayscale" is not completely
uniform.  You'll have to do that by hand, pixel by pixel, or using
another graphics library.  It's not hard.

Perhaps you should describe what you're trying to in a bit more detail.

--
Tim Roberts, <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="vl0BOn1lBAAJ" 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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

GadgetSteve


On 18/09/2017 21:33, steve wrote:

> Sorry for causing misunderstanding,
>
> I have a panel on my frame, and I do drawings on it (rectangles, shapes
> etc) with wxpython GDI (using methods like dc.DrawRectangle etc).
> Rectangles and shapes have colors. There are no widgets on the panel.
> Just shapes.
>
> When I press a button on the toolbar, I want everything on that panel to
> turn into grayscale (all shapes will lose their colors), and a colored
> custom progress bar will appear in the middle of that grayscaled panel
> (and on top of shapes), and it will run (because a lengthy operation
> will be executed). When the execution is completed, the progress bar
> will disappear and the shapes on panel will regain its original colors.
>
> I hope I could explain it.
>
> On Monday, September 18, 2017 at 10:43:56 PM UTC+3, Robin Dunn wrote:
>
>     wx.Image has a ConvertToGreyscale method.
>
>     Drawing in a layer on top of other widgets will be tricky however.
>       The overlay classes on OSX use a native implementation that can do
>     that, however the other platforms use a generic overlay based on
>     ClientDC so it can only support drawing on the window performing the
>     overlay which is likely to be the parent of the widgets you want to
>     draw over.
>
>     The only approach that comes to mind is to use wx.ScreenDC to blit a
>     snapshot of the window into a bitmap, temporarily replace (or hide)
>     the current contents of the window with one that displays that
>     bitmap and supports drawing like you want. However that won't work
>     on OSX (DC's are one-way there, in most cases you can't easily get
>     their current contents) but you can use the overlay classes there.
>     Also, IIRC the ScreenDC approach may or may not work on Linux,
>     depending on a number of factors.
>
>     Robin
>
>     On Monday, September 18, 2017 at 10:43:15 AM UTC-7, Tim Roberts wrote:
>
>         steve wrote:
>          >
>          > I would like to get a grayscale screenshot (overlay) of the
>         current
>          > window and do drawings on it. I mean, the current window and all
>          > widgets, etc on it should lose all their colors and I should do
>          > drawings on it. Do you know how to do this?
>
>         Well, an overlay is something that appears over the top of an
>         existing
>         window, so the controls on the window still show through.   Is that
>         really what you're after?  It sounds like you want a separate
>         window
>         contains a converted copy of your current window, so the existing
>         controls are not visible.
>
>         There is nothing in wx that will convert a color bitmap to a
>         grayscale
>         bitmap, in part because the definition of "grayscale" is not
>         completely
>         uniform.  You'll have to do that by hand, pixel by pixel, or using
>         another graphics library.  It's not hard.
>
>         Perhaps you should describe what you're trying to in a bit more
>         detail.
>
>         --
>         Tim Roberts, [hidden email] <javascript:>
>         Providenza & Boekelheide, Inc.

Simply hide the existing panel and replace it with one displaying a grey
scale version of the current bitmap or image for the duration.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
http://www.avg.com

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

Tim Roberts
In reply to this post by steve
steve wrote:
>
> I have a panel on my frame, and I do drawings on it (rectangles,
> shapes etc) with wxpython GDI (using methods like dc.DrawRectangle
> etc). Rectangles and shapes have colors. There are no widgets on the
> panel. Just shapes.

That's very different from what you first described.


> When I press a button on the toolbar, I want everything on that panel
> to turn into grayscale (all shapes will lose their colors), and a
> colored custom progress bar will appear in the middle of that
> grayscaled panel (and on top of shapes), and it will run (because a
> lengthy operation will be executed). When the execution is completed,
> the progress bar will disappear and the shapes on panel will regain
> its original colors.

It seems to me that the easy way to do this is to have all of your color
selections go through a filter:

    m_Shape->SetBackgroundColor( ChooseColor( 255,128,64 ) );
...
    wxColour MyWindow::ChooseColor( int r, int g, int b )
    {
        if( m_NeedGrayscale )
        {
            // This is a cheap but acceptable RGB->grayscale conversion.
            int gray = (2 * r + 4 * g + b) / 7;
            return wxColour( gray, gray, gray );
        }
        else
            return wxColour( r, g, b );
    }

Now, to draw in grayscale, you just set the flag and call "Refresh();."

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

Tim Roberts
Tim Roberts wrote:

> steve wrote:
>> I have a panel on my frame, and I do drawings on it (rectangles,
>> shapes etc) with wxpython GDI (using methods like dc.DrawRectangle
>> etc). Rectangles and shapes have colors. There are no widgets on the
>> panel. Just shapes.
> That's very different from what you first described.
>
>
>> When I press a button on the toolbar, I want everything on that panel
>> to turn into grayscale (all shapes will lose their colors), and a
>> colored custom progress bar will appear in the middle of that
>> grayscaled panel (and on top of shapes), and it will run (because a
>> lengthy operation will be executed). When the execution is completed,
>> the progress bar will disappear and the shapes on panel will regain
>> its original colors.
> It seems to me that the easy way to do this is to have all of your color
> selections go through a filter:

Holy cripes, I totally spaced that I was on the wxPython list.

    def ChooseColor( self, r, g, b ):
        if self.NeedGrayScale:
            gray = (2 * r + 4 * g + b) / 7
            return wx.Colour( gray, gray, gray )
        else:
            return wx.Colour( r, g, b )

    ....
        self.widget.SetBackgroundColor( self.ChooseColor( 255, 128, 64 ) )

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

Chris Barker - NOAA Federal
>
> Holy cripes, I totally spaced that I was on the wxPython list.

Makes you appreciate Python, eh?

Another option:

Rather than greyscale, draw a semi-transparent white or black
rectangle over the whole thing -- that will make it look all muted.

Also - you should probably have your window double/buffered-- so you
can grab the buffet, make it an image, convert to grayscale, and the
put it back.

-CHB

>
>     def ChooseColor( self, r, g, b ):
>         if self.NeedGrayScale:
>             gray = (2 * r + 4 * g + b) / 7
>             return wx.Colour( gray, gray, gray )
>         else:
>             return wx.Colour( r, g, b )
>
>     ....
>         self.widget.SetBackgroundColor( self.ChooseColor( 255, 128, 64 ) )
>
> --
> 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].
> 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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Grayscale overlay

steve
Great answer Chris, it doesn't exactly do what I want, bu still it is very handy. Thanks.

On Wednesday, September 20, 2017 at 3:25:37 AM UTC+3, Chris Barker - NOAA Federal wrote:
>
> Holy cripes, I totally spaced that I was on the wxPython list.

Makes you appreciate Python, eh?

Another option:

Rather than greyscale, draw a semi-transparent white or black
rectangle over the whole thing -- that will make it look all muted.

Also - you should probably have your window double/buffered-- so you
can grab the buffet, make it an image, convert to grayscale, and the
put it back.

-CHB

>
>     def ChooseColor( self, r, g, b ):
>         if self.NeedGrayScale:
>             gray = (2 * r + 4 * g + b) / 7
>             return wx.Colour( gray, gray, gray )
>         else:
>             return wx.Colour( r, g, b )
>
>     ....
>         self.widget.SetBackgroundColor( self.ChooseColor( 255, 128, 64 ) )
>
> --
> Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="m-30aXUnBAAJ" 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="m-30aXUnBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.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].
For more options, visit https://groups.google.com/d/optout.