Drawing in another window

Hi all,

A great feature from mplayer is the capability of drawing the played
movie in a window from another process using the -wid window_id
parameter. In the software I help to develop we want to do something
like that, a raycasting rendering from process A being drawing in the
process B using wxPython. Is it possible?

Thanks!

On Windows it might be doable. wx.Window_FromHWND(None, handle) can wrap a wx.Window around an existing window handle, so you can then bind paint events for it, etc. On the other platforms it will just raise an exception. If anybody would like to figure out how to do something like that for the other platforms I would love to get some patches submitted for it.

···

On 10/21/10 5:34 AM, Thiago Franco Moraes wrote:

Hi all,

A great feature from mplayer is the capability of drawing the played
movie in a window from another process using the -wid window_id
parameter. In the software I help to develop we want to do something
like that, a raycasting rendering from process A being drawing in the
process B using wxPython. Is it possible?

--
Robin Dunn
Software Craftsman

Thanks Robin! You have some example?

···

On 21 out, 15:07, Robin Dunn <ro...@alldunn.com> wrote:

On 10/21/10 5:34 AM, Thiago Franco Moraes wrote:

> Hi all,

> A great feature from mplayer is the capability of drawing the played
> movie in a window from another process using the -wid window_id
> parameter. In the software I help to develop we want to do something
> like that, a raycasting rendering from process A being drawing in the
> process B using wxPython. Is it possible?

On Windows it might be doable. wx.Window_FromHWND(None, handle) can
wrap a wx.Window around an existing window handle, so you can then bind
paint events for it, etc. On the other platforms it will just raise an
exception. If anybody would like to figure out how to do something like
that for the other platforms I would love to get some patches submitted
for it.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

No.

···

On 10/22/10 9:28 AM, tfmoraes wrote:

On 21 out, 15:07, Robin Dunn<ro...@alldunn.com> wrote:

On 10/21/10 5:34 AM, Thiago Franco Moraes wrote:

Hi all,

A great feature from mplayer is the capability of drawing the played
movie in a window from another process using the -wid window_id
parameter. In the software I help to develop we want to do something
like that, a raycasting rendering from process A being drawing in the
process B using wxPython. Is it possible?

On Windows it might be doable. wx.Window_FromHWND(None, handle) can
wrap a wx.Window around an existing window handle, so you can then bind
paint events for it, etc. On the other platforms it will just raise an
exception. If anybody would like to figure out how to do something like
that for the other platforms I would love to get some patches submitted
for it.

Thanks Robin! You have some example?

--
Robin Dunn
Software Craftsman

>>> Hi all,

>>> A great feature from mplayer is the capability of drawing the played
>>> movie in a window from another process using the -wid window_id
>>> parameter. In the software I help to develop we want to do something
>>> like that, a raycasting rendering from process A being drawing in the
>>> process B using wxPython. Is it possible?

>> On Windows it might be doable. wx.Window_FromHWND(None, handle) can
>> wrap a wx.Window around an existing window handle, so you can then bind
>> paint events for it, etc. On the other platforms it will just raise an
>> exception. If anybody would like to figure out how to do something like
>> that for the other platforms I would love to get some patches submitted
>> for it.
> Thanks Robin! You have some example?

No.

Ok. Here we'll try to do that and post a example here.

···

On 22 out, 15:29, Robin Dunn <ro...@alldunn.com> wrote:

On 10/22/10 9:28 AM, tfmoraes wrote:
> On 21 out, 15:07, Robin Dunn<ro...@alldunn.com> wrote:
>> On 10/21/10 5:34 AM, Thiago Franco Moraes wrote:

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Hi all,

A great feature from mplayer is the capability of drawing the played

movie in a window from another process using the -wid window_id

parameter. In the software I help to develop we want to do something

like that, a raycasting rendering from process A being drawing in the

process B using wxPython. Is it possible?

On Windows it might be doable. wx.Window_FromHWND(None, handle) can

wrap a wx.Window around an existing window handle, so you can then bind

paint events for it, etc. On the other platforms it will just raise an

exception. If anybody would like to figure out how to do something like

that for the other platforms I would love to get some patches submitted

for it.

Thanks Robin! You have some example?

No.

Ok. Here we’ll try to do that and post a example here.

Hi Robin,

We made a small example, but have 2 questions.

When you run the second process (1.py) is added to the panel frame of the first process (0.py), but it quickly disappears, the MainLoop () terminates immediately.

