예제 #1
0
    def create_debugger(self, debugger_id):
        """ Create a debugger panel and add a reference to it in the plugin.

        """
        declaration = self.plugin.debuggers.get(unicode(debugger_id))
        if not declaration:
            logging.getLogger(__name__)
            logging.warn('{} is not known debugger id'.format(debugger_id))
            return

        # Find first unused name.
        dock_numbers = sorted([
            int(pane.name[5]) for pane in self.dock_area.dock_items()
            if pane.name.startswith('item')
        ])

        if dock_numbers and dock_numbers[-1] > len(dock_numbers):
            first_free = min(
                set(xrange(1,
                           len(dock_numbers) + 1)) - set(dock_numbers))
            name = 'item_{}'.format(first_free)
        else:
            name = 'item_{}'.format(len(dock_numbers) + 1)

        debugger = declaration.factory(declaration, self.plugin)
        self.plugin.debugger_instances.append(debugger)
        declaration.view(self.dock_area, debugger=debugger, name=name)
        self.dock_area.update_layout(
            InsertItem(item=name, target='main_log', position='top'))
예제 #2
0
    def _insert_new_edition_panel(self, measure):
        """Handle inserting a new MeasureEditorDockItem in the content.

        """
        template = 'meas_%d'
        items = self.dock_area.dock_items()
        test = re.compile('meas\_([0-9]+)$')
        measure_items = [i for i in items if test.match(i.name)]

        if not measure_items:
            name = template % 0
            op = InsertItem(item=name, target='meas_exec')
        else:
            indexes = [int(test.match(i.name).group(1)) for i in measure_items]
            indexes.sort()

            if len(indexes) <= max(indexes):
                ind = [i for i, x in enumerate(indexes) if i != x][0]
            else:
                ind = len(measure_items)

            name = template % ind
            op = InsertTab(item=name, target=template % indexes[0])

        MeasureEditorDockItem(self.dock_area,
                              workspace=self,
                              measure=measure,
                              name=name)

        deferred_call(self.dock_area.update_layout, op)
예제 #3
0
    def _insert_new_edition_panels(self,
                                   measurements,
                                   update=True,
                                   panels=None):
        """Handle inserting a new MeasurementEditorDockItem in the content.

        """
        if panels is None:
            template = 'meas_%d'
            items = self.dock_area.dock_items()
            test = re.compile('meas\_([0-9]+)$')
            measurement_items = [i for i in items if test.match(i.name)]

            ops = []
            for measurement in measurements:
                if not measurement_items:
                    name = template % 0
                    ops.append(InsertItem(item=name, target='meas_exec'))
                else:
                    indexes = [
                        int(test.match(i.name).group(1))
                        for i in measurement_items
                    ]
                    indexes.sort()

                    if len(indexes) <= max(indexes):
                        ind = [i for i, x in enumerate(indexes) if i != x][0]
                    else:
                        ind = len(measurement_items)

                    name = template % ind
                    ops.append(
                        InsertTab(item=name, target=template % indexes[0]))

                measurement_items.append(
                    MeasurementEditorDockItem(self.dock_area,
                                              workspace=self,
                                              measurement=measurement,
                                              name=name))

            if update:
                deferred_call(self.dock_area.update_layout, ops)
        else:
            for m in measurements:
                if m not in panels:
                    msg = ('Cannot insert edition panels for measurement %s, '
                           'no infos were provided. Panels exists for:\n%s')
                    raise RuntimeError(msg % (m.name + ' (id : %s)' % m.id,
                                              ', '.join(m.name
                                                        for m in panels)))
                ed_name, t_name = panels[m]
                MeasurementEditorDockItem(self.dock_area,
                                          workspace=self,
                                          measurement=m,
                                          name=ed_name)
                if t_name:
                    ToolsEditorDockItem(self.dock_area,
                                        measurement=m,
                                        name=t_name)
예제 #4
0
    def _refresh_workspace(self, event=None):
        ui = self.workbench.get_plugin('enaml.workbench.ui')
        items = self.load_plugins(WORKSPACE_POINT,
                                  DockItem,
                                  'name',
                                  plugin=self)

        ops = []
        for item in items.values():
            item.set_parent(ui.workspace.dock_area)
            ops.append(InsertItem(item=item.name))

        deferred_call(ui.workspace.dock_area.update_layout, ops)
        self._workspace_contributions = items
