def show_gui(): pycam.Utils.set_application_key("pycam-gtk") deps_gtk = GuiCommon.requirements_details_gtk() report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t") if GuiCommon.check_dependencies(deps_gtk): from pycam.Gui.Project import ProjectGui gui_class = ProjectGui else: full_report = [] full_report.append("PyCAM dependency problem") full_report.append("Error: Failed to load the GTK interface.") full_report.append("Details:") full_report.append(report_gtk) full_report.append("") full_report.append("Detailed list of requirements: %s" % GuiCommon.REQUIREMENTS_LINK) log.critical(os.linesep.join(full_report)) return EXIT_CODES["requirements"] event_manager = get_event_handler() event_manager.set("history", DataHistory()) with merge_history_and_block_events(event_manager): gui = gui_class(event_manager) # initialize plugins plugin_manager = pycam.Plugins.PluginManager(core=event_manager) plugin_manager.import_plugins() # some more initialization gui.reset_preferences() gui.load_preferences() gui.load_startup_workspace() event_manager.emit_event("notify-initialization-finished") # open the GUI get_mainloop(use_gtk=True).run() # optionally save workspace (based on configuration or dialog response) if event_manager.get("save_workspace_on_exit") == QuestionStatus.ASK.value: response = gui.get_question_response("Save Workspace?", True, allow_memorize=True) if response.should_memorize: event_manager.set("save_workspace_on_exit", (QuestionStatus.YES if response.is_yes else QuestionStatus.NO).value) should_store = response.is_yes elif event_manager.get( "save_workspace_on_exit") == QuestionStatus.YES.value: should_store = True else: should_store = False if should_store: gui.save_startup_workspace() gui.save_preferences() # no error -> return no error code return None
def show_gui(inputfile=None, task_settings_file=None): deps_gtk = GuiCommon.requirements_details_gtk() report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t") if GuiCommon.check_dependencies(deps_gtk): from pycam.Gui.Project import ProjectGui gui_class = ProjectGui else: full_report = [] full_report.append("PyCAM dependency problem") full_report.append("Error: Failed to load the GTK interface.") full_report.append("Details:") full_report.append(report_gtk) full_report.append("") full_report.append("Detailed list of requirements: %s" % \ GuiCommon.REQUIREMENTS_LINK) log.critical(os.linesep.join(full_report)) return EXIT_CODES["requirements"] gui = gui_class() # load the given model or the default if not inputfile: default_model = get_default_model() if isinstance(default_model, (basestring, pycam.Utils.URIHandler)): gui.load_model_file(filename=default_model, store_filename=False) else: gui.load_model(default_model) else: gui.load_model_file(filename=inputfile) # load task settings file if not task_settings_file is None: gui.open_task_settings_file(task_settings_file) # tell the GUI to empty the "undo" queue gui.finish_startup() # open the GUI gui.mainloop() # no error -> return no error code return None
def show_gui(inputfile=None, task_settings_file=None): deps_gtk = GuiCommon.requirements_details_gtk() report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t") if GuiCommon.check_dependencies(deps_gtk): from pycam.Gui.Project import ProjectGui gui_class = ProjectGui else: full_report = [] full_report.append("PyCAM dependency problem") full_report.append("Error: Failed to load the GTK interface.") full_report.append("Details:") full_report.append(report_gtk) full_report.append("") full_report.append("Detailed list of requirements: %s" % \ GuiCommon.REQUIREMENTS_LINK) log.critical(os.linesep.join(full_report)) return EXIT_CODES["requirements"] gui = gui_class() # load the given model or the default if not inputfile: default_model = get_default_model() if isinstance(default_model, (basestring, pycam.Utils.URIHandler)): gui.load_model_file(filename=default_model, store_filename=False) else: gui.load_model(default_model) else: gui.load_model_file(filename=inputfile) # load task settings file if not task_settings_file is None: gui.open_task_settings_file(task_settings_file) # tell the GUI to empty the "undo" queue gui.finish_startup() # open the GUI gui.mainloop() # no error -> return no error code return None
def show_gui(): deps_gtk = GuiCommon.requirements_details_gtk() report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t") if GuiCommon.check_dependencies(deps_gtk): from pycam.Gui.Project import ProjectGui gui_class = ProjectGui else: full_report = [] full_report.append("PyCAM dependency problem") full_report.append("Error: Failed to load the GTK interface.") full_report.append("Details:") full_report.append(report_gtk) full_report.append("") full_report.append("Detailed list of requirements: %s" % GuiCommon.REQUIREMENTS_LINK) log.critical(os.linesep.join(full_report)) return EXIT_CODES["requirements"] event_manager = get_event_handler() gui = gui_class(event_manager) # initialize plugins plugin_manager = pycam.Plugins.PluginManager(core=event_manager) plugin_manager.import_plugins() # some more initialization gui.reset_preferences() # TODO: preferences are not loaded until the new format is stable # self.load_preferences() # tell the GUI to empty the "undo" queue gui.clear_undo_states() event_manager.emit_event("notify-initialization-finished") # open the GUI gui.mainloop() # no error -> return no error code return None
def show_gui(workspace_filename=None): pycam.Utils.set_application_key("pycam-gtk") deps_gtk = GuiCommon.requirements_details_gtk() report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t") if GuiCommon.check_dependencies(deps_gtk): from pycam.Gui.Project import ProjectGui gui_class = ProjectGui else: full_report = [] full_report.append("PyCAM dependency problem") full_report.append("Error: Failed to load the GTK interface.") full_report.append("Details:") full_report.append(report_gtk) full_report.append("") full_report.append("Detailed list of requirements: %s" % GuiCommon.REQUIREMENTS_LINK) log.critical(os.linesep.join(full_report)) return EXIT_CODES["requirements"] event_manager = get_event_handler() history = DataHistory() event_manager.set("history", history) with merge_history_and_block_events(event_manager): log.debug("Initializing user interface") gui = gui_class(event_manager) # initialize plugins log.debug("Loading all available plugins") plugin_manager = pycam.Plugins.PluginManager(core=event_manager) plugin_manager.import_plugins() # some more initialization log.debug("Resetting preferences") gui.reset_preferences() log.debug("Loading preferences") gui.load_preferences() has_loaded_custom_workspace = False log.debug("Loading workspace") if workspace_filename is None: gui.load_startup_workspace() else: if gui.load_workspace_from_file(workspace_filename): has_loaded_custom_workspace = True else: gui.load_startup_workspace() log.debug("Finished initialization") log.debug("Configured events: %s", ", ".join(event_manager.get_events_summary_lines())) shutdown_calls = [] def shutdown_handler(): # prevent repeated calls if shutdown_calls: return shutdown_calls.append(True) # optionally save workspace (based on configuration or dialog response) if has_loaded_custom_workspace: # A custom workspace file was given via command line - we always want to ask before # overwriting it. response = gui.get_question_response( "Save Workspace to '{}'?".format(workspace_filename), True) should_store = response.is_yes elif event_manager.get( "save_workspace_on_exit") == QuestionStatus.ASK.value: response = gui.get_question_response("Save Workspace?", True, allow_memorize=True) if response.should_memorize: event_manager.set("save_workspace_on_exit", (QuestionStatus.YES if response.is_yes else QuestionStatus.NO).value) should_store = response.is_yes elif event_manager.get( "save_workspace_on_exit") == QuestionStatus.YES.value: should_store = True else: should_store = False if should_store: gui.save_startup_workspace() gui.save_preferences() with merge_history_and_block_events(event_manager, emit_events_after=False): plugin_manager.disable_all_plugins() # close the GUI gui.stop() history.cleanup() # Register our shutdown handler: it should be run _before_ the GTK main loop stops. # Otherwise some references and signals are gone when the teardown actions are exeucted. event_manager.register_event("mainloop-stop", shutdown_handler) # open the GUI - wait until the window is closed gui.run_forever() event_manager.unregister_event("mainloop-stop", shutdown_handler) # show final statistics log.debug("Configured events: %s", ", ".join(event_manager.get_events_summary_lines())) for event, stats in sorted(event_manager.get_events_summary().items()): if len(stats["handlers"]) > 0: log.info("Remaining listeners for event '%s': %s", event, ", ".join(str(func) for func in stats["handlers"])) # no error -> return no error code return None