Is there a way to attach a frame to another frame or correlate position between two frames?

I have a frame with a videoplayer, and need to put a label on the top right corner, the videoplayer deletes anything in their own frame so I can’t put the label in the same frame, the solution as easy put another frame in the corner with the style wx.FRAME_SHAPED wx.NO_BORDER, wx.FRAME_NO_TASKBAR and wx.FRAME_FLOAT_ON_PARENT so even if it is a new frame it does not look like it. The problem begins when the user moves/resizes the window where the videoplayer is since the frame with the label remains on the top corner.

So, is there a way to pin the label frame to the corner of the videoplayer frame? So if the videoplayer frame moves, the label moves with it.

Thanks for the help

So, you want to draw something on top of the video?
The right way to do this is not the easiest way to do this. The
right way is to enable colorkey. The video player fills the
playback window with an uncommon solid color. It sets up the
graphics card to display the video only where the window contains
that color. The, you can draw whatever you want on the background,
and if it doesn’t match the colorkey color, it shows through.
What video player are you using? Does it support colorkey?

···

Marcos del Amo wrote:

    I have a frame with a videoplayer, and need to put

a label on the top right corner, the videoplayer deletes
anything in their own frame so I can’t put the label in the same
frame, the solution as easy put another frame in the corner with
the style wx.FRAME_SHAPED wx.NO_BORDER, wx.FRAME_NO_TASKBAR and
wx.FRAME_FLOAT_ON_PARENT so even if it is a new frame it does
not look like it. The problem begins when the user moves/resizes
the window where the videoplayer is since the frame with the
label remains on the top corner.

    So, is there a way to pin the label frame to the corner of the

videoplayer frame? So if the videoplayer frame moves, the label
moves with it.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

I’m using VLC, with the python bindings. I don’t know if it supports colorkey (I’ve never heard of it before)

