working on shape config

This commit is contained in:
Huy Pham 2019-12-03 17:17:45 -08:00
parent 0a26a8f8e3
commit 41a9b88189
3 changed files with 65 additions and 28 deletions

View file

@ -11,20 +11,35 @@ BORDER_WIDTH = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
class ShapeDialog(Dialog):
def __init__(self, master, app, shape_id):
def __init__(self, master, app, shape):
super().__init__(master, app, "Add a new shape", modal=True)
self.canvas = app.canvas
self.id = shape_id
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)
self.id = shape.id
data = shape.shape_data
self.shape_text = tk.StringVar(value=data.text)
self.font = tk.StringVar(value=data.font)
self.font_size = tk.IntVar(value=data.font_size)
self.text_color = data.text_color
self.fill_color = data.fill_color
self.border_color = data.border_color
self.border_width = tk.IntVar(value=data.border_width)
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
@ -146,20 +161,24 @@ class ShapeDialog(Dialog):
)
shape = self.canvas.shapes[self.id]
shape_text = self.shape_text.get()
if shape.text is None:
size = int(self.font_size.get())
x0, y0, x1, y1 = self.canvas.bbox(self.id)
text_y = y0 + 2 * size
text_x = (x0 + x1) / 2
f = [self.font.get(), size]
if self.bold.get() == 1:
f.append("bold")
if self.italic.get() == 1:
f.append("italic")
if self.underline.get() == 1:
f.append("underline")
size = int(self.font_size.get())
x0, y0, x1, y1 = self.canvas.bbox(self.id)
text_y = y0 + 2 * size
text_x = (x0 + x1) / 2
f = [self.font.get(), size]
if self.bold.get() == 1:
f.append("bold")
if self.italic.get() == 1:
f.append("italic")
if self.underline.get() == 1:
f.append("underline")
if shape.text_id is None:
shape.text = self.canvas.create_text(
text_x, text_y, text=shape_text, fill=self.text_color, font=f
)
self.canvas.shapes[self.id].created = True
self.canvas.shapes[self.id].created = True
else:
self.canvas.itemconfig(
shape.text_id, text=shape_text, fill=self.text_color, font=f
)
self.destroy()

View file

@ -11,6 +11,7 @@ from coretk.canvastooltip import CanvasTooltip
from coretk.dialogs.emaneconfig import EmaneConfigDialog
from coretk.dialogs.mobilityconfig import MobilityConfigDialog
from coretk.dialogs.nodeconfig import NodeConfigDialog
from coretk.dialogs.shapemod import ShapeDialog
from coretk.dialogs.wlanconfig import WlanConfigDialog
from coretk.graph_helper import GraphHelper, WlanAntennaManager
from coretk.images import ImageEnum, Images
@ -445,7 +446,8 @@ class CanvasGraph(tk.Canvas):
def double_click(self, event):
selected = self.get_selected(event)
if selected is not None and "shape" in self.gettags(selected):
print("bring up shape dialog ")
s = ShapeDialog(self.app, self.app, self.shapes[selected])
print(s)
def add_node(self, x, y):
if self.selected is None or "shape" in self.gettags(self.selected):

View file

@ -9,6 +9,20 @@ from coretk.images import ImageEnum
ABOVE_COMPONENT = ["gridline", "edge", "linkinfo", "antenna", "node", "nodename"]
class ShapeData:
def __init__(self):
self.text = ""
self.font = "Arial"
self.font_size = 12
self.text_color = "#000000"
self.fill_color = "#CFCFFF"
self.border_color = "#000000"
self.border_width = 0
self.bold = 0
self.italic = 0
self.underline = 0
class Shape:
def __init__(self, app, canvas, top_x, top_y):
self.app = app
@ -18,7 +32,9 @@ class Shape:
self.cursor_x = None
self.cursor_y = None
self.created = False
self.text = None
self.text_id = None
self.shape_data = ShapeData()
canvas.delete(canvas.find_withtag("selectednodes"))
annotation_type = self.canvas.annotation_type
if annotation_type == ImageEnum.OVAL:
@ -38,7 +54,7 @@ class Shape:
def shape_complete(self, x, y):
for component in ABOVE_COMPONENT:
self.canvas.tag_raise(component)
s = ShapeDialog(self.app, self.app, self.id)
s = ShapeDialog(self.app, self.app, self)
s.show()
def click_release(self, event):