Пример #1
0
    def OnCloseWindow(self, event = None, force = False):
        found = False
        if event != None:
            nr = event.GetEventType()
            lookup = { wx.EVT_CLOSE.evtType[0]: "EVT_CLOSE", wx.EVT_QUERY_END_SESSION.evtType[0]: "EVT_QUERY_END_SESSION", wx.EVT_END_SESSION.evtType[0]: "EVT_END_SESSION" }
            if nr in lookup:
                nr = lookup[nr]
                found = True

            print >>sys.stderr, "mainframe: Closing due to event ",nr,`event`
        else:
            print >>sys.stderr, "mainframe: Closing untriggered by event"


        # Don't do anything if the event gets called twice for some reason
        if self.utility.abcquitting:
            print
            return

        # Check to see if we can veto the shutdown
        # (might not be able to in case of shutting down windows)
        if event is not None:
            try:
                if isinstance(event,wx.CloseEvent) and event.CanVeto() and self.utility.config.Read('confirmonclose', "boolean") and not event.GetEventType() == wx.EVT_QUERY_END_SESSION.evtType[0]:
                    if self.shutdown_and_upgrade_notes:
                        confirmmsg = self.utility.lang.get('confirmupgrademsg') + "\n\n" + self.shutdown_and_upgrade_notes
                        confirmtitle = self.utility.lang.get('confirmupgrade')
                    else:
                        confirmmsg = self.utility.lang.get('confirmmsg')
                        confirmtitle = self.utility.lang.get('confirm')

                    dialog = wx.MessageDialog(self, confirmmsg, confirmtitle, wx.OK|wx.CANCEL|wx.ICON_QUESTION)
                    result = dialog.ShowModal()
                    dialog.Destroy()
                    if result != wx.ID_OK:
                        event.Veto()

                        print >>sys.stderr, "mainframe: Not closing messagebox did not return OK"
                        return
            except:
                print_exc()

        self.utility.abcquitting = True
        self.GUIupdate = False

        if VideoPlayer.hasInstance():
            print >>sys.stderr, "mainframe: Closing videoplayer"

            videoplayer = VideoPlayer.getInstance()
            videoplayer.stop_playback()

        try:
            print >>sys.stderr, "mainframe: Restoring from taskbar"

            # Restore the window before saving size and position
            # (Otherwise we'll get the size of the taskbar button and a negative position)
            self.onTaskBarActivate()
            self.saveWindowSettings()
        except:
            print_exc()

        if self.tbicon is not None:
            try:
                print >>sys.stderr, "mainframe: Removing tbicon"

                self.tbicon.RemoveIcon()
                self.tbicon.Destroy()
            except:
                print_exc()

        try:
            print >>sys.stderr, "mainframe: Calling Destroy"
            self.Destroy()
        except:
            print_exc()

        print >>sys.stderr, "mainframe: Calling quit"
        self.quit(event != None or force)
        self.Destroy()

        if DEBUG:
            print >>sys.stderr,"mainframe: OnCloseWindow END"
            ts = enumerate()
            for t in ts:
                print >>sys.stderr,"mainframe: Thread still running",t.getName(),"daemon",t.isDaemon()