Discussion:
Drawing to the background
a***@googlemail.com
2014-09-06 14:42:27 UTC
Permalink
I'm working with an app that I want to capture user inputs and use them to
draw rectangles onto the screen which then move on a timer until more
inputs are captured. Originally I solved this by setting a high
transparency for the panel, but this isn't ideal as the rectangles are also
highly transparent.

I thought I'd found a solution in using wx.ScreenDC() to draw directly to
the screen, but I found that this caused the timer to no longer activate.
I can fix this with the final line in the attached code, but doing so
causes flickering. Is there some way to fix this? or some better way to
do what I'm doing?
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-08 16:42:25 UTC
Permalink
Can you post a sample program that we can run, that demostrates the timer
failing to function?
Post by a***@googlemail.com
I'm working with an app that I want to capture user inputs and use them to
draw rectangles onto the screen which then move on a timer until more
inputs are captured. Originally I solved this by setting a high
transparency for the panel, but this isn't ideal as the rectangles are also
highly transparent.
I thought I'd found a solution in using wx.ScreenDC() to draw directly to
the screen, but I found that this caused the timer to no longer activate.
I can fix this with the final line in the attached code, but doing so
causes flickering. Is there some way to fix this? or some better way to
do what I'm doing?
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a***@googlemail.com
2014-09-08 23:08:52 UTC
Permalink
Sure thing, I've attached an example with all of the unnecessary logic
removed. Pressing space bar creates a screen wide red rectangle which
scans from the left to the right of the screen.
The problem can be seen in the OnPaint function. In this function if I
comment out the second line, replacing it with the first (lines 66 and 68)
then everything functions, though the rectangle is as transparent as the
window. If left as is then the rectangle is not transparent but the timer
does not function (so it does not move). Finally if the final line of that
function is uncommented (line 73) then the rectangle is not transparent and
moves, but there is flickering as it does.
Post by Nathan McCorkle
Can you post a sample program that we can run, that demostrates the timer
failing to function?
Post by a***@googlemail.com
I'm working with an app that I want to capture user inputs and use them
to draw rectangles onto the screen which then move on a timer until more
inputs are captured. Originally I solved this by setting a high
transparency for the panel, but this isn't ideal as the rectangles are also
highly transparent.
I thought I'd found a solution in using wx.ScreenDC() to draw directly to
the screen, but I found that this caused the timer to no longer activate.
I can fix this with the final line in the attached code, but doing so
causes flickering. Is there some way to fix this? or some better way to
do what I'm doing?
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Werner
2014-09-09 06:28:28 UTC
Permalink
Hi Adam,
Post by a***@googlemail.com
Sure thing, I've attached an example with all of the unnecessary logic
removed. Pressing space bar creates a screen wide red rectangle which
scans from the left to the right of the screen.
The problem can be seen in the OnPaint function. In this function if
I comment out the second line, replacing it with the first (lines 66
and 68) then everything functions, though the rectangle is as
transparent as the window. If left as is then the rectangle is not
transparent but the timer does not function (so it does not move).
Finally if the final line of that function is uncommented (line 73)
then the rectangle is not transparent and moves, but there is
flickering as it does.
Changing wx.TRANSPARENT to wx.SOLID in the OnPaint handler and using
wx.PaintDC works for me (Win 8.1, Py2.7, wxPython 2.9.5).

The changed handler:

def OnPaint(self, event):
dc = wx.PaintDC(self.panel)
dc.SetPen(wx.Pen('red', 3))
dc.SetBrush(wx.Brush(wx.Colour(255, 0, 0), wx.SOLID))
if self.rect is not None:
dc.DrawRectangleRect(self.rect)

But there is some flicker.

I believe you shouldn't use wx.ScreenDC in OnPaint:
wxpython.org/Phoenix/docs/html/PaintDC.html

Werner
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a***@googlemail.com
2014-09-09 18:57:02 UTC
Permalink
Hi Werner,

