def test(argv): # Create graph widget app = QtWidgets.QApplication(argv) graph = GraphWidget(None) graph.ast = ASTModel.get_ast(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../apps/simple/simple.camkes")) print ASTModel.find_instance(graph.ast.assembly.instances, "echo") is not None # find_component is not being tested because it is not used anywhere. However # there is no reason why find_component will fail to work, if everything else worked. print "visualCAmkES test passed" return 0
def sync_model(self): """ Updates view to the model representation """ # Get assembly from the ast ast_assembly = self.ast.assembly assert isinstance(ast_assembly, Assembly) # --- For each instance, create a node in the graph & a widget. --- instance_list_copy = list(ast_assembly.instances) widgets_to_remove = [] # Update widget's instance object counterpart for widget in self.widget_instances: assert isinstance(widget, InstanceWidget) new_instance_object = ASTModel.find_instance(instance_list_copy, widget.name) if new_instance_object is not None: # If found, replace widget's local copy self.sync_instance(new_instance_object, widget) instance_list_copy.remove(new_instance_object) else: # Instance object for widget not found, probably deleted - so widget not necessary widgets_to_remove.append(widget) # Delete the widget (since it is not possible to delete the widget during iteration) for widget in widgets_to_remove: self.remove_instance_widget(widget) for instance in instance_list_copy: # For all new instances (instances without widget counterpart) # Make a new widget assert isinstance(instance, Instance) new_widget = InstanceWidget(self.context_menu) new_widget.color = self.random_color_generator() self.sync_instance(instance, new_widget) new_widget.widget_moved.connect(self.update_view) # Add to internal list of widgets self.widget_instances.append(new_widget) # Add to scene self.reposition_instance_widget(new_widget, 0, 0) self.clear_connection_widgets() # Create connection widgets for all connections in assembly # Instead of syncing connections, ConnectionWidgets are considered disposable. Just delete all and remake them assert isinstance(self.ast.assembly, Assembly) for connection in self.ast.assembly.connections: assert isinstance(connection, Connection) for from_instance_end in connection.from_ends: assert isinstance(from_instance_end, ConnectionEnd) from_instance = from_instance_end.instance assert isinstance(from_instance, Instance) for to_instance_end in connection.to_ends: assert isinstance(to_instance_end, ConnectionEnd) to_instance = to_instance_end.instance assert isinstance(to_instance, Instance) new_connection_widget = self.create_connection_widget(connection, from_instance.name, from_instance_end.interface.name, to_instance.name, to_instance_end.interface.name) self.connection_widgets.append(new_connection_widget) self.add_connection_widget(new_connection_widget)