I was thinking of using [GetClientArea](http://www.wxpython.org/docs/api/wx.Display-class.html#GetClientArea)() with the frame floating on top of the video so every time the user interacts with the player (which is gonna be a lot) the program get’s the client area, and recalculate it’s position. It’s not perfect but at least if the user moves the video between screens the labels will pop up on the right positions.

···

El miércoles, 25 de mayo de 2016, 19:23:18 (UTC+2), Tim Roberts escribió:

Marcos del Amo wrote:

    I have a frame with a videoplayer, and need to put

a label on the top right corner, the videoplayer deletes
anything in their own frame so I can’t put the label in the same
frame, the solution as easy put another frame in the corner with
the style wx.FRAME_SHAPED wx.NO_BORDER, wx.FRAME_NO_TASKBAR and
wx.FRAME_FLOAT_ON_PARENT so even if it is a new frame it does
not look like it. The problem begins when the user moves/resizes
the window where the videoplayer is since the frame with the
label remains on the top corner.

    So, is there a way to pin the label frame to the corner of the

videoplayer frame? So if the videoplayer frame moves, the label
moves with it.

So, you want to draw something on top of the video?



The right way to do this is not the easiest way to do this.  The

right way is to enable colorkey. The video player fills the
playback window with an uncommon solid color. It sets up the
graphics card to display the video only where the window contains
that color. The, you can draw whatever you want on the background,
and if it doesn’t match the colorkey color, it shows through.

What video player are you using?  Does it support colorkey?
-- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Looking at your earlier post which included a part of the code you are
using absolute positioning for just about everything - you will find
that a lot of your headaches will go away if you read up a bit on and
use sizers instead. Then moving the top window will automatically
relocate and child windows within the sizers.

···

On 25/05/2016 18:34, Marcos del Amo wrote:

I'm using VLC, with the python bindings. I don't know if it supports
colorkey (I've never heard of it before)

I was thinking of using ||GetClientArea|
<wxPython API Documentation — wxPython Phoenix 4.2.2 documentation with
the frame floating on top of the video so every time the user interacts
with the player (which is gonna be a lot) the program get's the client
area, and recalculate it's position. It's not perfect but at least if
the user moves the video between screens the labels will pop up on the
right positions.

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

I’m using sizers for other parts of the code, but in this case, I want the video and the label to ocupy the same space, I mean, I want the label on hoovering over the video, if I use a sizers won’t like a reserved space for the label? Or I am missunderstanding how sizers works (which could be a posibility)

P.S. I’ve been googlin up a bit and it seems I can use the colorkey thingy with VLC right? I look into it tomorrow…I’ve been struck for three weeks with this so thanks for the help!

···

El miércoles, 25 de mayo de 2016, 19:52:25 (UTC+2), Gadget Steve escribió:

On 25/05/2016 18:34, Marcos del Amo wrote:

I’m using VLC, with the python bindings. I don’t know if it supports

colorkey (I’ve never heard of it before)

I was thinking of using ||GetClientArea|

<http://www.wxpython.org/docs/api/wx.Display-class.html#GetClientArea>|() with

the frame floating on top of the video so every time the user interacts

with the player (which is gonna be a lot) the program get’s the client

area, and recalculate it’s position. It’s not perfect but at least if

the user moves the video between screens the labels will pop up on the

right positions.

Looking at your earlier post which included a part of the code you are

using absolute positioning for just about everything - you will find

that a lot of your headaches will go away if you read up a bit on and

use sizers instead. Then moving the top window will automatically

relocate and child windows within the sizers.


Steve (Gadget) Barnes

Any opinions in this message are my personal opinions and do not reflect

those of my employer.

I’m just wondering, would a custom DC event work here?

···

On Wednesday, May 25, 2016, Marcos del Amo mdelamo90@gmail.com wrote:

I’m using sizers for other parts of the code, but in this case, I want the video and the label to ocupy the same space, I mean, I want the label on hoovering over the video, if I use a sizers won’t like a reserved space for the label? Or I am missunderstanding how sizers works (which could be a posibility)

P.S. I’ve been googlin up a bit and it seems I can use the colorkey thingy with VLC right? I look into it tomorrow…I’ve been struck for three weeks with this so thanks for the help!

El miércoles, 25 de mayo de 2016, 19:52:25 (UTC+2), Gadget Steve escribió:

On 25/05/2016 18:34, Marcos del Amo wrote:

I’m using VLC, with the python bindings. I don’t know if it supports

colorkey (I’ve never heard of it before)

I was thinking of using ||GetClientArea|

<http://www.wxpython.org/docs/api/wx.Display-class.html#GetClientArea>|() with

the frame floating on top of the video so every time the user interacts

with the player (which is gonna be a lot) the program get’s the client

area, and recalculate it’s position. It’s not perfect but at least if

the user moves the video between screens the labels will pop up on the

right positions.

Looking at your earlier post which included a part of the code you are

using absolute positioning for just about everything - you will find

that a lot of your headaches will go away if you read up a bit on and

use sizers instead. Then moving the top window will automatically

relocate and child windows within the sizers.


Steve (Gadget) Barnes

Any opinions in this message are my personal opinions and do not reflect

those of my employer.

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+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

I think not, but I’m not really sure, I tried to paint every milisecond the label, but the flickering was insane (vlc deleting, me painting).

I’ve made some little test, in order to show you the problem.

In order to work you’ll need two images, one as a background for the label and the other to add some colour and some mp4 video.
Finally in order to use the program you’ll to have installed VLC in the custom path and add vlc.py in the same folder as the VLC.
Python should be 32 bits or the python bindings won’t work -.- (or I couldn’t make it work for 64)

This is how I’m using it but there are some tests commented, in line 301-305 is the option to put a button in the same frame as the video, and uncommenting the lines 481-482 to repaint it every milisecond that turns out as a big flickering like I explained.

Hope this help

That should be all

r.py (19.9 KB)

logo.png

vlc.py (295 KB)

···

El miércoles, 25 de mayo de 2016, 19:59:08 (UTC+2), Emad Dlala escribió:

I’m just wondering, would a custom DC event work here?

On Wednesday, May 25, 2016, Marcos del Amo mdel...@gmail.com wrote:

I’m using sizers for other parts of the code, but in this case, I want the video and the label to ocupy the same space, I mean, I want the label on hoovering over the video, if I use a sizers won’t like a reserved space for the label? Or I am missunderstanding how sizers works (which could be a posibility)

P.S. I’ve been googlin up a bit and it seems I can use the colorkey thingy with VLC right? I look into it tomorrow…I’ve been struck for three weeks with this so thanks for the help!

El miércoles, 25 de mayo de 2016, 19:52:25 (UTC+2), Gadget Steve escribió:

On 25/05/2016 18:34, Marcos del Amo wrote:

I’m using VLC, with the python bindings. I don’t know if it supports

colorkey (I’ve never heard of it before)

I was thinking of using ||GetClientArea|

<http://www.wxpython.org/docs/api/wx.Display-class.html#GetClientArea>|() with

the frame floating on top of the video so every time the user interacts

with the player (which is gonna be a lot) the program get’s the client

area, and recalculate it’s position. It’s not perfect but at least if

the user moves the video between screens the labels will pop up on the

right positions.

Looking at your earlier post which included a part of the code you are

using absolute positioning for just about everything - you will find

that a lot of your headaches will go away if you read up a bit on and

use sizers instead. Then moving the top window will automatically

relocate and child windows within the sizers.


Steve (Gadget) Barnes

Any opinions in this message are my personal opinions and do not reflect

those of my employer.

Hi Marcos,

I’m not sure I follow all of your code, and I’m not familiar with the vlc library. So perhaps this advice is obvious or inappropriate.

I often want to show an image from live video cameras and place overlays on top of these images – typically static shapes. To do this, I make a subclass of a wx.Panel(), and bind Paint events to a method that redraws the image and the overlays.

class ImagePanel(wx.Panel):

def init(self, parent, **kws):
super(ImagePanel, self).init(parent, -1, size=(800, 600))

    self.Bind(wx.EVT_PAINT, self.onPaint)

self.scale = 0.6 # sets scaling of raw bitmap image to that displayed on screen

probably set more stuff here

def onPaint(self, evt):

get the next full image, could be any source. Example of simple web camera:

    full_image = wx.ImageFromStream(StringIO(urlopen(self.url).read()))

    # scale image: usually you know the size of full image, or read it once

scaled_image = full_image.Scale((self.scaleself.full_width, self.scaleself.full_height))

    # make bitmap
    bitmap = wx.BitmapFromImage(scaled_image)

    bmp_w, bmp_h = self.bitmap_size = bitmap.GetSize()
    pan_w, pan_h = self.panel_size  = self.GetSize()
    pad_w, pad_h = (pan_w-bmp_w)/2.0, (pan_h-bmp_h)/2.0

    # draw bitmap
    dc = wx.AutoBufferedPaintDC(self)
    dc.Clear()
    dc.DrawBitmap(bitmap, pad_w, pad_h, useMask=True)

draw extra bits on top

    dc.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.NORMAL))

