wxMac: Hiding the frame on close

Hi all,

Usually (X) will cause the application to close.

I would like to change it in my main frame to the following behaviour:

-1- The close button will only hide my application and will keep it active in the dock.

-2- Unlike minimizing, there should be no window icon in the dock, only the application icon should be shown.

-3- The right click menu of the dock icon should show ‘Show Application’ and not ‘Hide application’.

The above is for wxMac only of course.

I have tried using EVT_CLOSE event handler like this (and with many other variations…):

self.Bind(wx.EVT_CLOSE, self.OnClose)

def OnClose(self, event):
if wx.Platform == “WXMAC” and event.CanVeto():
self.Iconize(True)
self.Hide()
event.Veto()
else:
self.OnCloseWindow(event) # This function also calls destroy

Nothing seems to match all three conditions.

Thanks in advance,

Roee.

Hello,

To get this behavior you can call wx.App.SetExitOnFrameDelete(False) after you create your app instance so it will stay alive after your last frame is destroyed.

Cody

···

On Feb 21, 2008, at 10:29 AM, roee shlomo wrote:

Hi all,

Usually (X) will cause the application to close.
I would like to change it in my main frame to the following behaviour:
-1- The close button will only hide my application and will keep it active in the dock.
-2- Unlike minimizing, there should be no `window icon` in the dock, only the application icon should be shown.
-3- The right click menu of the dock icon should show 'Show Application' and not 'Hide application'.
The above is for wxMac only of course.

I have tried using EVT_CLOSE event handler like this (and with many other variations...):
    self.Bind(wx.EVT_CLOSE, self.OnClose)
    def OnClose(self, event):
        if wx.Platform == "__WXMAC__" and event.CanVeto():
            self.Iconize(True)
            self.Hide()
            event.Veto()
        else:
            self.OnCloseWindow(event) # This function also calls destroy
Nothing seems to match all three conditions.

Thanks in advance,
Roee.

Hi,

From: roee shlomo [mailto:roee88@gmail.com]
Sent: Thursday, February 21, 2008 10:29 AM
To: wxpython-users@lists.wxwidgets.org
Subject: wxMac: Hiding the frame on close

Hi all,

Usually (X) will cause the application to close.
I would like to change it in my main frame to the following behaviour:
-1- The close button will only hide my application and will
keep it active in the dock.
-2- Unlike minimizing, there should be no `window icon` in
the dock, only the application icon should be shown.
-3- The right click menu of the dock icon should show 'Show
Application' and not 'Hide application'.
The above is for wxMac only of course.

I have tried using EVT_CLOSE event handler like this (and
with many other variations...):

      self.Bind(wx.EVT_CLOSE, self.OnClose)
      def OnClose(self, event):
          if wx.Platform == "__WXMAC__" and event.CanVeto():
              self.Iconize(True)
              self.Hide()
              event.Veto()
          else:
              self.OnCloseWindow(event) # This function
also calls destroy

Nothing seems to match all three conditions.

Thanks in advance,
Roee.

I don't do the exact same thing that you're talking about, but it's quite
similar (although I use Windows XP and I actually minimize to the tray).
Also, when I create my application, I have the icon already created.
However, I would think you could catch the EVT_CLOSE and do the icon
creation then. So something like this *untested* code:

<code>

self.Bind(wx.EVT_CLOSE, self.onClose)

def onClose(self, event):
    # I'm not sure if this IF of yours will work or not...
    if wx.Platform == "__WXMAC__" and event.CanVeto():
        # create icon from the Demo
        self.tbicon = TaskBarIcon(self.frame, self.iconfilepath)
        self.Hide()

</code>

Then in the TaskbarIcon code, you'd want to edit the "CreatePopupMenu()"
method to have the appropriate menu items. Basically something like this:

<code>
menu = wx.Menu()
menu.Append(self.TBMENU_RESTORE, "Show Application")
</code>

Hopefully that isn't completely confusing.

Mike

···

-----Original Message-----

roee shlomo wrote:

