コード例 #1
0
	def importGraph(self):
		# This method is called to import a new graph.
		# An empty graph to populate is accessible through the "graph" class attribute
		# (see documentation of class tlp.Graph).

		# The parameters provided by the user are stored in a Tulip DataSet 
		# and can be accessed through the "dataSet" class attribute
		# (see documentation of class tlp.DataSet).

		# The method must return a boolean indicating if the
		# graph has been successfully imported.
		
		if not tulipnx.checkNetworkX(self.pluginProgress):
			return False
			
		graph = self.graph
		
		n = self.dataSet["n"]
		m = self.dataSet["m"]
		p = self.dataSet["p"]
		
		bp_graph = tulipnx.bipartite_random_graph(n, m, p)
		
		tulipnx.nxGraphToTlpGraph(bp_graph, graph)	
		
		return True
コード例 #2
0
	def importGraph(self):
		# This method is called to import a new graph.
		# An empty graph to populate is accessible through the "graph" class attribute
		# (see documentation of class tlp.Graph).

		# The parameters provided by the user are stored in a Tulip DataSet 
		# and can be accessed through the "dataSet" class attribute
		# (see documentation of class tlp.DataSet).

		# The method must return a boolean indicating if the
		# graph has been successfully imported.
		
		if not tulipnx.checkNetworkX(self.pluginProgress):
			return False
			
		graph = self.graph
		
		graphMLFile = self.dataSet["file::filename"]
		
		nx_graph = None

		try:	
			nx_graph = tulipnx.nx.read_graphml(graphMLFile)
		except:
			pass
		
		if nx_graph:
			tulipnx.nxGraphToTlpGraph(nx_graph, graph)		
			return True
		else:
			if self.pluginProgress:
				self.pluginProgress.setError("An error occurred when trying to import the GraphML file")
			return False