ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pythoncard
pythoncard
RE: [Pythoncard-users] app close event?
by Kevin Altis other posts by this author
Apr 19 2002 4:23PM messages near this date
[Pythoncard-users] app close event? | [Pythoncard-users] what does an event object look like
>  From: David Primmer
> 
>  I have to do database cleanup when my app closes. I have it working in
>  the menu>exit event handler but what about if someone clicks the close
>  button on my app? How do I capture that?

OnCloseWindow

It is used in addresses, dbBrowser, findfiles, resourceEditor,
searchexplorer, textEditor, and textRouter

The close window event is bound in the Background class, it just isn't
wrapped for the PythonCard events yet. I'll probably look at wrapping close,
move, and size in the next release. If you want to use OnCloseWindow now,
the only change to your code later should be the method name, which will
probably be "on_closeBackground" to match "on_openBackground" and instead of
directly calling the event superclass you'll probably call event.Skip()

The addresses sample shows the simple solution since it only has a single
persistent document and the user never has to worry about new/open/save, the
app just does it automatically.

# addresses.py

    def doExit(self):
        self.document.saveFile()

    # we don't have window events hooked up yet to our own event model yet
    def OnCloseWindow(self, event):
        self.doExit()
        model.Background.OnCloseWindow(self, event)

    def on_exit_command(self, event):
        self.Close()

As the above code shows, the File-> Exit menu item which in addresses is
bound to a command just calls the wxPython method Close() to close the
window. That is the same as clicking the close box on the window and
triggers the close window event, so that OnCloseWindow is called. I placed
the work to be done when the document is closing in doExit. When you
override OnCloseWindow, you need to call the superclass OnCloseWindow method
for the application to actually quit.

The textEditor sample is similar, but since it has a document that requires
the user to be prompted, the doExit method returns a boolean, so that the
close window action can be cancelled.

# textEditor.pyw

    def doExit(self):
        if self.documentChanged:
            save = self.saveChanges()
            if save == "Cancel":
                return 0
            elif save == "No":
                return 1
            else:
                if self.documentPath == None:
                    return self.on_menuFileSaveAs_select(None)
                else:
                    self.saveFile(self.documentPath)
                    return 1
        else:
            return 1

    # we don't have window events hooked up yet to our own event model yet
    def OnCloseWindow(self, event):
        if self.doExit():
            self.saveConfig()
            model.Background.OnCloseWindow(self, event)

    def on_menuFileExit_select(self, event):
        self.Close()


ka


_______________________________________________
Pythoncard-users mailing list
Pythoncard-users@[...].net
https://lists.sourceforge.net/lists/listinfo/pythoncard-users
Thread:
David Primmer
Kevin Altis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved