Merge branch 'coretk' of https://github.com/coreemu/core into coretk
This commit is contained in:
commit
1de3ac9d09
6 changed files with 76 additions and 43 deletions
BIN
coretk/coretk/data/icons/tunnel.png
Normal file
BIN
coretk/coretk/data/icons/tunnel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 799 B |
|
@ -26,24 +26,8 @@ class ShapeDialog(Dialog):
|
|||
self.bold = tk.IntVar(value=data.bold)
|
||||
self.italic = tk.IntVar(value=data.italic)
|
||||
self.underline = tk.IntVar(value=data.underline)
|
||||
|
||||
# else:
|
||||
# self.fill_color = self.canvas.itemcget(self.id, "fill")
|
||||
# self.shape_text = tk.StringVar(value="")
|
||||
# self.font = tk.StringVar(value="Arial")
|
||||
# self.font_size = tk.IntVar(value=12)
|
||||
# self.text_color = "#000000"
|
||||
# # self.fill_color = "#CFCFFF"
|
||||
# self.border_color = "black"
|
||||
# self.border_width = tk.IntVar(value=0)
|
||||
# self.bold = tk.IntVar(value=0)
|
||||
# self.italic = tk.IntVar(value=0)
|
||||
# self.underline = tk.IntVar(value=0)
|
||||
# print(self.fill_color)
|
||||
|
||||
self.fill = None
|
||||
self.border = None
|
||||
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
self.draw()
|
||||
|
||||
|
@ -91,7 +75,7 @@ class ShapeDialog(Dialog):
|
|||
frame.columnconfigure(2, weight=1)
|
||||
label = ttk.Label(frame, text="Fill color")
|
||||
label.grid(row=0, column=0, sticky="nsew")
|
||||
self.fill = ttk.Label(frame, text=self.fill_color, background="#CFCFFF")
|
||||
self.fill = ttk.Label(frame, text=self.fill_color, background=self.fill_color)
|
||||
self.fill.grid(row=0, column=1, sticky="nsew", padx=3)
|
||||
button = ttk.Button(frame, text="Color", command=self.choose_fill_color)
|
||||
button.grid(row=0, column=2, sticky="nsew")
|
||||
|
@ -173,7 +157,7 @@ class ShapeDialog(Dialog):
|
|||
if self.underline.get() == 1:
|
||||
f.append("underline")
|
||||
if shape.text_id is None:
|
||||
shape.text = self.canvas.create_text(
|
||||
shape.text_id = self.canvas.create_text(
|
||||
text_x, text_y, text=shape_text, fill=self.text_color, font=f
|
||||
)
|
||||
self.canvas.shapes[self.id].created = True
|
||||
|
@ -181,4 +165,15 @@ class ShapeDialog(Dialog):
|
|||
self.canvas.itemconfig(
|
||||
shape.text_id, text=shape_text, fill=self.text_color, font=f
|
||||
)
|
||||
data = self.canvas.shapes[self.id].shape_data
|
||||
data.text = shape_text
|
||||
data.font = self.font.get()
|
||||
data.font_size = int(self.font_size.get())
|
||||
data.text_color = self.text_color
|
||||
data.fill_color = self.fill_color
|
||||
data.border_color = self.border_color
|
||||
data.border_width = int(self.border_width.get())
|
||||
data.bold = self.bold.get()
|
||||
data.italic = self.italic.get()
|
||||
data.underline = self.underline.get()
|
||||
self.destroy()
|
||||
|
|
|
@ -377,21 +377,28 @@ class CanvasGraph(tk.Canvas):
|
|||
self.selected = shape.id
|
||||
self.shapes[shape.id] = shape
|
||||
self.shape_drawing = True
|
||||
if self.mode == GraphMode.SELECT:
|
||||
if selected is not None:
|
||||
if "shape" in self.gettags(selected):
|
||||
x, y = self.canvas_xy(event)
|
||||
self.shapes[selected].cursor_x = x
|
||||
self.shapes[selected].cursor_y = y
|
||||
if selected not in self.canvas_management.selected:
|
||||
self.canvas_management.node_select(self.shapes[selected])
|
||||
self.selected = selected
|
||||
else:
|
||||
for i in self.find_withtag("selectednodes"):
|
||||
self.delete(i)
|
||||
self.canvas_management.selected.clear()
|
||||
|
||||
def ctrl_click(self, event):
|
||||
logging.debug("Control left click %s", event)
|
||||
selected = self.get_selected(event)
|
||||
if (
|
||||
self.mode == GraphMode.SELECT
|
||||
and selected is not None
|
||||
and "shape" in self.gettags(selected)
|
||||
):
|
||||
x, y = self.canvas_xy(event)
|
||||
self.shapes[selected].cursor_x = x
|
||||
self.shapes[selected].cursor_y = y
|
||||
self.canvas_management.node_select(self.shapes[selected])
|
||||
self.selected = selected
|
||||
|
||||
def ctrl_click(self, event):
|
||||
logging.debug("Control left click %s", event)
|
||||
selected = self.get_selected(event)
|
||||
if self.mode == GraphMode.SELECT and "shape" in self.gettags(selected):
|
||||
self.canvas_management.node_select(self.shapes[selected], True)
|
||||
|
||||
def click_motion(self, event):
|
||||
|
@ -417,7 +424,19 @@ class CanvasGraph(tk.Canvas):
|
|||
and self.selected is not None
|
||||
and "shape" in self.gettags(self.selected)
|
||||
):
|
||||
self.shapes[self.selected].motion(event)
|
||||
x, y = self.canvas_xy(event)
|
||||
shape = self.shapes[self.selected]
|
||||
delta_x = x - shape.cursor_x
|
||||
delta_y = y - shape.cursor_y
|
||||
shape.motion(event)
|
||||
# move other selected components
|
||||
for nid in self.canvas_management.selected:
|
||||
if nid != self.selected and nid in self.shapes:
|
||||
self.shapes[nid].motion(None, delta_x, delta_y)
|
||||
if nid != self.selected and nid in self.nodes:
|
||||
node_x = self.nodes[nid].core_node.position.x
|
||||
node_y = self.nodes[nid].core_node.position.y
|
||||
self.nodes[nid].move(node_x + delta_x, node_y + delta_y)
|
||||
|
||||
def click_context(self, event):
|
||||
logging.info("context event: %s", self.context)
|
||||
|
@ -448,7 +467,7 @@ class CanvasGraph(tk.Canvas):
|
|||
selected = self.get_selected(event)
|
||||
if selected is not None and "shape" in self.gettags(selected):
|
||||
s = ShapeDialog(self.app, self.app, self.shapes[selected])
|
||||
print(s)
|
||||
s.show()
|
||||
|
||||
def add_node(self, x, y):
|
||||
if self.selected is None or "shape" in self.gettags(self.selected):
|
||||
|
@ -766,8 +785,9 @@ class CanvasNode:
|
|||
def click_press(self, event):
|
||||
logging.debug(f"node click press {self.core_node.name}: {event}")
|
||||
self.moving = self.canvas.canvas_xy(event)
|
||||
self.canvas.canvas_management.node_select(self)
|
||||
self.canvas.selected = self.id
|
||||
if self.id not in self.canvas.canvas_management.selected:
|
||||
self.canvas.canvas_management.node_select(self)
|
||||
self.canvas.selected = self.id
|
||||
|
||||
def click_release(self, event):
|
||||
logging.debug(f"node click release {self.core_node.name}: {event}")
|
||||
|
@ -778,7 +798,19 @@ class CanvasNode:
|
|||
if self.canvas.mode == GraphMode.EDGE:
|
||||
return
|
||||
x, y = self.canvas.canvas_xy(event)
|
||||
my_x = self.core_node.position.x
|
||||
my_y = self.core_node.position.y
|
||||
self.move(x, y)
|
||||
# move other selected components
|
||||
for nid, bboxid in self.canvas.canvas_management.selected.items():
|
||||
if nid != self.id and nid in self.canvas.nodes:
|
||||
other_old_x = self.canvas.nodes[nid].core_node.position.x
|
||||
other_old_y = self.canvas.nodes[nid].core_node.position.y
|
||||
other_new_x = x + other_old_x - my_x
|
||||
other_new_y = y + other_old_y - my_y
|
||||
self.canvas.nodes[nid].move(other_new_x, other_new_y)
|
||||
if nid != self.id and nid in self.canvas.shapes:
|
||||
self.canvas.shapes[nid].motion(None, x - my_x, y - my_y)
|
||||
|
||||
def select_multiple(self, event):
|
||||
self.canvas.canvas_management.node_select(self, True)
|
||||
|
|
|
@ -33,6 +33,9 @@ class CanvasComponentManagement:
|
|||
tags="selectednodes",
|
||||
)
|
||||
self.selected[canvas_node.id] = bbox_id
|
||||
else:
|
||||
bbox_id = self.selected.pop(canvas_node.id)
|
||||
self.canvas.delete(bbox_id)
|
||||
|
||||
def node_drag(self, canvas_node, offset_x, offset_y):
|
||||
select_id = self.selected.get(canvas_node.id)
|
||||
|
@ -87,7 +90,7 @@ class CanvasComponentManagement:
|
|||
for shape_id in self.selected:
|
||||
if "shape" in self.canvas.gettags(shape_id):
|
||||
bbox_id = self.selected[node_id]
|
||||
self.canvas.delete(shape_id)
|
||||
self.canvas.shapes[shape_id].delete()
|
||||
self.canvas.delete(bbox_id)
|
||||
self.canvas.shapes.pop(shape_id)
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ class Shape:
|
|||
top_x, top_y, top_x, top_y, tags="shape", dash="-"
|
||||
)
|
||||
self.canvas.tag_bind(self.id, "<ButtonRelease-1>", self.click_release)
|
||||
# self.canvas.tag_bind(self.id, "<B1-Motion>", self.motion)
|
||||
|
||||
def shape_motion(self, x1, y1):
|
||||
self.canvas.coords(self.id, self.x0, self.y0, x1, y1)
|
||||
|
@ -60,14 +59,18 @@ class Shape:
|
|||
def click_release(self, event):
|
||||
logging.debug("Click release on shape %s", self.id)
|
||||
|
||||
def motion(self, event):
|
||||
def motion(self, event, delta_x=None, delta_y=None):
|
||||
logging.debug("motion on shape %s", self.id)
|
||||
delta_x = event.x - self.cursor_x
|
||||
delta_y = event.y - self.cursor_y
|
||||
x0, y0, x1, y1 = self.canvas.bbox(self.id)
|
||||
self.canvas.coords(
|
||||
self.id, x0 + delta_x, y0 + delta_y, x1 + delta_x, y1 + delta_y
|
||||
)
|
||||
if event is not None:
|
||||
delta_x = event.x - self.cursor_x
|
||||
delta_y = event.y - self.cursor_y
|
||||
self.cursor_x = event.x
|
||||
self.cursor_y = event.y
|
||||
self.canvas.move(self.id, delta_x, delta_y)
|
||||
self.canvas.canvas_management.node_drag(self, delta_x, delta_y)
|
||||
self.cursor_x = event.x
|
||||
self.cursor_y = event.y
|
||||
if self.text_id is not None:
|
||||
self.canvas.move(self.text_id, delta_x, delta_y)
|
||||
|
||||
def delete(self):
|
||||
self.canvas.delete(self.id)
|
||||
self.canvas.delete(self.text_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue