Exemplo n.º 1
0
    def _refresh(self):
        for k in range(self.count()):

            # this construct depends on the details of the window build
            # and layout sequence as implemented in module sp_widget.
            window = self.widget(k).layout().itemAt(0).widget().widget(0)

            # it's not enough to send a generic signal to tell the model
            # (as in MVC) that it changed. We have to resort to completely
            # removing all rows from the tree, and then adding them back.
            # This somehow may have to do with the Qt nonblock mechanism,
            # because when in blocking mode, a direct, generic signal
            # works as expected.
            window.model.beginRemoveRows(window.treeView.rootIndex(), 0,
                                         window.model.rowCount() - 1)
            component_list = []
            row_range = range(window.model.rowCount())
            for k in row_range:
                item = window.model.item(0).getDataItem()
                component_list.append(item)
                window.model.removeRow(0)
            window.model.endRemoveRows()
            for k in row_range:
                component = component_list[k]
                name = models_registry.getComponentName(component)
                window.model.addToModel(name, component)
Exemplo n.º 2
0
    def _refresh(self):
        for k in range(self.count()):

            # this construct depends on the details of the window build
            # and layout sequence as implemented in module sp_widget.
            window = self.widget(k).layout().itemAt(0).widget().widget(0)

            # it's not enough to send a generic signal to tell the model
            # (as in MVC) that it changed. We have to resort to completely
            # removing all rows from the tree, and then adding them back.
            # This somehow may have to do with the Qt nonblock mechanism,
            # because when in blocking mode, a direct, generic signal
            # works as expected.
            window.model.beginRemoveRows(window.treeView.rootIndex(),
                                         0, window.model.rowCount()-1)
            component_list = []
            row_range = range(window.model.rowCount())
            for k in row_range:
                item = window.model.item(0).getDataItem()
                component_list.append(item)
                window.model.removeRow(0)
            window.model.endRemoveRows()
            for k in row_range:
                component = component_list[k]
                name = models_registry.getComponentName(component)
                window.model.addToModel(name, component)
Exemplo n.º 3
0
def adjust(instance, x, y):
    if x is None or y is None:
        return instance

    name = models_registry.getComponentName(instance)
    try:
        adjuster = _adjusters[name]
        return adjuster.adjust(instance, x, y)
    except KeyError:
        return instance
Exemplo n.º 4
0
    def _addComponentToActive(self, component):
        name = models_registry.getComponentName(component)

        # this should be done by instantiating from a class, but that is
        # not possible yet (the astropy dev version can't be compiled due
        # to a Cython syntax error...). So we resort to brute force and
        # copy the instances instead.
        component = models_registry.registry[name].copy()
        if component:
            sp_adjust.adjust(component, self.x, self.y)
            self.models_gui.updateModel(component)
Exemplo n.º 5
0
    def _addComponentToActive(self, component):
        name = models_registry.getComponentName(component)

        # this should be done by instantiating from a class, but that is
        # not possible yet (the astropy dev version can't be compiled due
        # to a Cython syntax error...). So we resort to brute force and
        # copy the instances instead.
        component = models_registry.registry[name].copy()
        if component:
            sp_adjust.adjust(component, self.x, self.y)
            self.models_gui.updateModel(component)
Exemplo n.º 6
0
    def adjust(self, instance, x, y):

        y_range = np.max(y) - np.min(y)
        x_range = x[len(x) - 1] - x[0]
        position = x_range / 2.0 + x[0]
        width = x_range / 50.

        name = models_registry.getComponentName(instance)

        _setattr(instance, name, 'amplitude', y_range * self._factor)
        _setattr(instance, name, 'position', position)
        _setattr(instance, name, 'width', width)

        return instance
Exemplo n.º 7
0
 def addOneElement(self, element):
     name = models_registry.getComponentName(element)
     self.addToModel(name, element)
Exemplo n.º 8
0
 def addOneElement(self, element):
     name = models_registry.getComponentName(element)
     self.addToModel(name, element)