예제 #5
0
 def _refresh_workspace(self, event=None):
     log.debug('Refreshing workspace')
     ui = self.workbench.get_plugin('enaml.workbench.ui')
     point = self.workbench.get_extension_point(WORKSPACE_POINT)
     items_added = []
     for extension in point.extensions:
         if extension.factory is not None:
             extension.factory(ui.workbench, ui.workspace)
         for item in extension.get_children(DockItem):
             item.set_parent(ui.workspace.dock_area)
             op = InsertItem(item=item.name)
             ui.workspace.dock_area.update_layout(op)
             items_added.append(item.name)
     log.debug('Added dock area items: %s', ', '.join(items_added))
예제 #6
0
    def set_layout(self, layout):
        ui = self.workbench.get_plugin('enaml.workbench.ui')
        try:
            ui._window.set_geometry(layout['geometry'])
        except Exception as e:
            log.exception(e)

        try:
            self._set_toolbar_layout(layout['toolbars'])
        except Exception as e:
            log.exception(e)

        available = [i.name for i in ui.workspace.dock_area.dock_items()]
        missing = MissingDockLayoutValidator(available)(layout['dock_layout'])
        ops = []
        for item in missing:
            log.debug('{} missing from saved dock layout'.format(item))
            ops.append(InsertItem(item=item))
        ui.workspace.dock_area.layout = layout['dock_layout']
        deferred_call(ui.workspace.dock_area.update_layout, ops)
    def initialize(self):
        super(TimeDelayEstimationPreview, self).initialize()
        log.info("Setup LivePreview")
        with enaml.imports():
            from .views.time_delay_estimation import TimeDelayEstimationPreviewContent
            from utinteractiveconsole.plugins.calibration.views.live_preview import LivePreview

        self.content = TimeDelayEstimationPreviewContent(
            parent=self.widget_parent, controller=self)
        self.content.initialize()

        # create and show preview
        self.parent.preview = LivePreview(
            name="%s_preview" % self.widget_name,
            title="Time Delay Estimation Preview",
            controller=self,
            state=self.parent.current_state,
            renderer=self.content.renderer)
        # add to layout
        parent = self.workspace.content.find("wizard_dockarea")
        self.parent.preview.set_parent(self.widget_parent)
        op = InsertItem(item=self.parent.preview.name,
                        target=self.widget_name,
                        position='right')
        parent.update_layout(op)

        self.camera = self.content.camera
        self.renderer = self.content.renderer
        self.bgtexture = self.content.scene.find("preview_bgtexture")
        self.origin_marker = self.content.scene.find("origin_marker")
        self.target_marker = self.content.scene.find("target_marker")
        self.tooltip_marker = self.content.scene.find("tooltip_marker")

        if self.facade is not None:
            # XXX needs some improvement .. is_running does not directly relate to startDataflow ..
            if self.facade.is_loaded:
                self.connector_setup(dict(value=True))
            else:
                self.facade.observe("is_loaded", self.connector_setup)
                self.facade.startDataflow()
예제 #8
0
def build_single_instr_panel(panel_class, state, main_ui, second_ui, prop_ui,
                main_panel, area):
    """
    """
    profile = state['pref']['profile']
    if state['profile_available']:
        with main_panel.suppress_notifications():
            main_panel.available_profiles.remove(profile)
    model = panel_class(state = state)
    main_panel.panels.append(model)
    main_panel.used_profiles[profile] = model

    dock_numbers = sorted([pane.name[5] for pane in area.dock_items()])
    if dock_numbers and dock_numbers[-1] > len(dock_numbers):
        first_free = min(set(xrange(len(dock_numbers))) - dock_numbers)
        name = 'item_{}'.format(first_free)
    else:
        name = 'item_{}'.format(len(dock_numbers) + 1)

    SingleInstrDock(area, model = model, name = name,
                    main_ui = main_ui, second_ui = second_ui,
                    prop_ui = prop_ui)
    area.update_layout(InsertItem(item = name))