The second question is, wxPython has some “special” way of making two applications to communicate? so for me to pass the id of the first application for the second.

The code:

#==================== 0.py ==================================

import wx

class Jan(wx.Frame):

def __init__(self):

    wx.Frame.__init__(self, None, -1, "Test", wx.DefaultPosition, wx.Size(800,600))

    pnl = wx.Panel(self)
    handle = int(pnl.GetHandle())

    f = open("handle.conf", "w")
    f.write(str(handle))
    f.close()

class Programa1(wx.App):

def OnInit(self):
    jan = Jan()
    jan.Show()

    return True

prog = Programa1(0)
prog.MainLoop()

#================ 1.py =======================================

import wx

class Jan2(wx.Panel):

def __init__(self, parent):


    wx.Panel.__init__(self, parent, -1)
    self.SetBackgroundColour((0,0,255))
    self.SetSize(wx.Size(500,500))

class Programa2(wx.App):

def OnInit(self):
    f = open("handle.conf", "r")

    a = int(f.readline())
    f.close()
   
    w = wx.Window_FromHWND(None, a)
   
    jan2 = Jan2(w)
    jan2.Show()
    return True

prog2 = Programa2(0)

prog2.MainLoop()

Thx,
Paulo Amorim

···

On 22 October 2010 15:36, tfmoraes totonixsame@gmail.com wrote:

On 22 out, 15:29, Robin Dunn ro...@alldunn.com wrote:

On 10/22/10 9:28 AM, tfmoraes wrote:

On 21 out, 15:07, Robin Dunnro...@alldunn.com wrote:

On 10/21/10 5:34 AM, Thiago Franco Moraes wrote:

Robin Dunn

Software Craftsmanhttp://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

class Jan2(wx.Panel):

def \_\_init\_\_\(self, parent\):

    wx\.Panel\.\_\_init\_\_\(self, parent, \-1\)
    self\.SetBackgroundColour\(\(0,0,255\)\)
    self\.SetSize\(wx\.Size\(500,500\)\)

. . .

prog2 = Programa2(0)
prog2.MainLoop()

The top level control of any wx.App or wx.PySimpleApp must be wx.Frame
or even a wx.Dialog. A wx.Panel can only be a child control.

Ray

Whenever you see "HWND" or "hwnd" that indicates a MS Windows OS
window handle.

To get the MSW window handle value you can call a MSW API DLL
function. This is made easy by installing the following 2 packages.
The easiest way to get the hwnd is to refer to the target OS window
with its title string. In your 0.PY code this is "Test".

    PyWin32 Python package by Mark Hammond @
        http://sourceforge.net/projects/pywin32/

    WMI Python package by Tim Golden @
        http://pypi.python.org/pypi/WMI/

See my wiki page MswGuiDllCallsForWxPython for working demos @
    http://wiki.wxpython.org/MswGuiDllCallsForWxPython

Look for the function call GetHwndFromPid( pid ). The simplest way to
get the MSW pid value for an application is to launch that application
using another DLL call from within your 1.PY app. Call function
CreateExecProc() which starts the app and returns the MSW pid.

Ray

If the 0.py app was already running when 1.py starts, you can use the
function FindTopWindows() to search for that app frame using its frame
title text string. This function returns a list of hwnd's that match
the given title, so make sure the app title is unique.

Ray

     > >>> A great feature from mplayer is the capability of drawing the
    played
     > >>> movie in a window from another process using the -wid window_id
     > >>> parameter. In the software I help to develop we want to do
    something
     > >>> like that, a raycasting rendering from process A being
    drawing in the
     > >>> process B using wxPython. Is it possible?
     >
     > >> On Windows it might be doable. wx.Window_FromHWND(None,
    handle) can
     > >> wrap a wx.Window around an existing window handle, so you can
    then bind
     > >> paint events for it, etc. On the other platforms it will just
    raise an
     > >> exception. If anybody would like to figure out how to do
    something like
     > >> that for the other platforms I would love to get some patches
    submitted
     > >> for it.
     > > Thanks Robin! You have some example?
     >
     > No.

    Ok. Here we'll try to do that and post a example here.

Hi Robin,

We made a small example, but have 2 questions.

When you run the second process (1.py) is added to the panel frame of
the first process (0.py), but it quickly disappears, the MainLoop ()
terminates immediately.

Normally MainLoop will exit when there are no more top-level windows or TaskBarIcons. So as Ray tried to explain you can get around this by creating a frame, even if you never show it. Another possibility is to use prog2.SetExitOnFrameDelete(False), however I seem to recall that that may still allow MainLoop to exit if there are never any frames created at all...