Hi all,
Usually (X) will cause the application to close.
I would like to change it in my main frame to the following behaviour:
-1- The close button will only hide my application and will keep it active in the dock.
-2- Unlike minimizing, there should be no `window icon` in the dock, only the application icon should be shown.
-3- The right click menu of the dock icon should show 'Show Application' and not 'Hide application'.
The above is for wxMac only of course.
I have tried using EVT_CLOSE event handler like this (and with many other variations...):

        self.Bind(wx.EVT_CLOSE, self.OnClose)
        def OnClose(self, event):
            if wx.Platform == "__WXMAC__" and event.CanVeto():
                self.Iconize(True)
                self.Hide()
                event.Veto()
            else:
                self.OnCloseWindow(event) # This function also calls
    destroy

Nothing seems to match *all* three conditions.

Does it behave the way you want if you remove the Iconize()?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

I saw Stefan’s answer , so I understand it is not currently possible via wxPython API.

After more googling I found out I can use python itself to do that:

cmd = “”“osascript -e ‘tell application “System Events” to set visible of process “MyApplicationName” to false’”“”

os.system(cmd)
Now all I need to find out is what “MyApplicationName” is after building an app bundle.

This has nothing to do with wxPython :slight_smile:
So let me just say thanks a lot for the hints Robin!

Roee.

···

On 2/22/08, Robin Dunn robin@alldunn.com wrote:

roee shlomo wrote:

Hi Cody and Mike,

First let me say thanks a lot for your responses.

you can call wx.App.SetExitOnFrameDelete(False)

I looked at SetExitOnFrameDelete a few hours ago. Unfortunately it is
not what I need.
I want to keep the frame itself alive, not just the app.

Sorry for not being so clear about it earlier.
Actually a simple call to Hide() should do the work, but the menu
doesn’t update accordingly.

I don't do the exact same thing that you're talking about, but it's
quite
similar (although I use Windows XP and I actually minimize to the tray).

I already got it working on wxMSW and wxGTK.
Mac is the tricky one because (1) it has in the dock both application

icon and an icon for any minimized frame. (2) The popup menu has some
default items provided by the system.

The problem probably boils down to the fact that the system’s Show/Hide
functionality is for the whole application, not for the individual frame

(even if your app has only one frame.) I’ll ask Stefan about this and
see if there is already a way in the wx API to Show/Hide the app the way
the system expects.


Robin Dunn
Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

roee shlomo wrote:

Hi Robin,
I saw Stefan's answer <http://www.nabble.com/wxMac-Show-HIde-application-td15623893.html&gt; , so I understand it is not currently possible via wxPython API.

I've added a method to wx.App called MacHideApp using the code Stefan suggested.

After more googling I found out I can use python itself to do that:

    cmd = """osascript -e 'tell application "System Events" to set
    visible of process "MyApplicationName" to false'"""
    os.system(cmd)

Be prepared for that to take a second or two the first time, as it will have to launch System Events which will then have to hunt for MyApplicationName.

Now all I need to find out is what "MyApplicationName" is after building an app bundle.

If you're the one building the bundle then you know what it is. :wink:

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Be prepared for that to take a second or two the first time, as it will
have to launch System Events which will then have to hunt for

MyApplicationName.
Yes you are right, this is taking way too long.

Python has some built in libraries for sending Apple Events, but most of them are either deprecated or undocumented.

If you’re the one building the bundle then you know what it is. :wink:
Heh :slight_smile:

I was afraid the process name will be ‘Python’ as shown in the menubar before bundling. This isn’t the case though.

I’ve added a method to wx.App called MacHideApp using the code Stefan
suggested

Thanks!

···

On Sun, Feb 24, 2008 at 1:55 AM, Robin Dunn robin@alldunn.com wrote:

roee shlomo wrote:

Hi Robin,

I saw Stefan’s answer

<http://www.nabble.com/wxMac-Show-HIde-application-td15623893.html> , so
I understand it is not currently possible via wxPython API.

I’ve added a method to wx.App called MacHideApp using the code Stefan
suggested.

After more googling I found out I can use python itself to do that:

cmd = """osascript -e 'tell application "System Events" to set
visible of process "MyApplicationName" to false'"""
os.system(cmd)

Be prepared for that to take a second or two the first time, as it will
have to launch System Events which will then have to hunt for

MyApplicationName.

Now all I need to find out is what “MyApplicationName” is after building
an app bundle.

If you’re the one building the bundle then you know what it is. :wink:

Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org