What's the correct way to cleanly terminate a Phoenix app?

I’m just starting out learning Phoenix.

At the moment I’m using this model:

#!/usr/bin/env python3
import sys
import wx

class MainWindow(wx.Frame):

def __init__(self, parent, title):
    super().__init__(parent, title=title, size=(600, 400))
    filemenu= wx.Menu()
    menuQuit = filemenu.Append(wx.ID_EXIT,"&Quit", "Quit")
    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File")
    self.SetMenuBar(menuBar)
    self.Bind(wx.EVT_MENU, self.OnClose, menuQuit)
    self.Bind(wx.EVT_CLOSE, self.OnClose)
    self.Show(True)

def OnClose(self, event):
    print("OnClose") # Save config etc. here
    self.Destroy()

app = wx.App()
frame = MainWindow(None, “Test”)
app.MainLoop()

This means that no matter if the user clicks File->Quit, or presses Ctrl+Q (which wx seems to give me for free), or clicks the window’s X close button, the OnClose method is called. So the code works. My question is, is this the correct way to do it?

Thanks.

Yes, that's all pretty normal. You want your close actions to all
result in an EVT_CLOSE event, which should route to a single function
where you do your clean up and call Destroy.

The only minor picky quibble I might make is that the menuQuit handler
should probably call self.Close, which would then trigger the onClose
handler, but that's an extremely minor religious point that would not
make a difference except in extreme circumstances.

···

'Mark Summerfield' via wxPython-users wrote:

I'm just starting out learning Phoenix.

At the moment I'm using this model:
...
This means that no matter if the user clicks File->Quit, or presses
Ctrl+Q (which wx seems to give me for free), or clicks the window's X
close button, the OnClose method is called. So the code works. My
question is, is this the correct way to do it?

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

To completely quit the app, you can use wx.Exit().

···

Le lundi 20 mars 2017 16:41:55 UTC+1, Mark Summerfield a écrit :

I’m just starting out learning Phoenix.

At the moment I’m using this model:

#!/usr/bin/env python3
import sys
import wx

class MainWindow(wx.Frame):

def __init__(self, parent, title):
    super().__init__(parent, title=title, size=(600, 400))
    filemenu= wx.Menu()
    menuQuit = filemenu.Append(wx.ID_EXIT,"&Quit", "Quit")
    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File")
    self.SetMenuBar(menuBar)
    self.Bind(wx.EVT_MENU, self.OnClose, menuQuit)
    self.Bind(wx.EVT_CLOSE, self.OnClose)
    self.Show(True)

def OnClose(self, event):
    print("OnClose") # Save config etc. here
    self.Destroy()

app = wx.App()
frame = MainWindow(None, “Test”)
app.MainLoop()

This means that no matter if the user clicks File->Quit, or presses Ctrl+Q (which wx seems to give me for free), or clicks the window’s X close button, the OnClose method is called. So the code works. My question is, is this the correct way to do it?

Thanks.