dc.SetPen(wx.Pen(wx.Colour((200, 0, 0)), 2, wx.SOLID))

dc.DrawLine(100, 100, 300, 100)
dc.DrawText(‘text here’, 150, 125)

I think what you’re trying to do is not (or does not need to) be a lot more complicated than that. In short, you do have to draw the overlays every time the image updates. It’s helpful to bind to size events to adjust the scale factor too, but this example is long enough. And, you might want some error checking in your actual code ;).

···

I haven’t tried this with pre-existing videos files, but this works to display images from1 to 2Mb gigE or usb3 cameras at 15 to 20 fps without flickering or performance problems, assuming the video card and network are up to the job.

I hope that’s helpful,

–Matt

On Thu, May 26, 2016 at 2:05 AM, Marcos del Amo mdelamo90@gmail.com wrote:

I think not, but I’m not really sure, I tried to paint every milisecond the label, but the flickering was insane (vlc deleting, me painting).

I’ve made some little test, in order to show you the problem.

In order to work you’ll need two images, one as a background for the label and the other to add some colour and some mp4 video.
Finally in order to use the program you’ll to have installed VLC in the custom path and add vlc.py in the same folder as the VLC.
Python should be 32 bits or the python bindings won’t work -.- (or I couldn’t make it work for 64)

