def run(self): """ Run the UI workbench application. This method will load the core and ui plugins and start the main application event loop. This is a blocking call which will return when the application event loop exits. """ InkcutWorkbench._instance = self with enaml.imports(): from enaml.workbench.core.core_manifest import CoreManifest from enaml.workbench.ui.ui_manifest import UIManifest from inkcut.core.manifest import InkcutManifest #from inkcut.settings.manifest import SettingsManifest self.register(CoreManifest()) self.register(UIManifest()) self.register(InkcutManifest()) #self.register(SettingsManifest()) #: Init the ui ui = self.get_plugin('enaml.workbench.ui') ui.show_window() # Make sure ^C keeps working signal.signal(signal.SIGINT, signal.SIG_DFL) #: Start the core plugin plugin = self.get_plugin('inkcut.core') ui.start_application()
def initialize_default(extra_manifests, workspace='psi.experiment.workspace'): with enaml.imports(): from enaml.workbench.core.core_manifest import CoreManifest from enaml.workbench.ui.ui_manifest import UIManifest from psi.context.manifest import ContextManifest from psi.data.manifest import DataManifest from psi.experiment.manifest import ExperimentManifest with warnings.catch_warnings(): warnings.simplefilter('ignore') workbench = Workbench() workbench.register(CoreManifest()) workbench.register(UIManifest()) workbench.register(ContextManifest()) workbench.register(DataManifest()) workbench.register(ExperimentManifest()) for manifest in extra_manifests: workbench.register(manifest()) core = workbench.get_plugin('enaml.workbench.core') ui = workbench.get_plugin('enaml.workbench.ui') ui.show_window() core.invoke_command('enaml.workbench.ui.select_workspace', {'workspace': workspace}) experiment = workbench.get_plugin('psi.experiment') return workbench
def test_open_browser_command(exopy_qtbot, prof_plugin): """Test opening the browsing window. """ with enaml.imports(): from enaml.workbench.ui.ui_manifest import UIManifest prof_plugin.workbench.register(UIManifest()) core = prof_plugin.workbench.get_plugin('enaml.workbench.core') with handle_dialog(exopy_qtbot): core.invoke_command('exopy.instruments.open_browser')
def setup(self): self.workbench = Workbench() self.workbench.register(CoreManifest()) self.workbench.register(UIManifest()) self.workbench.register(StateManifest()) self.workbench.register(PreferencesManifest()) self.workbench.register(LogManifest()) self.workbench.register(MeasureManifest()) # Needed otherwise the monitor manifest is not registered. self.workbench.get_plugin(u'hqc_meas.measure')
def processor(windows, measure_workbench, measure): """Fixture starting the measure plugin and returning the processor. Use app because we need run the event loop """ # measure ensures that contributions are there measure_workbench.register(UIManifest()) measure_workbench.register(TasksManagerManifest()) plugin = measure_workbench.get_plugin('ecpy.measure') plugin.selected_engine = 'dummy' return plugin.processor
def content_workbench(measurement_workbench, measurement, exopy_qtbot): """Create a measurement workspace. """ measurement_workbench.register(UIManifest()) measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) measurement_plugin = measurement_workbench.get_plugin('exopy.measurement') measurement_plugin.selected_engine = 'dummy' measurement_plugin.default_monitors = ['dummy'] return measurement_workbench
def content_workbench(measure_workbench, measure, windows): """Create a measure workspace. """ measure_workbench.register(UIManifest()) measure_workbench.register(LogManifest()) measure_workbench.register(TasksManagerManifest()) measure_plugin = measure_workbench.get_plugin('ecpy.measure') measure_plugin.selected_engine = 'dummy' measure_plugin.default_monitors = ['dummy'] return measure_workbench
def setup(self): self.workbench = Workbench() self.workbench.register(CoreManifest()) self.workbench.register(UIManifest()) self.workbench.register(HqcAppManifest()) self.workbench.register(StateManifest()) self.workbench.register(PreferencesManifest()) self.workbench.register(LogManifest()) self.workbench.register(TaskManagerManifest()) self.workbench.register(InstrManagerManifest()) self.workbench.register(MeasureManifest()) self.workbench.register(TestSuiteManifest())
def workspace(measure_workbench, measure, windows): """Create a measure workspace. """ measure_workbench.register(UIManifest()) measure_workbench.register(LogManifest()) measure_workbench.register(TasksManagerManifest()) measure_plugin = measure_workbench.get_plugin('ecpy.measure') measure_plugin.selected_engine = 'dummy' measure_plugin.default_monitors = ['dummy'] core = measure_workbench.get_plugin('enaml.workbench.core') cmd = 'enaml.workbench.ui.select_workspace' core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'}) return measure_plugin.workspace
def workbench_and_tools(exopy_qtbot): """Create a workbench to test closing of the application window. """ workbench = Workbench() workbench.register(CoreManifest()) workbench.register(UIManifest()) workbench.register(AppManifest()) workbench.register(ErrorsManifest()) closing = ClosingContributor1() workbench.register(closing) closed = ClosedContributor() workbench.register(closed) return workbench, closing, closed
def register_core_plugins(self, io_manifest, controller_manifests): # Note, the get_plugin calls appear to be necessary to properly # initialize parts of the application before new plugins are loaded. # This is likely some sort of bug or poor design on my part. with enaml.imports(): from enaml.workbench.core.core_manifest import CoreManifest from enaml.workbench.ui.ui_manifest import UIManifest from psi.experiment.manifest import ExperimentManifest self.register(ExperimentManifest()) self.register(CoreManifest()) self.register(UIManifest()) self.get_plugin('enaml.workbench.ui') self.get_plugin('enaml.workbench.core') manifest_class = load_manifest_from_file(io_manifest, 'IOManifest') self.register(manifest_class()) manifests = [] for manifest in controller_manifests: manifest_class = load_manifest(manifest) manifest = manifest_class() manifests.append(manifest) self.register(manifest) from psi.context.manifest import ContextManifest from psi.data.manifest import DataManifest from psi.token.manifest import TokenManifest from psi.controller.calibration.manifest import CalibrationManifest self.register(ContextManifest()) self.register(DataManifest()) self.register(TokenManifest()) self.register(CalibrationManifest()) # Required to bootstrap plugin loading self.get_plugin('psi.controller') self.get_plugin('psi.controller.calibration') context = self.get_plugin('psi.context') # Now, bind context to any manifests that want it (TODO, I should # have a core PSIManifest that everything inherits from so this # check isn't necessary). for manifest in manifests: if hasattr(manifest, 'C'): manifest.C = context.lookup
def workspace(exopy_qtbot, measurement_workbench, measurement): """Create a measurement workspace. """ measurement_workbench.register(UIManifest()) measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) measurement_plugin = measurement_workbench.get_plugin('exopy.measurement') measurement_plugin.selected_engine = 'dummy' measurement_plugin.default_monitors = ['dummy'] core = measurement_workbench.get_plugin('enaml.workbench.core') cmd = 'enaml.workbench.ui.select_workspace' core.invoke_command(cmd, {'workspace': 'exopy.measurement.workspace'}) yield measurement_plugin.workspace cmd = 'enaml.workbench.ui.close_workspace' core.invoke_command(cmd, {'workspace': 'exopy.measurement.workspace'})
def setup(self): self.workbench = Workbench() self.workbench.register(CoreManifest()) self.workbench.register(UIManifest()) self.workbench.register(HqcAppManifest()) self.workbench.register(StateManifest()) self.workbench.register(PreferencesManifest()) self.workbench.register(LogManifest()) self.workbench.register(DependenciesManifest()) self.workbench.register(TaskManagerManifest()) self.workbench.register(InstrManagerManifest()) self.workbench.register(MeasureManifest()) self.workbench.register(TestSuiteManifest()) # Adding by hand the false instr task. plugin = self.workbench.get_plugin('hqc_meas.task_manager') plugin._py_tasks['False instr'] = FalseInstrTask
def pulses_workspace(pulses_workbench, windows): """Create a measure workspace. """ pulses_workbench.register(UIManifest()) pulses_workbench.register(LogManifest()) pulses_plugin = pulses_workbench.get_plugin('ecpy.pulses') core = pulses_workbench.get_plugin('enaml.workbench.core') cmd = 'enaml.workbench.ui.select_workspace' core.invoke_command(cmd, {'workspace': 'ecpy.pulses.workspace'}) yield pulses_plugin.workspace cmd = 'enaml.workbench.ui.close_workspace' core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'}) for m_id in ('ecpy.app.logging'): try: pulses_workbench.unregister(m_id) except ValueError: pass
def register_core_plugins(self, io_manifest, controller_manifests): # Note, the get_plugin calls appear to be necessary to properly # initialize parts of the application before new plugins are loaded. # This is likely some sort of bug or poor design on my part. self.register(ExperimentManifest()) self.register(ContextManifest()) self.register(DataManifest()) self.register(TokenManifest()) self.register(CalibrationManifest()) self.register(CoreManifest()) self.register(UIManifest()) self.get_plugin('enaml.workbench.ui') self.get_plugin('enaml.workbench.core') if io_manifest is not None: self.io_manifest_class = load_manifest_from_file( io_manifest, 'IOManifest') io_manifest = self.io_manifest_class() self.register(io_manifest) manifests = [io_manifest] else: manifests = [] for manifest in controller_manifests: log.info('Registering %r', manifest) manifests.append(manifest) self.register(manifest) # Required to bootstrap plugin loading self.controller_plugin = self.get_plugin('psi.controller') self.get_plugin('psi.controller.calibration') self.context_plugin = self.get_plugin('psi.context') for manifest in self._manifests.values(): if hasattr(manifest, 'C'): # Now, bind information to the manifests manifest.C = self.context_plugin.lookup manifest.context = self.context_plugin manifest.controller = self.controller_plugin
def test_install_excepthook(err_workbench, windows): """Test the installation and use of the sys.excepthook. """ import sys old_hook = sys.excepthook err_workbench.register(UIManifest()) err_workbench.register(AppManifest()) core = err_workbench.get_plugin('enaml.workbench.core') core.invoke_command('ecpy.app.errors.install_excepthook') new_hook = sys.excepthook sys.excepthook = old_hook assert old_hook is not new_hook try: raise Exception() except Exception: with handle_dialog(): new_hook(*sys.exc_info())
def run(self): """ Run the UI workbench application. This method will load the core and ui plugins and start the main application event loop. This is a blocking call which will return when the application event loop exits. """ import enaml with enaml.imports(): from enaml.workbench.core.core_manifest import CoreManifest from enaml.workbench.ui.ui_manifest import UIManifest self.register(CoreManifest()) self.register(UIManifest()) ui = self.get_plugin(UI_PLUGIN) ui.show_window() ui.start_application() # TODO stop all plugins on app exit? self.unregister(UI_PLUGIN)
def workspace(measure_workbench, measure, windows): """Create a measure workspace. """ measure_workbench.register(UIManifest()) measure_workbench.register(LogManifest()) measure_workbench.register(TasksManagerManifest()) measure_plugin = measure_workbench.get_plugin('ecpy.measure') measure_plugin.selected_engine = 'dummy' measure_plugin.default_monitors = ['dummy'] core = measure_workbench.get_plugin('enaml.workbench.core') cmd = 'enaml.workbench.ui.select_workspace' core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'}) yield measure_plugin.workspace cmd = 'enaml.workbench.ui.close_workspace' core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'}) for m_id in ('ecpy.tasks', 'ecpy.app.logging'): try: measure_workbench.unregister(m_id) except ValueError: pass
def run(self): """ Run the UI workbench application. This method will load the core and ui plugins and start the main application event loop. This is a blocking call which will return when the application event loop exits. """ DeclaracadWorkbench._instance = self with enaml.imports(): from enaml.workbench.core.core_manifest import CoreManifest from enaml.workbench.ui.ui_manifest import UIManifest self.register(CoreManifest()) self.register(UIManifest()) #: Init the ui ui = self.get_plugin('enaml.workbench.ui') ui.show_window() #: Start the core plugin plugin = self.get_plugin('declaracad.core') ui.start_application()
def main(cmd_line_args=None): """Main entry point of the Exopy application. """ # Build parser from ArgParser and parse arguemnts parser = ArgParser() parser.add_choice('workspaces', 'exopy.measurement.workspace', 'measurement') parser.add_argument("-s", "--nocapture", help="Don't capture stdout/stderr", action='store_true') parser.add_argument("-w", "--workspace", help='Select start-up workspace', default='measurement', choices='workspaces') parser.add_argument("-r", "--reset-app-folder", help='Reset the application startup folder.', action='store_true') modifiers = [] for i, ep in enumerate(iter_entry_points('exopy_cmdline_args')): try: modifier, priority = ep.load(require=False) modifiers.append((ep, modifier, priority, i)) except Exception as e: text = 'Error loading extension %s' % ep.name content = ('The following error occurred when trying to load the ' 'entry point {} :\n {}'.format(ep.name, e)) details = format_exc() display_startup_error_dialog(text, content, details) modifiers.sort(key=itemgetter(1, 2)) try: for m in modifiers: m[1](parser) except Exception as e: text = 'Error modifying cmd line arguments' content = ('The following error occurred when the entry point {} ' 'tried to add cmd line options :\n {}'.format(ep.name, e)) details = format_exc() display_startup_error_dialog(text, content, details) try: args = parser.parse_args(cmd_line_args) except BaseException as e: if e.args == (0, ): sys.exit(0) text = 'Failed to parse cmd line arguments' content = ('The following error occurred when trying to parse the ' 'command line arguments :\n {}'.format(e)) details = format_exc() display_startup_error_dialog(text, content, details) # Patch Thread to use sys.excepthook setup_thread_excepthook() workbench = Workbench() workbench.register(CoreManifest()) workbench.register(UIManifest()) workbench.register(AppManifest()) workbench.register(StateManifest()) workbench.register(ErrorsManifest()) workbench.register(PreferencesManifest()) workbench.register(IconManagerManifest()) workbench.register(LogManifest()) workbench.register(PackagesManifest()) workbench.register(DependenciesManifest()) workbench.register(InstrumentManagerManifest()) workbench.register(TasksManagerManifest()) workbench.register(MeasureManifest()) workbench.register(TextMonitorManifest()) ui = workbench.get_plugin(u'enaml.workbench.ui') # Create the application try: app = workbench.get_plugin('exopy.app') app.run_app_startup(args) except Exception as e: text = 'Error starting plugins' content = ('The following error occurred when executing plugins ' 'application start ups :\n {}'.format(e)) details = format_exc() display_startup_error_dialog(text, content, details) core = workbench.get_plugin('enaml.workbench.core') # Install global except hook. if not args.nocapture: core.invoke_command('exopy.app.errors.install_excepthook', {}) # Select workspace core.invoke_command('enaml.workbench.ui.select_workspace', {'workspace': args.workspace}, workbench) ui = workbench.get_plugin(u'enaml.workbench.ui') ui.show_window() ui.window.maximize() ui.start_application() core.invoke_command('enaml.workbench.ui.close_workspace', {}, workbench) # Unregister all contributed packages workbench.unregister('exopy.app.packages') workbench.unregister('exopy.measurement.monitors.text_monitor') workbench.unregister('exopy.measurement') workbench.unregister('exopy.tasks') workbench.unregister('exopy.instruments') workbench.unregister('exopy.app.icons') workbench.unregister('exopy.app.preferences') workbench.unregister('exopy.app.states') workbench.unregister('exopy.app.dependencies') workbench.unregister('exopy.app.errors') workbench.unregister('exopy.app.logging') workbench.unregister('exopy.app') workbench.unregister(u'enaml.workbench.ui') workbench.unregister(u'enaml.workbench.core')
if __name__ == '__main__': with enaml.imports(): from enaml.workbench.core.core_manifest import CoreManifest from enaml.workbench.ui.ui_manifest import UIManifest from psi.setting.manifest import SettingManifest from psi.data.manifest import DataManifest from psi.controller.manifest import ControllerManifest from psi.experiment.manifest import ExperimentManifest with warnings.catch_warnings(): warnings.simplefilter('ignore') workbench = Workbench() workbench.register(CoreManifest()) workbench.register(UIManifest()) workbench.register(SettingManifest()) workbench.register(DataManifest()) workbench.register(ControllerManifest()) workbench.register(ExperimentManifest()) core = workbench.get_plugin('enaml.workbench.core') ui = workbench.get_plugin('enaml.workbench.ui') parameters = core.invoke_command('psi.setting.get_parameters') parameters[0].rove = True name = parameters[0].name setting = workbench.get_plugin('psi.setting') setting.selectors['go'].add_setting({name: 12.0})
def main(cmd_line_args=None): """Main entry point of the Oculy application.""" # Build parser from ArgParser and parse arguments parser = ArgParser() parser.add_choice("workspaces", "oculy.simple_viewer", "simple") parser.add_argument( "-d", "--debug", help= "Don't capture stdout/stderr, and do not catch top level exceptions", action="store_true", ) parser.add_argument( "-w", "--workspace", help="Select start-up workspace", default="simple", choices="workspaces", ) parser.add_argument( "-r", "--reset-app-folder", help="Reset the application startup folder.", action="store_true", ) extend_parser( parser, "oculy_cmdline_args", lambda title, content, details, exception: display_startup_error_dialog(title, content, details), ) try: args = parser.parse_args(cmd_line_args) except BaseException as e: if self.debug: raise if e.args == (0, ): sys.exit(0) text = "Failed to parse cmd line arguments" content = ("The following error occurred when trying to parse the " "command line arguments :\n {}".format(e)) details = format_exc() display_startup_error_dialog(text, content, details) # Patch Thread to use sys.excepthook if not args.debug: setup_thread_excepthook() workbench = Workbench() workbench.register(CoreManifest()) workbench.register(UIManifest()) workbench.register(LifecycleManifest()) workbench.register(StateManifest()) workbench.register(ErrorsManifest()) workbench.register(PreferencesManifest(application_name="oculy")) workbench.register(IconManagerManifest()) workbench.register(LogManifest(no_capture=args.debug)) workbench.register(PackagesManifest()) workbench.register(OculyManifest()) workbench.register(DataStorageManifest()) workbench.register(IOManifest()) workbench.register(PlottingManifest()) workbench.register(DataTransformerManifest()) workbench.register(SimpleViewerManifest()) ui = workbench.get_plugin(u"enaml.workbench.ui") # Create the application try: app = workbench.get_plugin("glaze.lifecycle") app.run_app_startup(args) except Exception as e: if args.debug: raise text = "Error starting plugins" content = ("The following error occurred when executing plugins " "application start ups :\n {}".format(e)) details = format_exc() display_startup_error_dialog(text, content, details) core = workbench.get_plugin("enaml.workbench.core") # Install global except hook. if not args.debug: core.invoke_command("glaze.errors.install_excepthook", {}) # Select workspace core.invoke_command("enaml.workbench.ui.select_workspace", {"workspace": args.workspace}, workbench) ui = workbench.get_plugin(u"enaml.workbench.ui") ui.show_window() ui.window.maximize() ui.start_application() core.invoke_command("enaml.workbench.ui.close_workspace", {}, workbench) # Unregister all contributed packages workbench.unregister("oculy.workspaces.simple_viewer") workbench.unregister("oculy.data") workbench.unregister("oculy.io") workbench.unregister("oculy.plotting") workbench.unregister("oculy.transformers") workbench.unregister("glaze.packages") workbench.unregister("glaze.icons") workbench.unregister("glaze.states") workbench.unregister("glaze.errors") workbench.unregister("glaze.logging") workbench.unregister("oculy") workbench.unregister("glaze.preferences") workbench.unregister("glaze.lifecycle") workbench.unregister("enaml.workbench.ui") workbench.unregister("enaml.workbench.core")