I am extending the functions of GraphWidget that visualizes the Graph()
object.
By default, in graph-tool, when right-click on the widget, the self.picked
vertex (closest to the pointer) will be unselected.
However, i want to extend it so that 1) when right-click on the selected
vertex, it popups a menu - let's say A, while 2) right-click on the
background area, it first unselects the selected vertex and then popups
another menu, let's say B.
I know that i have to overwrite the button_press_event(), but at the branch
of event.button == 3, i cannot successfully differentiate the above two
cases. Thanks a lot.
I think the easiest way to do this is not to modify the button_press_event()
but instead to register another callback to the same event. Please take a
look at the GTK documentation on this. If you have a question, you can ask
in the GTK users' mailing list, IRC channels, etc.
Thanks for your reply, I am new to python GTK, but i was wondering if this
will have conflicts with each other because two callback functions will
response to the same event.
One quick question: But what is the differences between 1) inside my
button_press_event I also call GraphWidget.button_press_event before my code
and 2) giving two callback functions for the same event?
I think the key problem is to differentiate the position we right-click on
the GraphWidget area. Now the case is wherever i right-click, the
button_press_event cancel the selected node. It cannot check if we
right-click on the selected node or I move away and right-click on the other
places. Usually people want to have some operations on the selected node
with a right-click menu, otherwise unselect it.
I tried to handle this within the branch of event.button == 3, check the pos
of the self.picked and my current self.pointer value. But it doesn't work.
In principle,
if pos of self.picked is somehow the same as self.pointer:
then it means "right-click on selected node"
else:
it means "right-click on other area, and I want to unselect the node"