This is how I’m using it but there are some tests commented, in line 301-305 is the option to put a button in the same frame as the video, and uncommenting the lines 481-482 to repaint it every milisecond that turns out as a big flickering like I explained.

Hope this help

That should be all

El miércoles, 25 de mayo de 2016, 19:59:08 (UTC+2), Emad Dlala escribió:

I’m just wondering, would a custom DC event work here?

On Wednesday, May 25, 2016, Marcos del Amo mdel...@gmail.com wrote:

I’m using sizers for other parts of the code, but in this case, I want the video and the label to ocupy the same space, I mean, I want the label on hoovering over the video, if I use a sizers won’t like a reserved space for the label? Or I am missunderstanding how sizers works (which could be a posibility)

P.S. I’ve been googlin up a bit and it seems I can use the colorkey thingy with VLC right? I look into it tomorrow…I’ve been struck for three weeks with this so thanks for the help!

El miércoles, 25 de mayo de 2016, 19:52:25 (UTC+2), Gadget Steve escribió:

On 25/05/2016 18:34, Marcos del Amo wrote:

I’m using VLC, with the python bindings. I don’t know if it supports

colorkey (I’ve never heard of it before)

I was thinking of using ||GetClientArea|

<http://www.wxpython.org/docs/api/wx.Display-class.html#GetClientArea>|() with

the frame floating on top of the video so every time the user interacts

with the player (which is gonna be a lot) the program get’s the client

area, and recalculate it’s position. It’s not perfect but at least if

the user moves the video between screens the labels will pop up on the

right positions.

Looking at your earlier post which included a part of the code you are

using absolute positioning for just about everything - you will find

that a lot of your headaches will go away if you read up a bit on and

use sizers instead. Then moving the top window will automatically

relocate and child windows within the sizers.


Steve (Gadget) Barnes

Any opinions in this message are my personal opinions and do not reflect

those of my employer.

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+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

What you’re doing there is repeatedly reading individual images from
a URL. That works for network-connected cameras that have a web
server, but it certainly won’t work for USB-connected cameras.
The difference with a directly-connected camera is that you’re
usually running a framework (DirectShow, VLC, gstreamer, etc) that
draws the frames into a special surface in the graphics card. That
allows the frames to stay in YUV, for example, by allowing the
graphics card itself to convert the colorspace. In that case, the
frames are not drawn with GDI and a DC at all. They arrive
asynchronously.

···

Matt Newville wrote:

      I'm not sure I follow all of your code, and I'm not familiar

with the vlc library. So perhaps this advice is obvious or
inappropriate.

      I often want to show an image from live video cameras and

place overlays on top of these images – typically static
shapes. To do this, I make a subclass of a wx.Panel(), and
bind Paint events to a method that redraws the image and the
overlays.

      ...
      I think what you're trying to do is not (or does not need

to) be a lot more complicated than that. In short, you do
have to draw the overlays every time the image updates. It’s
helpful to bind to size events to adjust the scale factor too,
but this example is long enough. And, you might want some
error checking in your actual code ;).

      I haven't tried this with pre-existing

videos files, but this works to display images from1 to 2Mb
gigE or usb3 cameras at 15 to 20 fps without flickering or
performance problems, assuming the video card and network are
up to the job.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

Matt Newville wrote:

