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): 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) super().__init__(master, app, "Add a new shape", modal=True)
self.canvas = app.canvas self.canvas = app.canvas
self.id = shape_id self.id = shape.id
self.shape_text = tk.StringVar(value="") data = shape.shape_data
self.font = tk.StringVar(value="Arial") self.shape_text = tk.StringVar(value=data.text)
self.font_size = tk.IntVar(value=12) self.font = tk.StringVar(value=data.font)
self.text_color = "#000000" self.font_size = tk.IntVar(value=data.font_size)
self.fill_color = "#CFCFFF" self.text_color = data.text_color
self.border_color = "black" self.fill_color = data.fill_color
self.border_width = tk.IntVar(value=0) self.border_color = data.border_color
self.bold = tk.IntVar(value=0) self.border_width = tk.IntVar(value=data.border_width)
self.italic = tk.IntVar(value=0) self.bold = tk.IntVar(value=data.bold)
self.underline = tk.IntVar(value=0) 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.fill = None
self.border = None self.border = None
@ -146,20 +161,24 @@ class ShapeDialog(Dialog):
) )
shape = self.canvas.shapes[self.id] shape = self.canvas.shapes[self.id]
shape_text = self.shape_text.get() shape_text = self.shape_text.get()
if shape.text is None: size = int(self.font_size.get())
size = int(self.font_size.get()) x0, y0, x1, y1 = self.canvas.bbox(self.id)
x0, y0, x1, y1 = self.canvas.bbox(self.id) text_y = y0 + 2 * size
text_y = y0 + 2 * size text_x = (x0 + x1) / 2
text_x = (x0 + x1) / 2 f = [self.font.get(), size]
f = [self.font.get(), size] if self.bold.get() == 1:
if self.bold.get() == 1: f.append("bold")
f.append("bold") if self.italic.get() == 1:
if self.italic.get() == 1: f.append("italic")
f.append("italic") if self.underline.get() == 1:
if self.underline.get() == 1: f.append("underline")
f.append("underline") if shape.text_id is None:
shape.text = self.canvas.create_text( shape.text = self.canvas.create_text(
text_x, text_y, text=shape_text, fill=self.text_color, font=f 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() self.destroy()

View file

@ -11,6 +11,7 @@ from coretk.canvastooltip import CanvasTooltip
from coretk.dialogs.emaneconfig import EmaneConfigDialog from coretk.dialogs.emaneconfig import EmaneConfigDialog
from coretk.dialogs.mobilityconfig import MobilityConfigDialog from coretk.dialogs.mobilityconfig import MobilityConfigDialog
from coretk.dialogs.nodeconfig import NodeConfigDialog from coretk.dialogs.nodeconfig import NodeConfigDialog
from coretk.dialogs.shapemod import ShapeDialog
from coretk.dialogs.wlanconfig import WlanConfigDialog from coretk.dialogs.wlanconfig import WlanConfigDialog
from coretk.graph_helper import GraphHelper, WlanAntennaManager from coretk.graph_helper import GraphHelper, WlanAntennaManager
from coretk.images import ImageEnum, Images from coretk.images import ImageEnum, Images
@ -445,7 +446,8 @@ class CanvasGraph(tk.Canvas):
def double_click(self, event): def double_click(self, event):
selected = self.get_selected(event) selected = self.get_selected(event)
if selected is not None and "shape" in self.gettags(selected): 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): def add_node(self, x, y):
if self.selected is None or "shape" in self.gettags(self.selected): 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"] 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: class Shape:
def __init__(self, app, canvas, top_x, top_y): def __init__(self, app, canvas, top_x, top_y):
self.app = app self.app = app
@ -18,7 +32,9 @@ class Shape:
self.cursor_x = None self.cursor_x = None
self.cursor_y = None self.cursor_y = None
self.created = False self.created = False
self.text = None self.text_id = None
self.shape_data = ShapeData()
canvas.delete(canvas.find_withtag("selectednodes")) canvas.delete(canvas.find_withtag("selectednodes"))
annotation_type = self.canvas.annotation_type annotation_type = self.canvas.annotation_type
if annotation_type == ImageEnum.OVAL: if annotation_type == ImageEnum.OVAL:
@ -38,7 +54,7 @@ class Shape:
def shape_complete(self, x, y): def shape_complete(self, x, y):
for component in ABOVE_COMPONENT: for component in ABOVE_COMPONENT:
self.canvas.tag_raise(component) self.canvas.tag_raise(component)
s = ShapeDialog(self.app, self.app, self.id) s = ShapeDialog(self.app, self.app, self)
s.show() s.show()
def click_release(self, event): def click_release(self, event):