The second question is, wxPython has some "special" way of making two
applications to communicate? so for me to pass the id of the first
application for the second.

There are several IPC mechanisms available to Python, so there hasn't been any need to add it to wxPython.

···

On 10/24/10 7:01 AM, Paulo Henrique Junqueira Amorim wrote:

--
Robin Dunn
Software Craftsman

Thanks!!! Robin and Pasco,

Worked perfectly!! Simply create wx.Frame in the init of the 1.py.

What remains now is how to do this on other platforms.

It would be wonderful if anyone knows how to make Linux and Mac

Regards and Thx,
Paulo

···

On 25 October 2010 15:00, Robin Dunn robin@alldunn.com wrote:

On 10/24/10 7:01 AM, Paulo Henrique Junqueira Amorim wrote:

 > >>> A great feature from mplayer is the capability of drawing the

played

 > >>> movie in a window from another process using the -wid window_id

 > >>> parameter. In the software I help to develop we want to do

something

 > >>> like that, a raycasting rendering from process A being

drawing in the

 > >>> process B using wxPython. Is it possible?

 >

 > >> On Windows it might be doable.  wx.Window_FromHWND(None,

handle) can

 > >> wrap a wx.Window around an existing window handle, so you can

then bind

 > >> paint events for it, etc.  On the other platforms it will just

raise an

 > >> exception.  If anybody would like to figure out how to do

something like

 > >> that for the other platforms I would love to get some patches

submitted

 > >> for it.

 > > Thanks Robin! You have some example?

 >

 > No.



Ok. Here we'll try to do that and post a example here.

Hi Robin,

We made a small example, but have 2 questions.

When you run the second process (1.py) is added to the panel frame of

the first process (0.py), but it quickly disappears, the MainLoop ()

terminates immediately.

Normally MainLoop will exit when there are no more top-level windows or TaskBarIcons. So as Ray tried to explain you can get around this by creating a frame, even if you never show it. Another possibility is to use prog2.SetExitOnFrameDelete(False), however I seem to recall that that may still allow MainLoop to exit if there are never any frames created at all…

The second question is, wxPython has some “special” way of making two

applications to communicate? so for me to pass the id of the first

application for the second.

There are several IPC mechanisms available to Python, so there hasn’t been any need to add it to wxPython.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

You can find an excellent tutorial on making the frames communicate here: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/

···

On Tue, Oct 26, 2010 at 1:32 AM, Paulo Henrique Junqueira Amorim paulojamorim@gmail.com wrote:

Thanks!!! Robin and Pasco,

Worked perfectly!! Simply create wx.Frame in the init of the 1.py.

What remains now is how to do this on other platforms.

It would be wonderful if anyone knows how to make Linux and Mac

Regards and Thx,
Paulo

On 25 October 2010 15:00, Robin Dunn robin@alldunn.com wrote:

On 10/24/10 7:01 AM, Paulo Henrique Junqueira Amorim wrote:

 > >>> A great feature from mplayer is the capability of drawing the

played

 > >>> movie in a window from another process using the -wid window_id

 > >>> parameter. In the software I help to develop we want to do

something

 > >>> like that, a raycasting rendering from process A being

drawing in the

 > >>> process B using wxPython. Is it possible?

 >

 > >> On Windows it might be doable.  wx.Window_FromHWND(None,

handle) can

 > >> wrap a wx.Window around an existing window handle, so you can

then bind

 > >> paint events for it, etc.  On the other platforms it will just

raise an

 > >> exception.  If anybody would like to figure out how to do

something like

 > >> that for the other platforms I would love to get some patches

submitted

 > >> for it.

 > > Thanks Robin! You have some example?

 >

 > No.



Ok. Here we'll try to do that and post a example here.

Hi Robin,

We made a small example, but have 2 questions.

When you run the second process (1.py) is added to the panel frame of

the first process (0.py), but it quickly disappears, the MainLoop ()

terminates immediately.

Normally MainLoop will exit when there are no more top-level windows or TaskBarIcons. So as Ray tried to explain you can get around this by creating a frame, even if you never show it. Another possibility is to use prog2.SetExitOnFrameDelete(False), however I seem to recall that that may still allow MainLoop to exit if there are never any frames created at all…

The second question is, wxPython has some “special” way of making two

applications to communicate? so for me to pass the id of the first

