Mac equivalent of several win32gui methods

1,572 views
Skip to first unread message

Fahri

unread,
Nov 29, 2010, 1:56:31 PM11/29/10
to wxPython-users
Hi,

I am porting a windows wxPython application to Mac OSX. Windows
version uses two win32gui methods.

Here are the methods I need:

win32gui.GetActiveWindow()
win32gui.EnumWindows(winHandler, topWindows)

Any documentation performing these tasks on a Mac?

Thank you in advance for your help.

Fahri

Cody Precord

unread,
Nov 29, 2010, 2:02:05 PM11/29/10
to wxpytho...@googlegroups.com
Hi,

You will need to provide some specifics of what you are using the
methods for but there are platform independent methods in wx itself
that perform the same task (depending upon the usage).

On Mon, Nov 29, 2010 at 12:56 PM, Fahri <mang...@gmail.com> wrote:
> Hi,
>
> I am porting a windows wxPython application to Mac OSX.  Windows
> version uses two win32gui methods.
>
> Here are the methods I need:
>
> win32gui.GetActiveWindow()

app = wx.GetApp()
app.GetTopWindow()

> win32gui.EnumWindows(winHandler, topWindows)

windowList = wx.GetTopLevelWindows()


Cody

Robin Dunn

unread,
Nov 29, 2010, 2:24:19 PM11/29/10
to wxpytho...@googlegroups.com
On 11/29/10 10:56 AM, Fahri wrote:
> Hi,
>
> I am porting a windows wxPython application to Mac OSX. Windows
> version uses two win32gui methods.
>
> Here are the methods I need:
>
> win32gui.GetActiveWindow()
> win32gui.EnumWindows(winHandler, topWindows)

What are you using them for? Perhaps there is a wx way to do it that
would not require calling native APIs. For example, to find the active
frame in your application this would probably work:

for win in wx.GetTopLevelWindows():
if win.IsActive():
return win
return None


>
> Any documentation performing these tasks on a Mac?

If you can find the API you need then you can use ctypes to call
functions in the Carbon library. I expect that PyObjC could be used to
call Cocoa methods in a Cocoa build of wx, but I've never tried it.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Robin Dunn

unread,
Nov 29, 2010, 2:24:43 PM11/29/10
to wxpytho...@googlegroups.com
On 11/29/10 11:02 AM, Cody Precord wrote:
> Hi,
>
> You will need to provide some specifics of what you are using the
> methods for but there are platform independent methods in wx itself
> that perform the same task (depending upon the usage).
>
> On Mon, Nov 29, 2010 at 12:56 PM, Fahri<mang...@gmail.com> wrote:
>> Hi,
>>
>> I am porting a windows wxPython application to Mac OSX. Windows
>> version uses two win32gui methods.
>>
>> Here are the methods I need:
>>
>> win32gui.GetActiveWindow()
>
> app = wx.GetApp()
> app.GetTopWindow()

That isn't the same. GetTopWindow only returns the window you passed to
SetTopWindow, or the first top-level window created if SetTopWindow
wasn't called. If there is more than one top-level window in the
application then that one may or may not be the active one.

Fahri

unread,
Nov 29, 2010, 2:27:20 PM11/29/10
to wxPython-users
Hi Cody,

Thank you for your prompt reply. I am using these functions for the
"Auto Save" feature in my application. The way my scheme works I need
to get a list of all open windows to detect all running instances of
my application. AFAIK wx.GetTopLevelWindows() does not return all
open windows but only the ones belong to the application itself.
Since I am trying to detect multiple instances of my application this
doesn't help me. I think I need a native OS function for this. Since
I don't even know what it is called I am having difficulties searching
for it.

Fahri


On Nov 29, 2:02 pm, Cody Precord <codyprec...@gmail.com> wrote:
> Hi,
>
> You will need to provide some specifics of what you are using the
> methods for but there are platform independent methods in wx itself
> that perform the same task (depending upon the usage).
>

Robin Dunn

unread,
Nov 29, 2010, 2:34:00 PM11/29/10
to wxpytho...@googlegroups.com
On 11/29/10 11:27 AM, Fahri wrote:
> Hi Cody,
>
> Thank you for your prompt reply. I am using these functions for the
> "Auto Save" feature in my application. The way my scheme works I need
> to get a list of all open windows to detect all running instances of
> my application. AFAIK wx.GetTopLevelWindows() does not return all
> open windows but only the ones belong to the application itself.
> Since I am trying to detect multiple instances of my application this
> doesn't help me. I think I need a native OS function for this. Since
> I don't even know what it is called I am having difficulties searching
> for it.

That may not be an issue on the Mac as you should not have multiple
instances of your application running. Instead Mac applications will
typically have one or more document windows (wx.Frames) open, all of
them running in the same process.

Cody Precord

unread,
Nov 29, 2010, 2:34:07 PM11/29/10
to wxpytho...@googlegroups.com
Hi,

Forgot about that as I usually have a OnActivate handling in my base
toplevel window class that calls SetTopWindow.

Something along the following lines could be equivalent if the usage
is app centric:

def GetActiveWindow():
for win in wx.GetTopLevelWindows():
if getattr(win, 'IsActive', lamba:False)():
return win


Cody

Fahri

unread,
Nov 29, 2010, 2:40:21 PM11/29/10
to wxPython-users
Hi Robin,

The difficult part for me is not getting the handler of the active
window but getting a list of all open windows' handlers. As I wrote
in my reply to Cody's reply I need this for my "Auto Save" feature. I
guess there are other ways I can handle auto-saving but since the
current implementation has been tested and functioning well, I would
like to port it as is.

If I can find the Carbon equivalent of win32gui.EnumWindows then I can
call it with Ctypes as you recommended. Maybe someone already knows
what this function is called in Carbon, if not I will have to dig
deeper.

Fahri

Fahri

unread,
Nov 29, 2010, 2:45:50 PM11/29/10
to wxPython-users
If that's the case then I may not even need the win32gui.EnumWindows.
I will test this now.

Thanks,

Fahri
Reply all
Reply to author
Forward
0 new messages