Merge pull request #364 from coreemu/coretk-enhance/fix-bug
Coretk enhance/fix bug
This commit is contained in:
commit
26a03cc758
5 changed files with 50 additions and 5 deletions
|
@ -110,6 +110,8 @@ class CoreClient:
|
|||
self.xml_dir = None
|
||||
self.xml_file = None
|
||||
|
||||
self.modified_service_nodes = set()
|
||||
|
||||
def reset(self):
|
||||
# helpers
|
||||
self.interfaces_manager.reset()
|
||||
|
@ -124,6 +126,7 @@ class CoreClient:
|
|||
self.emane_config = None
|
||||
self.service_configs.clear()
|
||||
self.file_configs.clear()
|
||||
self.modified_service_nodes.clear()
|
||||
for mobility_player in self.mobility_players.values():
|
||||
mobility_player.handle_close()
|
||||
self.mobility_players.clear()
|
||||
|
@ -806,6 +809,9 @@ class CoreClient:
|
|||
logging.error("unknown node: %s", node_id)
|
||||
continue
|
||||
del self.canvas_nodes[node_id]
|
||||
|
||||
self.modified_service_nodes.discard(node_id)
|
||||
|
||||
if node_id in self.mobility_configs:
|
||||
del self.mobility_configs[node_id]
|
||||
if node_id in self.wlan_configs:
|
||||
|
@ -1046,3 +1052,6 @@ class CoreClient:
|
|||
config = self.emane_model_configs.get(_from)
|
||||
if config:
|
||||
self.emane_model_configs[_to] = config
|
||||
|
||||
def service_been_modified(self, node_id: int) -> bool:
|
||||
return node_id in self.modified_service_nodes
|
||||
|
|
|
@ -36,8 +36,14 @@ class NodeServiceDialog(Dialog):
|
|||
services = canvas_node.core_node.services
|
||||
model = canvas_node.core_node.model
|
||||
if len(services) == 0:
|
||||
if not NodeUtils.is_custom(canvas_node.core_node.model):
|
||||
# not custom node type and node's services haven't been modified before
|
||||
if not NodeUtils.is_custom(
|
||||
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)
|
||||
|
@ -141,12 +147,14 @@ 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[:] = []
|
||||
|
|
|
@ -854,6 +854,11 @@ class CanvasGraph(tk.Canvas):
|
|||
node = CanvasNode(
|
||||
self.master, scaled_x, scaled_y, copy, self.nodes[canvas_nid].image
|
||||
)
|
||||
|
||||
# add new node to modified_service_nodes set if that set contains the to_copy node
|
||||
if self.app.core.service_been_modified(core_node.id):
|
||||
self.app.core.modified_service_nodes.add(copy.id)
|
||||
|
||||
copy_map[canvas_nid] = node.id
|
||||
self.core.canvas_nodes[copy.id] = node
|
||||
self.nodes[node.id] = node
|
||||
|
|
|
@ -89,12 +89,15 @@ class MenuAction:
|
|||
title="Open",
|
||||
filetypes=(("XML Files", "*.xml"), ("All Files", "*")),
|
||||
)
|
||||
if file_path:
|
||||
self.app.core.xml_file = file_path
|
||||
self.app.core.xml_dir = str(os.path.dirname(file_path))
|
||||
self.open_xml_task(file_path)
|
||||
|
||||
def open_xml_task(self, filename):
|
||||
if filename:
|
||||
self.app.core.xml_file = filename
|
||||
self.app.core.xml_dir = str(os.path.dirname(filename))
|
||||
self.prompt_save_running_session()
|
||||
self.app.statusbar.progress_bar.start(5)
|
||||
task = BackgroundTask(self.app, self.app.core.open_xml, args=(file_path,))
|
||||
task = BackgroundTask(self.app, self.app.core.open_xml, args=(filename,))
|
||||
task.start()
|
||||
|
||||
def gui_preferences(self):
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import logging
|
||||
import os
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
from typing import TYPE_CHECKING
|
||||
|
@ -55,6 +57,17 @@ class Menubar(tk.Menu):
|
|||
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save)
|
||||
menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
|
||||
self.app.bind_all("<Control-s>", self.save)
|
||||
|
||||
# some hard code values for testing
|
||||
sample_xmls = [
|
||||
"sample1.xml",
|
||||
"/home/ncs/.coretk/xmls/sample1.xml",
|
||||
"sample1.xml",
|
||||
]
|
||||
recent = tk.Menu(menu)
|
||||
for i in sample_xmls:
|
||||
recent.add_command(label=i, command=partial(self.open_recent_files, i))
|
||||
menu.add_cascade(label="Recent files", menu=recent)
|
||||
menu.add_separator()
|
||||
menu.add_command(label="Export Python script...", state=tk.DISABLED)
|
||||
menu.add_command(label="Execute XML or Python script...", state=tk.DISABLED)
|
||||
|
@ -409,6 +422,13 @@ class Menubar(tk.Menu):
|
|||
menu.add_command(label="About", command=self.menuaction.show_about)
|
||||
self.add_cascade(label="Help", menu=menu)
|
||||
|
||||
def open_recent_files(self, filename: str):
|
||||
if os.path.isfile(filename):
|
||||
logging.debug("Open recent file %s", filename)
|
||||
self.menuaction.open_xml_task(filename)
|
||||
else:
|
||||
logging.warning("File does not exist %s", filename)
|
||||
|
||||
def save(self):
|
||||
xml_file = self.app.core.xml_file
|
||||
if xml_file:
|
||||
|
|
Loading…
Reference in a new issue