application for the second.

There are several IPC mechanisms available to Python, so there hasn’t been any need to add it to wxPython.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mejak,

The pubsub only communicates with the frames in the same App.

I want to communicate in different frames App.

Thax,
Paulo

···

On 26 October 2010 07:39, Boštjan Mejak bostjan.mejak@gmail.com wrote:

You can find an excellent tutorial on making the frames communicate here: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/

On Tue, Oct 26, 2010 at 1:32 AM, Paulo Henrique Junqueira Amorim paulojamorim@gmail.com wrote:

Thanks!!! Robin and Pasco,

Worked perfectly!! Simply create wx.Frame in the init of the 1.py.

What remains now is how to do this on other platforms.

It would be wonderful if anyone knows how to make Linux and Mac

Regards and Thx,
Paulo

On 25 October 2010 15:00, Robin Dunn robin@alldunn.com wrote:

On 10/24/10 7:01 AM, Paulo Henrique Junqueira Amorim wrote:

 > >>> A great feature from mplayer is the capability of drawing the

played

 > >>> movie in a window from another process using the -wid window_id

 > >>> parameter. In the software I help to develop we want to do

something

 > >>> like that, a raycasting rendering from process A being

drawing in the

 > >>> process B using wxPython. Is it possible?

 >

 > >> On Windows it might be doable.  wx.Window_FromHWND(None,

handle) can

 > >> wrap a wx.Window around an existing window handle, so you can

then bind

 > >> paint events for it, etc.  On the other platforms it will just

raise an

 > >> exception.  If anybody would like to figure out how to do

something like

 > >> that for the other platforms I would love to get some patches

submitted

 > >> for it.

 > > Thanks Robin! You have some example?

 >

 > No.



Ok. Here we'll try to do that and post a example here.

Hi Robin,

We made a small example, but have 2 questions.

When you run the second process (1.py) is added to the panel frame of

the first process (0.py), but it quickly disappears, the MainLoop ()

terminates immediately.

Normally MainLoop will exit when there are no more top-level windows or TaskBarIcons. So as Ray tried to explain you can get around this by creating a frame, even if you never show it. Another possibility is to use prog2.SetExitOnFrameDelete(False), however I seem to recall that that may still allow MainLoop to exit if there are never any frames created at all…

The second question is, wxPython has some “special” way of making two

applications to communicate? so for me to pass the id of the first

application for the second.

There are several IPC mechanisms available to Python, so there hasn’t been any need to add it to wxPython.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mejak,

The pubsub only communicates with the frames in the same App.

I want to communicate in different frames App.

Thax,
Paulo

Paulo,

