Re: Gnome "Quit" menu is like clicking a button in a wxPython modal dialog
Matthias Brennwald <[email protected]> Sun, 13 Dec 2020 10:33:14 +0100
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Dec 13, 2020 at 00:47, Dietmar Schwertberger <[email protected]> wrote: > I don't find your video particularly helpful. A small code sample > plus observation would have been much more useful. > > What is your actual problem? When you close a dialog via the system > menu or the close icon of the window decoration, the return value is > the same as if you hit Cancel or the Escape key. > The return value of dlg.ShowModal() is identical to wx.ID_CANCEL in > these cases. The Cancel button has the Id wx.ID_CANCEL. Ok, here's a trivial code example to illustrate my problem: ----------------- import wx app = wx.App() ans = wx.MessageBox('Hello World', 'Info', wx.OK | wx.ICON_INFORMATION) if ans == 4: print('User clicked OK or pressed ENTER.') elif ans == 16: print('User pressed ESC.') else: print('Whoops, I have no clue what happened.') ----------------- My problem is that if the user chooses "Quit" from the menu at the top, the application will think that the user pressed the ESC button, which is not correct. Using a MessageBox in the context of a larger application, the "Quit" menu creates confusion: "Quit" is intended to quit the application, not to quit the MessageBox. On Sat, Dec 12, 2020 at 17:51, Tim Roberts <[email protected]> wrote: > Do you understand that’s NOT the “Gnome Shell” menu? That’s > your application’s menu. Oh... No, I was not aware of this. I did not write ANY code dealing with menus, so I didn't think that I had a menu somewhere in my application. > All of this is in your application’s control. What action do you > take when the Quit menu item is picked? My application has what I call a "main" frame. This frame has an "exit" method, which is used to quit the application (as the user if he/she really wants to quit, and clean up things before exiting). I guess the "Quit" menu should trigger this method. In any case, I don't want the "Quit" menu to mess with with the MessageBoxes or anything else in my GUI. How do I get a grip on the menu that Gnome gave to my application? How can I change the "Quit" menu to NOT mess with anything of the GUI (except the exit method of my main window)? How can I deal with this in a platform-independent way (so I don't have to write specific code for Gnome, MacOS, Windows, etc.)? (I tried Google, but couldn't find anything useful. I guess I don't know what I am looking for...) -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/EJU9LQ.MBY8XYXW6ZJ11%40gmail.com.