예제 #9
0
    def launch_wizard(self, ev):
        params = ev.parameters
        wizard_instances = self.wizard_instances
        live_previews = self.live_previews
        name = params.get('wizard_name')
        wizard_def = params.get('wizard_def')
        wizard_cfg = params.get('wizard_cfg')

        if name in wizard_instances:
            wizard = wizard_instances[name]
            wizard.show()
            da = ev.workbench.get_plugin(
                'enaml.workbench.ui').workspace.content.find("wizard_dockarea")
            op = InsertItem(item=name, target="new", position="right")
            da.update_layout(op)

            if name in live_previews:
                preview = live_previews[name]
                preview.show()
                op = InsertItem(item=preview.name,
                                target=name,
                                position="right")
                da.update_layout(op)

        else:
            wizard = WizardController(context=self.context,
                                      workbench=ev.workbench)
            if not wizard.initialize(wizard_def):
                log.error("Error launching wizard: %s" % name)
                return

            with enaml.imports():
                from .views.wizard_main import WizardView

            workspace = ev.workbench.get_plugin('enaml.workbench.ui').workspace

            def cleanup(*args):
                log.info("Cleanup for wizard: %s" % name)

                if wizard.preview is not None:
                    wizard.preview.destroy()
                    wizard.preview = None

                if wizard.wizview is not None:
                    wizard.wizview.unobserve("closed", cleanup)
                    wizard.wizview = None

                if wizard.current_state is not None:
                    log.info("Stop currently active processes")
                    wizard.current_state.stop()
                    wizard.current_state = None

                if name in wizard_instances:
                    wizard_instances.pop(name)
                workspace.unobserve("stopped", cleanup)
                log.info("Finished cleanup for wizard: %s" % name)

            if wizard.current_state is not None:
                wizard.current_state.start()

            if wizard.wizview is None:
                wizard.wizview = WizardView(name=name,
                                            title="Calibrate: %s" %
                                            wizard_def.get('name'),
                                            controller=wizard,
                                            state=wizard.current_state)
                wizard.wizview.observe("closed", cleanup)
                workspace.observe("stopped", cleanup)

                # add to layout
                parent = workspace.content.find("wizard_dockarea")
                wizard.wizview.set_parent(parent)
                op = InsertItem(item=wizard.wizview.name, )
                parent.update_layout(op)

            if wizard.preview is None and wizard_cfg.get("livepreview",
                                                         None) is not None:
                preview_controller_name = wizard_cfg.get("livepreview")
                mgr = stevedore.extension.ExtensionManager
                pce = mgr(
                    namespace="vharcalibration.controllers.preview",
                    invoke_on_load=True,
                    invoke_args=(wizard, self.context,
                                 wizard_def.get("config_namespace")),
                )
                if preview_controller_name in pce.names():
                    pc = pce[preview_controller_name].obj.create(
                        workspace, name, parent)
                    wizard.preview_controller = pc
                    pc.initialize()
                else:
                    log.warn("Invalid LivePreview config: %s" %
                             preview_controller_name)

            wizard.show()

            # start the watchdog timer for subprocess control
            if hasattr(wizard.wizview, "control"):
                wizard.wizview.control.subprocess.timer.start()

            wizard_instances[name] = wizard
예제 #10
0
    def _update_area_layout(self, change):
        """ When a document is opened or closed, add or remove it
        from the currently active TabLayout.

        The layout update is deferred so it fires after the items are
        updated by the Looper.

        """
        if change['type'] == 'create':
            return

        #: Get the dock area
        area = self.get_dock_area()

        #: Refresh the dock items
        #area.looper.iterable = self.documents[:]

        #: Determine what change to apply
        removed = set()
        added = set()
        if change['type'] == 'container':
            op = change['operation']
            if op in ['append', 'insert']:
                added = set([change['item']])
            elif op == 'extend':
                added = set(change['items'])
            elif op in ['pop', 'remove']:
                removed = set([change['item']])
        elif change['type'] == 'update':
            old = set(change['oldvalue'])
            new = set(change['value'])

            #: Determine which changed
            removed = old.difference(new)
            added = new.difference(old)
        elif change['type'] == 'load':
            old = set([Document()])
            new = set(self.documents)
            #: Determine which changed
            removed = old.difference(new)
            added = new.difference(old)

        #: Update operations to apply
        ops = []
        removed_targets = []

        #: Remove any old items
        for doc in removed:
            for item in self.get_editor_items():
                if item.doc == doc:
                    removed_targets.append(item.name)
                    ops.append(RemoveItem(item=item.name))

        # Remove ops
        area.update_layout(ops)

        # Add each one at a time
        targets = [
            item.name for item in area.dock_items()
            if (item.name.startswith("editor-item")
                and item.name not in removed_targets)
        ]

        # Sort documents so active is last so it's on top when we restore
        # from a previous state
        for doc in sorted(added, key=lambda d: int(d == self.active_document)):
            item = create_editor_item(area, plugin=self, doc=doc)
            if targets:
                op = InsertTab(item=item.name, target=targets[-1])
            else:
                op = InsertItem(item=item.name)
            targets.append(item.name)
            area.update_layout(op)

        # Now save it
        self.save_dock_area(change)