def close(self, force=False): """ Closes the window. This fires the :py:attr:`closing` vetoable event, giving listeners the opportunity to veto the closing of the window. If :py:obj:`force` is :py:obj:`True` then the window will close no matter what. If the window is closed, the closed event will be fired with the window object as the event value. Parameters ---------- force : bool Whether the window should close despite vetos. Returns ------- closed : bool Whether or not the window is closed. """ if self.control is not None: self.closing = event = Vetoable() if force or not event.veto: self.destroy() self.closed = self return self.control is None
def open(self): """ Open the window. Overridden to make the 'opening' event vetoable. Return True if the window opened successfully; False if the open event was vetoed. """ logger.debug("window %s opening", self) # Trait notification. self.opening = event = Vetoable() if not event.veto: if self.control is None: self._create() self.show(True) # Trait notification. self.opened = self logger.debug("window %s opened", self) else: logger.debug("window %s open was vetoed", self) # fixme: This is not actually part of the Pyface 'Window' API (but # maybe it should be). We return this to indicate whether the window # actually opened. return self.control is not None
def _on_window_closing(self, window, trait_name, event): """ Dynamic trait change handler. """ # Event notification. self.window_closing = window_event = VetoableWindowEvent(window=window) if window_event.veto: event.veto = True else: # Is this the last open window? if len(self.windows) == 1: # If this is an 'implicit exit' then make sure that we fire the # appropriate workbench lifecycle events. if not self._explicit_exit: # Event notification. self.exiting = window_event = Vetoable() if window_event.veto: event.veto = True if not event.veto: # Save the window size, position and layout. self._save_window_layout(window) return
def close(self): """ Close the editor. """ if self.control is not None: self.closing = event = Vetoable() if not event.veto: self.editor_area.remove_editor(self) self.closed = True
def close(self): """ Close the editor. """ if self.control is not None: self.closing = event = Vetoable() if not event.veto: self.window.close_editor(self) self.closed = True return
def close(self): """ Closes the window. Overriden to make the 'closing' event vetoable. Returns whether the window was closed. """ if self.control is not None: self.closing = event = Vetoable() if not event.veto: self.destroy() self.closed = self return self.control is None
def _can_exit(self): """ Is exit vetoed by anything? The default behaviour is to fire the :py:attr:`exiting` event and check to see if any listeners veto. Subclasses may wish to override to perform additional checks. Returns ------- can_exit : bool Return True if exit is OK, False if something vetoes the exit. """ self.exiting = event = Vetoable() return not event.veto
def _can_exit(self): """ Check with each window to see if it can be closed The fires closing events for each window, and returns False if any listener vetos. """ if not super(GUIApplication, self)._can_exit(): return False for window in reversed(self.windows): window.closing = event = Vetoable() if event.veto: return False else: return True
def close(self): """ Closes the window. Overridden to make the 'closing' event vetoable. Return True if the window closed successfully (or was not even open!), False if the close event was vetoed. """ logger.debug("window %s closing", self) if self.control is not None: # Trait notification. self.closing = event = Vetoable() # fixme: Hack to mimic vetoable events! if not event.veto: # Give views and editors a chance to cleanup after themselves. self.destroy_views(self.views) self.destroy_editors(self.editors) # Cleanup the window layout (event handlers, etc.) self.layout.close() # Cleanup the toolkit-specific control. self.destroy() # Cleanup our reference to the control so that we can (at least # in theory!) be opened again. self.control = None # Trait notification. self.closed = self logger.debug("window %s closed", self) else: logger.debug("window %s close was vetoed", self) else: logger.debug("window %s is not open", self) # FIXME v3: This is not actually part of the Pyface 'Window' API (but # maybe it should be). We return this to indicate whether the window # actually closed. return self.control is None
def exit(self): """ Exits the workbench. This closes all open workbench windows. This method is not called when the user clicks the close icon. Nor when they do an Alt+F4 in Windows. It is only called when the application menu File->Exit item is selected. Returns True if the exit succeeded, False if it was vetoed. """ logger.debug("**** exiting the workbench ****") # Event notification. self.exiting = event = Vetoable() if not event.veto: # This flag is checked in '_on_window_closing' to see what kind of # exit is being performed. self._explicit_exit = True if len(self.windows) > 0: exited = self._close_all_windows() # The degenerate case where no workbench windows have ever been # created! else: # Trait notification. self.exited = self exited = True # Whether the exit succeeded or not, we are no longer in the # process of exiting! self._explicit_exit = False else: exited = False if not exited: logger.debug("**** exit of the workbench vetoed ****") return exited
def exit(self, force=False): """Exits the application, closing all open task windows. Each window is sent a veto-able closing event. If any window vetoes the close request, no window will be closed. Otherwise, all windows will be closed and the GUI event loop will terminate. This method is not called when the user clicks the close button on a window or otherwise closes a window through his or her window manager. It is only called via the File->Exit menu item. It can also, of course, be called programatically. Parameters ---------- force : bool, optional (default False) If set, windows will receive no closing events and will be destroyed unconditionally. This can be useful for reliably tearing down regression tests, but should be used with caution. Returns ------- bool A boolean indicating whether the application exited. """ self._explicit_exit = True try: if not force: for window in reversed(self.windows): window.closing = event = Vetoable() if event.veto: return False self._prepare_exit() for window in reversed(self.windows): window.destroy() window.closed = True finally: self._explicit_exit = False return True
def open(self): """ Opens the window. Overridden to make the 'opening' event vetoable and to activate a task if one has not already been activated. Returns whether the window was opened. """ self.opening = event = Vetoable() if not event.veto: # Create the control, if necessary. if self.control is None: self._create() # Activate a task, if necessary. if self._active_state is None and self._states: self.activate_task(self._states[0].task) self.show(True) self.opened = self return self.control is not None
def open(self): """ Opens the window. This fires the :py:attr:`closing` vetoable event, giving listeners the opportunity to veto the opening of the window. If the window is opened, the :py:attr:`opened` event will be fired with the IWindow instance as the event value. Returns ------- opened : bool Whether or not the window was opened. """ self.opening = event = Vetoable() if not event.veto: # Create the control, if necessary. if self.control is None: self._create() self.show(True) self.opened = self return self.control is not None and not event.veto