diff --git a/coretk/coretk/app.py b/coretk/coretk/app.py index 1297c622..7330f21a 100644 --- a/coretk/coretk/app.py +++ b/coretk/coretk/app.py @@ -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() diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index f018a348..ccb47176 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -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( diff --git a/coretk/coretk/dialogs/customnodes.py b/coretk/coretk/dialogs/customnodes.py index f2423bf0..e98b8c77 100644 --- a/coretk/coretk/dialogs/customnodes.py +++ b/coretk/coretk/dialogs/customnodes.py @@ -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) diff --git a/coretk/coretk/toolbar.py b/coretk/coretk/toolbar.py index 298cc24a..ebdb4d39 100644 --- a/coretk/coretk/toolbar.py +++ b/coretk/coretk/toolbar.py @@ -145,15 +145,23 @@ 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: - self.create_button( - Images.get(image_enum), - partial(self.update_button, self.node_button, image_enum, tooltip), - self.node_picker, - tooltip, - ) + 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( + image, self.click_edit_node, self.node_picker, "custom nodes" + ) self.show_picker(self.node_button, self.node_picker) def show_picker(self, button, picker): @@ -165,17 +173,17 @@ class Toolbar(tk.Frame): self.wait_window(picker) self.app.unbind_all("") - 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("", lambda e: func()) button.grid(pady=1) CreateToolTip(button, tooltip) @@ -221,19 +229,17 @@ 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) + def click_edit_node(self): + dialog = CustomNodesDialog(self.app, self.app) + dialog.show() + + def update_button(self, button, image, name): + logging.info("update button(%s): %s", button, name) self.hide_pickers() - if image_enum == ImageEnum.EDITNODE: - dialog = CustomNodesDialog(self.app, self.app) - dialog.show() - else: - image = Images.get(image_enum) - logging.info("updating button(%s): %s", button, name) - button.configure(image=image) - self.app.canvas.mode = GraphMode.NODE - self.app.canvas.draw_node_image = image - self.app.canvas.draw_node_name = name + button.configure(image=image) + self.app.canvas.mode = GraphMode.NODE + self.app.canvas.draw_node_image = image + self.app.canvas.draw_node_name = name def hide_pickers(self): logging.info("hiding pickers")