Exemplo n.º 1
0
 def load_components(self, filename):
     old_comps = self.get_selected_objects()
     if old_comps:
         num_oc = len(old_comps)
         new_comps = list()
         for comp in Component.load_components(filename, parent=self.model):
             comp.resolve_json_references()
             new_comps.append(comp)
         num_nc = len(new_comps)
         if num_oc != num_nc:
             DialogFactory.get_information_dialog(
                 "The number of components to import must equal the number of selected components!"
             ).run()
             return
         else:
             self.select_object(None)
             logger.info("Importing components...")
             # replace component(s):
             for old_comp, new_comp in zip(old_comps, new_comps):
                 i = self.model.components.index(old_comp)
                 self.model.components[i] = new_comp
     else:
         DialogFactory.get_information_dialog(
             "No components selected to replace!"
         ).run()
Exemplo n.º 2
0
 def load_components(self, filename):
     old_comps = self.get_selected_objects()
     if old_comps:
         num_oc = len(old_comps)
         new_comps = list()
         for comp in Component.load_components(filename, parent=self.model):
             comp.resolve_json_references()
             new_comps.append(comp)
         num_nc = len(new_comps)
         if num_oc != num_nc:
             DialogFactory.get_information_dialog(
                 "The number of components to import must equal the number of selected components!"
             ).run()
             return
         else:
             self.select_object(None)
             logger.info("Importing components...")
             # replace component(s):
             for old_comp, new_comp in zip(old_comps, new_comps):
                 i = self.model.components.index(old_comp)
                 self.model.components[i] = new_comp
     else:
         DialogFactory.get_information_dialog(
             "No components selected to replace!"
         ).run()
Exemplo n.º 3
0
    def phaseworker(in_queue, save_queue, stop):
        """
            Parses Phase descriptions into actual objects and passes them
            to the save_queue.
            'stop' should be a threading.Event() that should be toggled
            once all elements have been Queued.
            This way, the worker will only stop once the Queue is really empty,
            and not when it's processing faster than the Queue can be filled. 
        """
        while True:
            try:
                phases_path, phase_descr = in_queue.get(timeout=0.5)
                project = Project()
                phase_lookup = {}
                component_lookup = {}

                for phase_kwargs, code, comp_props in phase_descr:

                    # create phase:
                    G = len(code) / code_length
                    based_on = None
                    if "based_on" in phase_kwargs:
                        based_on = phase_lookup.get(phase_kwargs.pop("based_on"), None)
                    phase = Phase(G=G, parent=project, **phase_kwargs)
                    phase.based_on = based_on
                    phase_lookup[phase.name] = phase

                    # derive upper and lower limits for the codes using code lengths:
                    limits = list(zip(
                        list(range(0, len(code), code_length)),
                        list(range(code_length, len(code) + 1, code_length))
                    ))

                    # create components:
                    phase.components[:] = []
                    for ll, ul in limits:
                        part = code[ll: ul]
                        for component in Component.load_components(aliases[part] % (settings.DATA_REG.get_directory_path("DEFAULT_COMPONENTS") + "/"), parent=phase):
                            component.resolve_json_references()
                            phase.components.append(component)
                            props = comp_props.get(part, {})
                            for prop, value in props.items():
                                if prop == 'linked_with':
                                    value = component_lookup[value]
                                setattr(component, prop, value)

                            component_lookup[part] = component

                # put phases on the save queue:
                phases_path = phases_path % (settings.DATA_REG.get_directory_path("DEFAULT_PHASES") + "/")
                save_queue.put((phases_path, list(phase_lookup.values())))
                # Flag this as finished
                in_queue.task_done()
            except queue.Empty:
                if not stop.is_set():
                    continue
                else:
                    return
    def phaseworker(in_queue, save_queue, stop):
        """
            Parses Phase descriptions into actual objects and passes them
            to the save_queue.
            'stop' should be a threading.Event() that should be toggled
            once all elements have been Queued.
            This way, the worker will only stop once the Queue is really empty,
            and not when it's processing faster than the Queue can be filled. 
        """
        while True:
            try:
                phases_path, phase_descr = in_queue.get(timeout=0.5)
                project = Project()
                phase_lookup = {}
                component_lookup = {}

                for phase_kwargs, code, comp_props in phase_descr:

                    # create phase:
                    G = len(code) / code_length
                    based_on = None
                    if "based_on" in phase_kwargs:
                        based_on = phase_lookup.get(phase_kwargs.pop("based_on"), None)
                    phase = Phase(G=G, parent=project, **phase_kwargs)
                    phase.based_on = based_on
                    phase_lookup[phase.name] = phase

                    # derive upper and lower limits for the codes using code lengths:
                    limits = list(zip(
                        list(range(0, len(code), code_length)),
                        list(range(code_length, len(code) + 1, code_length))
                    ))

                    # create components:
                    phase.components[:] = []
                    for ll, ul in limits:
                        part = code[ll: ul]
                        for component in Component.load_components(aliases[part] % (settings.DATA_REG.get_directory_path("DEFAULT_COMPONENTS") + "/"), parent=phase):
                            component.resolve_json_references()
                            phase.components.append(component)
                            props = comp_props.get(part, {})
                            for prop, value in props.items():
                                if prop == 'linked_with':
                                    value = component_lookup[value]
                                setattr(component, prop, value)

                            component_lookup[part] = component

                # put phases on the save queue:
                phases_path = phases_path % (settings.DATA_REG.get_directory_path("DEFAULT_PHASES") + "/")
                save_queue.put((phases_path, list(phase_lookup.values())))
                # Flag this as finished
                in_queue.task_done()
            except queue.Empty:
                if not stop.is_set():
                    continue
                else:
                    return
Exemplo n.º 5
0
 def _setup_inheritance(self):
     self.component2 = Component()
     self.component2.linked_with = self.component
     self.component2.inherit_atom_relations = True  # TODO
     self.component2.inherit_interlayer_atoms = True  # TODO
     self.component2.inherit_layer_atoms = True  # TODO
     self.component2.inherit_delta_c = True
     self.component2.inherit_default_c = True
     self.component2.inherit_ucp_a = True  # TODO
     self.component2.inherit_ucp_b = True  # TODO
     self.component2.inherit_d001 = True
Exemplo n.º 6
0
 def on_accept(dialog):
     logger.info("Exporting components...")
     Component.save_components(self.get_selected_objects(), filename=dialog.filename)
Exemplo n.º 7
0
 def setUp(self):
     self.component = Component()
Exemplo n.º 8
0
 def on_accept(dialog):
     logger.info("Exporting components...")
     Component.save_components(self.get_selected_objects(), filename=dialog.filename)