I just use sockets to pass messages with a listener task that raises an event on receiving a complete message to pass it to the GUI element, (pubsub could well have been used instead of raising an event but I was not aware of it at the time.

Gadget/Steve

···

From: Paulo Henrique Junqueira Amorim

Sent: Tuesday, October 26, 2010 11:08 AM

To: wxpython-users@googlegroups.com

Subject: Re: [wxPython-users] Re: Drawing in another window

Hi,

···

On Tue, Oct 26, 2010 at 8:01 AM, Steve Barnes <GadgetSteve@live.co.uk> wrote:

I just use sockets to pass messages with a listener task that raises an
event on receiving a complete message to pass it to the GUI element, (pubsub
could well have been used instead of raising an event but I was not aware of
it at the time.

No, pubsub is not threadsafe, you can't call into the gui thread from
a background thread safely with it. So you are right to use events for
this task.

Cody

No, it doesn't ! App 1.py doesn't modify the frame created in app
0.py .
It simply creates another frame of its own.

Ray

···

On Oct 25, 7:32 pm, Paulo Henrique Junqueira Amorim <paulojamo...@gmail.com> wrote:

Thanks!!!!! Robin and Pasco,

Worked perfectly!! Simply create wx.Frame in the __init__ of the 1.py.

Hi,

···

-----Original Message----- From: Cody Precord
Sent: Tuesday, October 26, 2010 2:12 PM
To: wxpython-users@googlegroups.com
Subject: Re: [wxPython-users] Re: Drawing in another window

On Tue, Oct 26, 2010 at 8:01 AM, Steve Barnes <GadgetSteve@live.co.uk> wrote:

I just use sockets to pass messages with a listener task that raises an
event on receiving a complete message to pass it to the GUI element, (pubsub
could well have been used instead of raising an event but I was not aware of
it at the time.

No, pubsub is not threadsafe, you can't call into the gui thread from
a background thread safely with it. So you are right to use events for
this task.

Cody

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Nice when you are right through being a lot ignorant rather than getting it wrong through knowing a little, :wink:

Gadget/Steve

Thanks!!! Robin and Pasco,

Worked perfectly!! Simply create wx.Frame in the init of the 1.py.

No, it doesn’t ! App 1.py doesn’t modify the frame created in app

0.py .

It simply creates another frame of its own.

Ray,

Yeah, I add the Frame (not visible) in the 1.py because when you run the panel then closed.

The Robin said there must be a Frame MainLoop to be running.

Normally MainLoop will exit when there are no more top-level windows or TaskBarIcons. So as Ray tried to explain you can get around this by creating a frame, even if >>you never show it. Another possibility is to use prog2.SetExitOnFrameDelete(
False), however I seem to recall that that may still allow MainLoop to exit if there are never any frames created at all…

About pubsub, the pubsub does not communicate with different wx.App, I’m using socket for this.

Regards,
Paulo

···

On 26 October 2010 14:28, Ray Pasco pascor5071@gmail.com wrote:

On Oct 25, 7:32 pm, Paulo Henrique Junqueira Amorim > paulojamo...@gmail.com wrote:

Ray

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Thanks!!! Robin and Pasco,

Worked perfectly!! Simply create wx.Frame in the init of the 1.py.

What remains now is how to do this on other platforms.

It would be wonderful if anyone knows how to make Linux and Mac

Regards and Thx,
Paulo

Run the attached app to see how it’s done in MSW.

···

On Mon, Oct 25, 2010 at 7:32 PM, Paulo Henrique Junqueira Amorim paulojamorim@gmail.com wrote:

On 25 October 2010 15:00, Robin Dunn robin@alldunn.com wrote:

On 10/24/10 7:01 AM, Paulo Henrique Junqueira Amorim wrote:

> >>> A great feature from mplayer is the capability of drawing the

played

> >>> movie in a window from another process using the -wid window_id
> >>> parameter. In the software I help to develop we want to do

something
> >>> like that, a raycasting rendering from process A being

drawing in the
> >>> process B using wxPython. Is it possible?
>
> >> On Windows it might be doable. wx.Window_FromHWND(None,
handle) can
> >> wrap a wx.Window around an existing window handle, so you can

then bind
> >> paint events for it, etc. On the other platforms it will just
raise an
> >> exception. If anybody would like to figure out how to do
something like
> >> that for the other platforms I would love to get some patches

submitted
> >> for it.
> > Thanks Robin! You have some example?
>
> No.

Ok. Here we’ll try to do that and post a example here.

Hi Robin,

We made a small example, but have 2 questions.

When you run the second process (1.py) is added to the panel frame of
the first process (0.py), but it quickly disappears, the MainLoop ()
terminates immediately.

Normally MainLoop will exit when there are no more top-level windows or TaskBarIcons. So as Ray tried to explain you can get around this by creating a frame, even if you never show it. Another possibility is to use prog2.SetExitOnFrameDelete(False), however I seem to recall that that may still allow MainLoop to exit if there are never any frames created at all…

The second question is, wxPython has some “special” way of making two
applications to communicate? so for me to pass the id of the first

application for the second.

There are several IPC mechanisms available to Python, so there hasn’t been any need to add it to wxPython.


Robin Dunn

Software Craftsman

http://wxPython.org


To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en


To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Oops - Run the attached app for an example modifying another app’s frame. MSW-only.

Ray

EXTERNAL_FRAME_MODIFY.zip (17.5 KB)

···

On 25 October 2010 15:00, Robin Dunn robin@alldunn.com wrote:

On 10/24/10 7:01 AM, Paulo Henrique Junqueira Amorim wrote:

> >>> A great feature from mplayer is the capability of drawing the

played

> >>> movie in a window from another process using the -wid window_id
> >>> parameter. In the software I help to develop we want to do

something
> >>> like that, a raycasting rendering from process A being

drawing in the
> >>> process B using wxPython. Is it possible?
>
> >> On Windows it might be doable. wx.Window_FromHWND(None,
handle) can
> >> wrap a wx.Window around an existing window handle, so you can

then bind
> >> paint events for it, etc. On the other platforms it will just
raise an
> >> exception. If anybody would like to figure out how to do
something like
> >> that for the other platforms I would love to get some patches

submitted
> >> for it.
> > Thanks Robin! You have some example?
>
> No.