def setup_method(self):
        self.app = get_qapp()
        self.data1 = Data(x=[1, 2, 3], y=[3.5, 4.5, -1.0], z=['a', 'r', 'w'])
        self.data2 = Data(a=[3, 4, 1], b=[1.5, -2.0, 3.5], c=['y', 'e', 'r'])

        # Add a derived component so that we can test how we deal with existing ones
        components = dict((cid.label, cid) for cid in self.data2.components)
        pc = ParsedCommand('{a}', components)
        link = ParsedComponentLink(ComponentID('d'), pc)
        self.data2.add_component_link(link)

        self.data_collection = DataCollection([self.data1, self.data2])
        self.listener1 = ChangeListener(self.data1)
        self.listener2 = ChangeListener(self.data2)
示例#2
0
    def accept(self):

        for data in self._components:

            cids_main = self._components[data]['main']
            cids_derived = self._components[data]['derived']
            cids_other = self._components[data]['other']

            # First deal with renaming of components
            for cid_new in cids_main + cids_derived:
                label = self._state[data][cid_new]['label']
                if label != cid_new.label:
                    cid_new.label = label

            cids_all = data.pixel_component_ids + data.world_component_ids + cids_main + cids_derived + cids_other

            cids_existing = data.components

            for cid_old in cids_existing:
                if not any(cid_old is cid_new for cid_new in cids_all):
                    data.remove_component(cid_old)

            components = dict((cid.uuid, cid) for cid in data.components)

            for cid_new in cids_derived:
                if any(cid_new is cid_old for cid_old in cids_existing):
                    comp = data.get_component(cid_new)
                    if comp.link._parsed._cmd != self._state[data][cid_new][
                            'equation']._cmd:
                        comp.link._parsed._cmd = self._state[data][cid_new][
                            'equation']._cmd
                        comp.link._parsed._references = components
                        if data.hub:
                            msg = NumericalDataChangedMessage(data)
                            data.hub.broadcast(msg)
                else:
                    pc = ParsedCommand(
                        self._state[data][cid_new]['equation']._cmd,
                        components)
                    link = ParsedComponentLink(cid_new, pc)
                    data.add_component_link(link)

            data.reorder_components(cids_all)

        super(ComponentManagerWidget, self).accept()
示例#3
0
    def accept(self):

        for data in self._components_derived:

            cids_derived = self._components_derived[data]
            cids_other = self._components_other[data]
            cids_all = cids_other + cids_derived
            cids_existing = data.components
            components = dict((cid.uuid, cid) for cid in data.components)

            # First deal with renaming of components
            for cid_new in cids_derived:
                label = self._state[data][cid_new]['label']
                if label != cid_new.label:
                    cid_new.label = label

            # Second deal with the removal of components
            for cid_old in cids_existing:
                if not any(cid_old is cid_new for cid_new in cids_all):
                    data.remove_component(cid_old)

            # Third, update/add arithmetic expressions as needed
            for cid_new in cids_derived:
                if any(cid_new is cid_old for cid_old in cids_existing):
                    comp = data.get_component(cid_new)
                    if comp.link._parsed._cmd != self._state[data][cid_new][
                            'equation']._cmd:
                        comp.link._parsed._cmd = self._state[data][cid_new][
                            'equation']._cmd
                        comp.link._parsed._references = components
                        if data.hub:
                            msg = NumericalDataChangedMessage(data)
                            data.hub.broadcast(msg)
                else:
                    pc = ParsedCommand(
                        self._state[data][cid_new]['equation']._cmd,
                        components)
                    link = ParsedComponentLink(cid_new, pc)
                    data.add_component_link(link)

            # Findally, reorder components as needed
            data.reorder_components(cids_all)

        super(ArithmeticEditorWidget, self).accept()
示例#4
0
 def _get_parsed_command(self):
     expression = self._get_raw_command()
     return ParsedCommand(expression, self.references)