Thanks a lot for the response.
Post by Werner
Hi Adam,
Post by a***@googlemail.com
Sure thing, I've attached an example with all of the unnecessary logic
removed. Pressing space bar creates a screen wide red rectangle which
scans from the left to the right of the screen.
The problem can be seen in the OnPaint function. In this function if
I comment out the second line, replacing it with the first (lines 66
and 68) then everything functions, though the rectangle is as
transparent as the window. If left as is then the rectangle is not
transparent but the timer does not function (so it does not move).
Finally if the final line of that function is uncommented (line 73)
then the rectangle is not transparent and moves, but there is
flickering as it does.
Changing wx.TRANSPARENT to wx.SOLID in the OnPaint handler and using
wx.PaintDC works for me (Win 8.1, Py2.7, wxPython 2.9.5).
This works, but the rectangle drawn is transparent (that is, as set in
line 16, where I set the frame's transparency). I was hoping to overlay
the rectangle over whatever is on the screen and have it be bold and
noticeable so this solution isn't ideal. Hopefully that makes sense.
Post by Werner
wxpython.org/Phoenix/docs/html/PaintDC.html
Werner
Thanks for the link, I was aware that it probably wasn't a great idea, but
it was the only way I'd found of having the
frame be transparent while drawing a solid line to the screen.

Cheers,
Adam
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-09 18:59:49 UTC
Permalink
Post by a***@googlemail.com
Hi Werner,
Thanks a lot for the response.
Post by Werner
Hi Adam,
Post by a***@googlemail.com
Sure thing, I've attached an example with all of the unnecessary logic
removed. Pressing space bar creates a screen wide red rectangle which
scans from the left to the right of the screen.
The problem can be seen in the OnPaint function. In this function if
I comment out the second line, replacing it with the first (lines 66
and 68) then everything functions, though the rectangle is as
transparent as the window. If left as is then the rectangle is not
transparent but the timer does not function (so it does not move).
Finally if the final line of that function is uncommented (line 73)
then the rectangle is not transparent and moves, but there is
flickering as it does.
Changing wx.TRANSPARENT to wx.SOLID in the OnPaint handler and using
wx.PaintDC works for me (Win 8.1, Py2.7, wxPython 2.9.5).
This works, but the rectangle drawn is transparent (that is, as set in
line 16, where I set the frame's transparency). I was hoping to overlay
the rectangle over whatever is on the screen and have it be bold and
noticeable so this solution isn't ideal. Hopefully that makes sense.
Maybe you could just create a new, borderless frame for each shape? Unless
you need tons of shapes I guess.
with these styles for the frame maybe:
style= wx.NO_BORDER| wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a***@googlemail.com
2014-09-09 19:24:08 UTC
Permalink
Post by Nathan McCorkle
Maybe you could just create a new, borderless frame for each shape? Unless
you need tons of shapes I guess.
style= wx.NO_BORDER| wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT
Hi Nathan,

Hmm, that's a really interesting solution. I think that would definitely
fit most of my needs and I hadn't realised it
was so simple. The only concern I have is that I'd like to be able to
capture key and mouse inputs as well and the
impression I had was that if the current frame didn't have focus then that
wasn't possible. Is this the case?
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-10 16:38:51 UTC
Permalink
Post by a***@googlemail.com
Hi Nathan,
Hmm, that's a really interesting solution. I think that would definitely
fit most of my needs and I hadn't realised it
was so simple. The only concern I have is that I'd like to be able to
capture key and mouse inputs as well and the
impression I had was that if the current frame didn't have focus then that
wasn't possible. Is this the case?
Well, you could say that *at least* one frame/window will have focus, so
just have your event handlers in the caller Frame and every time a new
Frame is created Bind the events to the existing handlers. That way no
matter which Frame actually has focus, the outcome will be equivalent.
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a***@googlemail.com
2014-09-10 21:39:24 UTC
Permalink
Post by Nathan McCorkle
Post by a***@googlemail.com
Hi Nathan,
Hmm, that's a really interesting solution. I think that would definitely
fit most of my needs and I hadn't realised it
was so simple. The only concern I have is that I'd like to be able to
capture key and mouse inputs as well and the
impression I had was that if the current frame didn't have focus then
that wasn't possible. Is this the case?
Well, you could say that *at least* one frame/window will have focus, so
just have your event handlers in the caller Frame and every time a new
Frame is created Bind the events to the existing handlers. That way no
matter which Frame actually has focus, the outcome will be equivalent.
Ah yes, I can see how that will work. Thanks so much for your help :)
--
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 wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...