Merge pull request #440 from coreemu/pygui-rmallservices-fix
Pygui rmallservices fix
This commit is contained in:
commit
ffe6eed2f2
3 changed files with 11 additions and 55 deletions
|
@ -85,7 +85,6 @@ class CoreClient:
|
|||
self.handling_events = None
|
||||
self.xml_dir = None
|
||||
self.xml_file = None
|
||||
self.modified_service_nodes = set()
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
|
@ -112,7 +111,6 @@ class CoreClient:
|
|||
self.links.clear()
|
||||
self.hooks.clear()
|
||||
self.emane_config = None
|
||||
self.modified_service_nodes.clear()
|
||||
for mobility_player in self.mobility_players.values():
|
||||
mobility_player.handle_close()
|
||||
self.mobility_players.clear()
|
||||
|
@ -815,6 +813,11 @@ class CoreClient:
|
|||
if NodeUtils.is_custom(node_type, model):
|
||||
services = NodeUtils.get_custom_node_services(self.app.guiconfig, model)
|
||||
node.services[:] = services
|
||||
# assign default services to CORE node
|
||||
else:
|
||||
services = self.default_services.get(model, None)
|
||||
if services:
|
||||
node.services[:] = services
|
||||
logging.info(
|
||||
"add node(%s) to session(%s), coordinates(%s, %s)",
|
||||
node.name,
|
||||
|
@ -836,7 +839,6 @@ class CoreClient:
|
|||
logging.error("unknown node: %s", node_id)
|
||||
continue
|
||||
del self.canvas_nodes[node_id]
|
||||
self.modified_service_nodes.discard(node_id)
|
||||
for edge in canvas_node.edges:
|
||||
if edge in edges:
|
||||
continue
|
||||
|
@ -1052,9 +1054,6 @@ class CoreClient:
|
|||
)
|
||||
return dict(config)
|
||||
|
||||
def service_been_modified(self, node_id: int) -> bool:
|
||||
return node_id in self.modified_service_nodes
|
||||
|
||||
def execute_script(self, script):
|
||||
response = self.client.execute_script(script)
|
||||
logging.info("execute python script %s", response)
|
||||
|
|
|
@ -3,11 +3,10 @@ core node services
|
|||
"""
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox, ttk
|
||||
from typing import TYPE_CHECKING, Any, Set
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.dialogs.serviceconfig import ServiceConfigDialog
|
||||
from core.gui.nodeutils import NodeUtils
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CheckboxList, ListboxScroll
|
||||
|
||||
|
@ -17,13 +16,7 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class NodeServiceDialog(Dialog):
|
||||
def __init__(
|
||||
self,
|
||||
master: Any,
|
||||
app: "Application",
|
||||
canvas_node: "CanvasNode",
|
||||
services: Set[str] = None,
|
||||
):
|
||||
def __init__(self, master: Any, app: "Application", canvas_node: "CanvasNode"):
|
||||
title = f"{canvas_node.core_node.name} Services"
|
||||
super().__init__(master, app, title, modal=True)
|
||||
self.app = app
|
||||
|
@ -32,24 +25,7 @@ class NodeServiceDialog(Dialog):
|
|||
self.groups = None
|
||||
self.services = None
|
||||
self.current = None
|
||||
if services is None:
|
||||
services = canvas_node.core_node.services
|
||||
model = canvas_node.core_node.model
|
||||
if len(services) == 0:
|
||||
# not custom node type and node's services haven't been modified before
|
||||
if not NodeUtils.is_custom(
|
||||
canvas_node.core_node.type, canvas_node.core_node.model
|
||||
) and not self.app.core.service_been_modified(self.node_id):
|
||||
services = set(self.app.core.default_services[model])
|
||||
# services of default type nodes were modified to be empty
|
||||
elif canvas_node.core_node.id in self.app.core.modified_service_nodes:
|
||||
services = set()
|
||||
else:
|
||||
services = set(
|
||||
NodeUtils.get_custom_node_services(self.app.guiconfig, model)
|
||||
)
|
||||
else:
|
||||
services = set(services)
|
||||
services = set(canvas_node.core_node.services)
|
||||
self.current_services = services
|
||||
self.draw()
|
||||
|
||||
|
@ -103,7 +79,7 @@ class NodeServiceDialog(Dialog):
|
|||
button.grid(row=0, column=1, sticky="ew", padx=PADX)
|
||||
button = ttk.Button(frame, text="Remove", command=self.click_remove)
|
||||
button.grid(row=0, column=2, sticky="ew", padx=PADX)
|
||||
button = ttk.Button(frame, text="Cancel", command=self.click_cancel)
|
||||
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
||||
button.grid(row=0, column=3, sticky="ew")
|
||||
|
||||
# trigger group change
|
||||
|
@ -153,22 +129,8 @@ class NodeServiceDialog(Dialog):
|
|||
)
|
||||
|
||||
def click_save(self):
|
||||
# if node is custom type or current services are not the default services then
|
||||
# set core node services and add node to modified services node set
|
||||
if (
|
||||
self.canvas_node.core_node.model not in self.app.core.default_services
|
||||
or self.current_services
|
||||
!= self.app.core.default_services[self.canvas_node.core_node.model]
|
||||
):
|
||||
self.canvas_node.core_node.services[:] = self.current_services
|
||||
self.app.core.modified_service_nodes.add(self.canvas_node.core_node.id)
|
||||
else:
|
||||
if len(self.canvas_node.core_node.services) > 0:
|
||||
self.canvas_node.core_node.services[:] = []
|
||||
self.destroy()
|
||||
|
||||
def click_cancel(self):
|
||||
self.current_services = None
|
||||
core_node = self.canvas_node.core_node
|
||||
core_node.services[:] = self.current_services
|
||||
self.destroy()
|
||||
|
||||
def click_remove(self):
|
||||
|
|
|
@ -936,11 +936,6 @@ class CanvasGraph(tk.Canvas):
|
|||
node.service_file_configs = deepcopy(canvas_node.service_file_configs)
|
||||
node.config_service_configs = deepcopy(canvas_node.config_service_configs)
|
||||
|
||||
# add new node to modified_service_nodes set if that set contains the
|
||||
# to_copy node
|
||||
if self.core.service_been_modified(core_node.id):
|
||||
self.core.modified_service_nodes.add(copy.id)
|
||||
|
||||
copy_map[canvas_node.id] = node.id
|
||||
self.core.canvas_nodes[copy.id] = node
|
||||
self.nodes[node.id] = node
|
||||
|
|
Loading…
Reference in a new issue