Restore minimized app on MacOS

I’ve written a small app to act as a script launcher Github link. It does not have a menu, but I had to disable the system controls (minimize/maximize/close) on the frame because I was unable to determine what I needed to do to make it restore from the system task bar.

Can anyone point me to an example on how to do that?

Thanks!

Chuck

I think your chances are better with a minimum working code sample.

A wrong github link to a project with unknown entry point and also with external dependencies will not encourage people to look a the problem.
I’m out…

Sorry, fixed the link. I’m having to type one-handed due to an injury… :frowning:

I fixed the link, but that has nothing to do with the question asked. I asked for an example of how to restore a minimized app that did not have an application menu, not for someone to fix my code. I’m fine if there is not one. A minimal example is any of the sample apps in the tutorial.

Sadly, with py2app and pyinstall broken in MacOS Big Sur, it looks like I’ll have to fall back to wxWidgets or another cross-platform library to be able to distribute apps.

Well, I’m not aware of minimization problems on macOS, but I’m only using it for testing sometimes.

Without a code sample, you only have the chance that someone had the same problem and reads your post and identifies the problem as being the same.

With a code sample, people will run it. Sometimes, it turns out that the way to run the script is causing the problem. If not, people can experiment with events and styles and maybe find a solution.

The second approach is much more promising…

The link to the repo is fixed, but the app is just a frame, a panel, and a modal dialog, the latter of which shouldn’t matter. I don’t know that it’s a “problem” per se, but I’m not finding anything that talks about how to restore a minimized app. I’ll keep looking, but I had hoped that someone had already seen this before as I’d have a hard time thinking it was a brand new issue. :man_shrugging:

Does frame.Iconize(False) not work?

Hi Robin,

As per the original post, I’m looking for an example of how to look for an event to cause the application to restore from being iconized/minimized/etc. to the Mac dock. Do I just need to bind an event handler to a click event and check to see if the app is minimized?

Thanks!

Chuck

I’ll second the request for an example. See HOWTO: Get help with a small runnable sample

Not sure I’m following what you’re saying. The main frame is below. As I mentioned, I’m not even sure what event to be looking for…

import os
import glob
import wx
import wx.grid
from MainPanel import MainPanel

class MainFrame(wx.Frame):
    """
    Main frame for the PyDevMgr application
    """
    def __init__(self):
        super().__init__(None, title='pylaunch', style=wx.CAPTION, size=wx.Size(300,600))


        panel = MainPanel(self)
        self.Bind(wx.EVT_BUTTON, self.__on_close, id=wx.ID_EXIT)
        self.Show()

    def __on_close(self, event):
        self.Destroy()

if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MainFrame()
    app.MainLoop()

Note: that is not a runnable sample. There is no MainPanel module.

Without the system controls on the title bar how is the window going to be minimized in the first place? Presumably you’ll have some code somewhere that will call self.Iconize(True). But once it is iconized then it can automatically be restored from the Dock simply by clicking on the app’s icon just like any other application. There is no need to do anything special to handle that, it’s built-in.

If you need something more than the built-in behavior then maybe you are looking for the wx.adv.TaskbarIcon class. You can see an example of how to use it in the main part of the wxPython demo (in Main.py).

The issue is that once the app was minimized using the button on the frame, clicking the app did not restore it. That’s why I was looking for sample code in the first place. :man_shrugging:

Ah, I think I finally understand, sorry to be so thick-headed.

It looks like something may have changed here. Clicking the Dock icon does indeed not do anything by default anymore. I was clicking the minimized document icon on the right end of the dock which works, but if you have your system set to hide the doc icons in the app then it may not be able to get that far.

Try creating a new class derived from wx.App and adding this method or something like it:

    def MacReopenApp(self):
        top = self.GetTopWindow()
        if top and top.IsIconized():
            top.Iconize(False)
        if top:
            top.Raise()

Hi Robin,

Just had a chance to try this and it works like a charm!

Just wondering if that should be folding into the main line of the code because it is the expected behavior. :thinking::thinking:

Merry Christmas!

No. I don’t recall any specific discussions about the change, but I would guess that there was a good reason that it was removed from the default behavior. Probably something like getting closer to native behavior, or making it easier to do something different in response to that stock system event.

Hmm, odd. I would think that the default behavior should be overridden rather than adding it in after the fact. Oh well, as long as there is a workaround, I’m good. :man_shrugging: