def quit_app(): """Close all windows and quit the QApplication if napari started it.""" QApplication.closeAllWindows() # if we started the application then the app will be named 'napari'. if (QApplication.applicationName() == 'napari' and not _ipython_has_eventloop()): QApplication.quit() # otherwise, something else created the QApp before us (such as # %gui qt IPython magic). If we quit the app in this case, then # *later* attempts to instantiate a napari viewer won't work until # the event loop is restarted with app.exec_(). So rather than # quit just close all the windows (and clear our app icon). else: QApplication.setWindowIcon(QIcon()) if perf.USE_PERFMON: # Write trace file before exit, if we were writing one. # Is there a better place to make sure this is done on exit? perf.timers.stop_trace_file() if config.monitor: # Stop the monitor service if we were using it from ..components.experimental.monitor import monitor monitor.stop() if config.async_loading: # Shutdown the chunkloader from ..components.experimental.chunk import chunk_loader chunk_loader.shutdown()
def closeEvent(self, event): """Close application. Parameters ---------- event : QEvent Close event. """ write_settings(size=self.size(), pos=self.pos()) if self.model.history: print("\n# Command History\n") print("\n".join(self.model.history)) QApplication.quit()
def closeEvent(self, event): """Close application. Parameters ---------- event : QEvent Close event. """ write_settings(geometry=self.saveGeometry(), state=self.saveState()) if self.model.history: print("\nCommand History") print("===============") print("\n".join(self.model.history)) QApplication.quit()
def handle_exit(): # if the event loop was started in gui_qt() then the app will be # named 'napari'. Since the Qapp was started by us, just close it. if QApplication.applicationName() == 'napari': QApplication.closeAllWindows() QApplication.quit() # otherwise, something else created the QApp before us (such as # %gui qt IPython magic). If we quit the app in this case, then # *later* attemps to instantiate a napari viewer won't work until # the event loop is restarted with app.exec_(). So rather than # quit just close all the windows (and clear our app icon). else: QApplication.setWindowIcon(QIcon()) self.close()
def handle_exit(): # if the event loop was started in gui_qt() then the app will be # named 'napari'. Since the Qapp was started by us, just close it. if QApplication.applicationName() == 'napari': QApplication.closeAllWindows() QApplication.quit() # otherwise, something else created the QApp before us (such as # %gui qt IPython magic). If we quit the app in this case, then # *later* attempts to instantiate a napari viewer won't work until # the event loop is restarted with app.exec_(). So rather than # quit just close all the windows (and clear our app icon). else: QApplication.setWindowIcon(QIcon()) self.close() if perf.USE_PERFMON: # Write trace file before exit, if we were writing one. # Is there a better place to make sure this is done on exit? perf.timers.stop_trace_file()
def main(): """ Main operating script main() is the main function that is calling the other procedures and functions. First, it will call the LaunchWindow() class and display and wait for the proper user inputs. Next, it will open the main UI window. In this window, all of the image processing tasks can be completed if necesssary. Args: None Returns: None """ if not QApplication.instance(): app = QApplication(sys.argv) else: app = QApplication.instance() # Display the config.py file app.setWindowIcon(QtGui.QIcon(config.ICON)) app.setApplicationName(config.TITLE) # Call the launch windows window = LaunchDialog() # Obtain data from launch window user, batch, img_group, location = get_launch_data(window) if user and batch and img_group and location: frame = MainWindow(user, batch, img_group, location) frame.setWindowTitle(config.TITLE) frame.show() app.exec_() else: app.quit()
class GUI_Environment(Environment): _viewers = { Diagram: diagram.Diagram_Editor, Block: diagram.Block_Editor, } def __init__(self, source, show=True): super().__init__(source, show=show) self.modified = False self.modified_widgets = set() self._app = QApplication([]) self._app.setAttribute(Qt.AA_DontShowIconsInMenus, True) self._main_window = Main_Window(self) if show: self._main_window.show() def execute(self): return self._app.exec_() def _add_tab(self, entity): self._main_window.tabs.addTab(entity.widget, entity.name) self._main_window.update_tab_title( self._main_window.tabs.indexOf(entity.widget)) def _remove_tab(self, entity): self._main_window.tabs.removeTab( self._main_window.tabs.indexOf(entity.widget)) def _ok_to_close(self, entity): if entity.widget in self.modified_widgets: mb = QMessageBox() mb.setText("The tab contents may have been modified.") mb.setInformativeText("Do you want to save your changes?") mb.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) mb.setDefaultButton(QMessageBox.Save) ans = mb.exec() if ans == QMessageBox.Cancel: return False elif ans == QMessageBox.Save: saved = self.save() if not saved: return False return True def _ok_to_quit(self): if not hasattr(self, "_main_window"): return True if self.modified: mb = QMessageBox() mb.setText("The project may have been modified.") mb.setInformativeText("Do you want to save your changes?") mb.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) mb.setDefaultButton(QMessageBox.Save) ans = mb.exec() if ans == QMessageBox.Cancel: return False elif ans == QMessageBox.Save: saved = self.save() if not saved: return False return True def new(self): if not self._ok_to_quit(): return self.clear_modified() ret = self.close_all() if not ret: return super().new() def open(self, file_name=None): if not self._ok_to_quit(): return if not file_name: file_name, selected_filter = QFileDialog.getOpenFileName( self._main_window, caption="Open File", filter="Hildegard Project Files (*.hp)") if file_name: self.clear_modified() ret = self.close_all() if not ret: return self._file_name = file_name self._main_window.update_title() super().open(file_name) def view(self, entity, show=True): added = super().view(entity, show=show) if not added: return False self._add_tab(entity) if show: entity.widget.show() return True def close(self, entity, quit=False): if not self.viewing(entity): return True if not self._ok_to_close(entity): return False self._remove_tab(entity) entity.widget.close() ret = super().close(entity) if not self.viewing() and quit: self._app.quit() return ret def close_all(self, quit=False): ret = super().close_all() if not self.viewing() and quit: self._app.quit() return ret def _set_new_file_name(self): file_name, selected_filter = QFileDialog.getSaveFileName( self._main_window, caption="Save Environment", filter="Hildegard Project Files (*.hp)") if file_name: self._file_name = file_name self._main_window.update_title() def save_as(self): self._set_new_file_name() if self._file_name: self.save() def save(self): if not self._file_name: self._set_new_file_name() if self._file_name: wumps.save(self._entities, file_name=self._file_name) self._main_window.save_action.setEnabled(False) self.clear_modified() return True if self._file_name else False def set_modified(self, subitem=None): if subitem is not None: self.modified_widgets.add(subitem) try: i = self._main_window.tabs.indexOf(subitem) self._main_window.update_tab_title(i) except: pass self.modified = True self._main_window.update_title() self._main_window.save_action.setEnabled(True) def clear_modified(self): self.modified = False self._main_window.update_title() widgets_to_update = self.modified_widgets self.modified_widgets = set() for widget in widgets_to_update: try: i = self._main_window.tabs.indexOf(widget) self._main_window.update_tab_title(i) except: pass
def sigint_handler(*args): """Handler for the SIGINT signal.""" warnings.warn('KeyboardInterrupt caught; specviz will terminate', AstropyUserWarning) QApplication.quit()
def shutdown(): QApplication.quit()
def exit(self): QApplication.quit() sys.exit(0)
def shutdown(self): self.closeGUI() self.closeAPE() self.closeLauncher() QApplication.quit()
def shutdown(self): self._app_helper.aboutToQuit.emit() QApplication.quit()
def closeEvent(self, event): QApplication.quit( ) # some errors can be recovered from, maybe I shouldn't autoclose the program
def terminate(self): QApplication.quit()