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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

wxPython-users mailing list-2
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.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Tim Roberts
'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?

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.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Adrien Tétar
In reply to this post by wxPython-users mailing list-2
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.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...