simplified select logic to check against known nodes and modified get_selected to avoid returning the canvas id
This commit is contained in:
parent
804b95d486
commit
3c7bf57b5c
1 changed files with 3 additions and 9 deletions
|
@ -238,19 +238,15 @@ class CanvasGraph(tk.Canvas):
|
||||||
:return: the item that the mouse point to
|
:return: the item that the mouse point to
|
||||||
"""
|
"""
|
||||||
overlapping = self.find_overlapping(event.x, event.y, event.x, event.y)
|
overlapping = self.find_overlapping(event.x, event.y, event.x, event.y)
|
||||||
nodes = set(self.find_withtag("node"))
|
|
||||||
selected = None
|
selected = None
|
||||||
for _id in overlapping:
|
for _id in overlapping:
|
||||||
if self.drawing_edge and self.drawing_edge.id == _id:
|
if self.drawing_edge and self.drawing_edge.id == _id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if _id in nodes:
|
if _id in self.nodes:
|
||||||
selected = _id
|
selected = _id
|
||||||
break
|
break
|
||||||
|
|
||||||
if selected is None:
|
|
||||||
selected = _id
|
|
||||||
|
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
def click_release(self, event):
|
def click_release(self, event):
|
||||||
|
@ -362,9 +358,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.core.delete_graph_nodes(nodes)
|
self.core.delete_graph_nodes(nodes)
|
||||||
|
|
||||||
def add_node(self, x, y):
|
def add_node(self, x, y):
|
||||||
plot_id = self.find_all()[0]
|
if self.selected is None:
|
||||||
logging.info("add node event: %s - %s", plot_id, self.selected)
|
|
||||||
if self.selected == plot_id:
|
|
||||||
core_node = self.core.create_node(
|
core_node = self.core.create_node(
|
||||||
int(x), int(y), self.node_draw.node_type, self.node_draw.model
|
int(x), int(y), self.node_draw.node_type, self.node_draw.model
|
||||||
)
|
)
|
||||||
|
@ -648,7 +642,7 @@ class CanvasNode:
|
||||||
self.moving = None
|
self.moving = None
|
||||||
|
|
||||||
def motion(self, event):
|
def motion(self, event):
|
||||||
if self.canvas.mode == GraphMode.EDGE or self.canvas.mode == GraphMode.NODE:
|
if self.canvas.mode == GraphMode.EDGE:
|
||||||
return
|
return
|
||||||
x, y = self.canvas.canvas_xy(event)
|
x, y = self.canvas.canvas_xy(event)
|
||||||
self.move(x, y)
|
self.move(x, y)
|
||||||
|
|
Loading…
Reference in a new issue