2

I would like to be able to retrieve the vertex_index of a currently selected vertex (the vertex currently having the mouse over it). I have not found this question asked in StackOverflow, nor this information mentioned in the official graph-tool documentation.

For example, I would like to retrieve the value "56" from this graph :

example_graph

2 Answers2

1

As is explained in the documentation, https://graph-tool.skewed.de/static/doc/draw.html#graph_tool.draw.graph_draw, the selected vertices are returned as property map, in addition to their position:

pos, selected = graph_draw(g)
v = numpy.where(selected.a == True)  # get selected vertices
Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28
-1

As I have found in the graph-tool source code here : https://git.skewed.de/count0/graph-tool/blob/a5574175680333e4dd948c7a89c3514281cfe7e7/src/graph_tool/draw/gtk_draw.py#L539

The text displayed on the bottom left corner can be retrieved from the picked attribute of the GraphWidget class.

  • Not only is this unnecessary, as the values are already provided by the API (see my answer), but it is also error prone, as the undocumented contents of that class can change in the future. – Tiago Peixoto May 16 '18 at 11:35