I'm not sure I follow all of your code, and I'm not familiar with the vlc
library. So perhaps this advice is obvious or inappropriate.

I often want to show an image from live video cameras and place overlays
on top of these images -- typically static shapes. To do this, I make a
subclass of a wx.Panel(), and bind Paint events to a method that redraws
the image and the overlays.
...
I think what you're trying to do is not (or does not need to) be a lot
more complicated than that. In short, you do have to draw the overlays
every time the image updates. It's helpful to bind to size events to
adjust the scale factor too, but this example is long enough. And, you
might want some error checking in your actual code ;).

I haven't tried this with pre-existing videos files, but this works to
display images from1 to 2Mb gigE or usb3 cameras at 15 to 20 fps without
flickering or performance problems, assuming the video card and network are
up to the job.

What you're doing there is repeatedly reading individual images from a
URL. That works for network-connected cameras that have a web server, but
it certainly won't work for USB-connected cameras.

To clarify, I do use same drawing code for gigE and usb cameras, just
using a different "get the image" call that reads the image from the
network in a different way. The read-image-from-web-server is just the
simplest (and fairly generic) example, not relying on the camera-specific
interfaces that I do use. These do all receive one image at a time, though
the frame rate is close to video speeds.

The difference with a directly-connected camera is that you're usually
running a framework (DirectShow, VLC, gstreamer, etc) that draws the frames
into a special surface in the graphics card. That allows the frames to
stay in YUV, for example, by allowing the graphics card itself to convert
the colorspace. In that case, the frames are not drawn with GDI and a DC
at all. They arrive asynchronously.

Ah, yes, that is certainly a difference. I have no experience with that
mixing of wx with lower level drawing to the same frame.

--Matt

···

On Thu, May 26, 2016 at 12:11 PM, Tim Roberts <timr@probo.com> wrote:

Okthen, I guess I’ll ask for the position with GetScreenPosition() everytme the user interacts with the videoplayer and move the label accordingly. It’s not the best move but at least it’s better than what I have now.

I’ll be open for future suggestions thought.

Thanks for the help everyone!

···

El miércoles, 25 de mayo de 2016, 9:09:56 (UTC+2), Marcos del Amo escribió:

I have a frame with a videoplayer, and need to put a label on the top right corner, the videoplayer deletes anything in their own frame so I can’t put the label in the same frame, the solution as easy put another frame in the corner with the style wx.FRAME_SHAPED wx.NO_BORDER, wx.FRAME_NO_TASKBAR and wx.FRAME_FLOAT_ON_PARENT so even if it is a new frame it does not look like it. The problem begins when the user moves/resizes the window where the videoplayer is since the frame with the label remains on the top corner.

So, is there a way to pin the label frame to the corner of the videoplayer frame? So if the videoplayer frame moves, the label moves with it.

Thanks for the help

Yep that’s the way to go. With an EVT_MOVE I can keep track of the videoplayer (resize and movement) and follow it around with the label’s frame:

def on_move(self,event):
client = self.GetClientRect()
       lbl.SetPosition((x+client[2]-400, y+40))
       logo.SetPosition((x+client[2]-400, y+40))

As easy as that… -.-

Once again, thanks everbody for the help!

···

El miércoles, 25 de mayo de 2016, 9:09:56 (UTC+2), Marcos del Amo escribió:

I have a frame with a videoplayer, and need to put a label on the top right corner, the videoplayer deletes anything in their own frame so I can’t put the label in the same frame, the solution as easy put another frame in the corner with the style wx.FRAME_SHAPED wx.NO_BORDER, wx.FRAME_NO_TASKBAR and wx.FRAME_FLOAT_ON_PARENT so even if it is a new frame it does not look like it. The problem begins when the user moves/resizes the window where the videoplayer is since the frame with the label remains on the top corner.

So, is there a way to pin the label frame to the corner of the videoplayer frame? So if the videoplayer frame moves, the label moves with it.

Thanks for the help