updates to draw custom nodes on the node picker frame
This commit is contained in:
parent
22177def1c
commit
b0fe5660bd
4 changed files with 37 additions and 30 deletions
|
@ -72,7 +72,8 @@ class Application(tk.Frame):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s"
|
||||
logging.basicConfig(level=logging.DEBUG, format=log_format)
|
||||
appdirs.check_directory()
|
||||
app = Application()
|
||||
app.mainloop()
|
||||
|
|
|
@ -13,8 +13,8 @@ from coretk.interface import Interface, InterfaceManager
|
|||
from coretk.mobilitynodeconfig import MobilityNodeConfig
|
||||
from coretk.wlannodeconfig import WlanNodeConfig
|
||||
|
||||
link_layer_nodes = ["switch", "hub", "wlan", "rj45", "tunnel", "emane"]
|
||||
network_layer_nodes = ["router", "host", "PC", "mdr", "prouter"]
|
||||
NETWORK_NODES = ["switch", "hub", "wlan", "rj45", "tunnel", "emane"]
|
||||
DEFAULT_NODES = ["router", "host", "PC", "mdr", "prouter"]
|
||||
|
||||
|
||||
class Node:
|
||||
|
@ -422,7 +422,7 @@ class CoreClient:
|
|||
"""
|
||||
node_type = None
|
||||
node_model = None
|
||||
if name in link_layer_nodes:
|
||||
if name in NETWORK_NODES:
|
||||
if name == "switch":
|
||||
node_type = core_pb2.NodeType.SWITCH
|
||||
elif name == "hub":
|
||||
|
@ -437,7 +437,7 @@ class CoreClient:
|
|||
node_type = core_pb2.NodeType.TUNNEL
|
||||
elif name == "emane":
|
||||
node_type = core_pb2.NodeType.EMANE
|
||||
elif name in network_layer_nodes:
|
||||
elif name in DEFAULT_NODES or name in self.custom_nodes:
|
||||
node_type = core_pb2.NodeType.DEFAULT
|
||||
node_model = name
|
||||
else:
|
||||
|
@ -606,7 +606,7 @@ class CoreClient:
|
|||
self.interfaces_manager.new_subnet()
|
||||
|
||||
src_node = self.nodes[src_canvas_id]
|
||||
if src_node.model in network_layer_nodes:
|
||||
if src_node.model in DEFAULT_NODES:
|
||||
ifid = len(src_node.interfaces)
|
||||
name = "eth" + str(ifid)
|
||||
src_interface = Interface(
|
||||
|
@ -620,7 +620,7 @@ class CoreClient:
|
|||
)
|
||||
|
||||
dst_node = self.nodes[dst_canvas_id]
|
||||
if dst_node.model in network_layer_nodes:
|
||||
if dst_node.model in DEFAULT_NODES:
|
||||
ifid = len(dst_node.interfaces)
|
||||
name = "eth" + str(ifid)
|
||||
dst_interface = Interface(
|
||||
|
|
|
@ -208,7 +208,7 @@ class CustomNodesDialog(Dialog):
|
|||
custom_node = self.app.core.custom_nodes.pop(previous_name)
|
||||
custom_node.name = name
|
||||
custom_node.image = self.image
|
||||
custom_node.image_file = Path(self.image_file).name
|
||||
custom_node.image_file = Path(self.image_file).stem
|
||||
custom_node.services = self.services
|
||||
self.app.core.custom_nodes[name] = custom_node
|
||||
self.nodes_list.listbox.delete(self.selected_index)
|
||||
|
|
|
@ -145,14 +145,22 @@ class Toolbar(tk.Frame):
|
|||
(ImageEnum.PC, "PC"),
|
||||
(ImageEnum.MDR, "mdr"),
|
||||
(ImageEnum.PROUTER, "prouter"),
|
||||
(ImageEnum.EDITNODE, "custom node types"),
|
||||
]
|
||||
# draw default nodes
|
||||
for image_enum, tooltip in nodes:
|
||||
image = Images.get(image_enum)
|
||||
func = partial(self.update_button, self.node_button, image, tooltip)
|
||||
self.create_button(image, func, self.node_picker, tooltip)
|
||||
# draw custom nodes
|
||||
for name in sorted(self.app.core.custom_nodes):
|
||||
custom_node = self.app.core.custom_nodes[name]
|
||||
image = custom_node.image
|
||||
func = partial(self.update_button, self.node_button, image, name)
|
||||
self.create_button(image, func, self.node_picker, name)
|
||||
# draw edit node
|
||||
image = Images.get(ImageEnum.EDITNODE)
|
||||
self.create_button(
|
||||
Images.get(image_enum),
|
||||
partial(self.update_button, self.node_button, image_enum, tooltip),
|
||||
self.node_picker,
|
||||
tooltip,
|
||||
image, self.click_edit_node, self.node_picker, "custom nodes"
|
||||
)
|
||||
self.show_picker(self.node_button, self.node_picker)
|
||||
|
||||
|
@ -165,17 +173,17 @@ class Toolbar(tk.Frame):
|
|||
self.wait_window(picker)
|
||||
self.app.unbind_all("<Button-1>")
|
||||
|
||||
def create_button(self, img, func, frame, tooltip):
|
||||
def create_button(self, image, func, frame, tooltip):
|
||||
"""
|
||||
Create button and put it on the frame
|
||||
|
||||
:param PIL.Image img: button image
|
||||
:param PIL.Image image: button image
|
||||
:param func: the command that is executed when button is clicked
|
||||
:param tkinter.Frame frame: frame that contains the button
|
||||
:param str tooltip: tooltip text
|
||||
:return: nothing
|
||||
"""
|
||||
button = tk.Button(frame, width=self.width, height=self.height, image=img)
|
||||
button = tk.Button(frame, width=self.width, height=self.height, image=image)
|
||||
button.bind("<Button-1>", lambda e: func())
|
||||
button.grid(pady=1)
|
||||
CreateToolTip(button, tooltip)
|
||||
|
@ -221,15 +229,13 @@ class Toolbar(tk.Frame):
|
|||
logging.debug("Click LINK button")
|
||||
self.app.canvas.mode = GraphMode.EDGE
|
||||
|
||||
def update_button(self, button, image_enum, name):
|
||||
logging.info("update button(%s): %s, %s", button, image_enum, name)
|
||||
self.hide_pickers()
|
||||
if image_enum == ImageEnum.EDITNODE:
|
||||
def click_edit_node(self):
|
||||
dialog = CustomNodesDialog(self.app, self.app)
|
||||
dialog.show()
|
||||
else:
|
||||
image = Images.get(image_enum)
|
||||
logging.info("updating button(%s): %s", button, name)
|
||||
|
||||
def update_button(self, button, image, name):
|
||||
logging.info("update button(%s): %s", button, name)
|
||||
self.hide_pickers()
|
||||
button.configure(image=image)
|
||||
self.app.canvas.mode = GraphMode.NODE
|
||||
self.app.canvas.draw_node_image = image
|
||||
|
|
Loading…
Add table
Reference in a new issue