Merge branch 'coretk' of https://github.com/coreemu/core into coretk
This commit is contained in:
commit
6a08bff7de
18 changed files with 166 additions and 76 deletions
|
@ -416,7 +416,7 @@ class CoreClient:
|
|||
else:
|
||||
emane_config = None
|
||||
|
||||
start = time.time()
|
||||
start = time.perf_counter()
|
||||
response = self.client.start_session(
|
||||
self.session_id,
|
||||
nodes,
|
||||
|
@ -430,7 +430,7 @@ class CoreClient:
|
|||
service_configs,
|
||||
file_configs,
|
||||
)
|
||||
process_time = time.time() - start
|
||||
process_time = time.perf_counter() - start
|
||||
logging.debug("start session(%s), result: %s", self.session_id, response.result)
|
||||
self.app.statusbar.start_session_callback(process_time)
|
||||
|
||||
|
@ -444,9 +444,9 @@ class CoreClient:
|
|||
def stop_session(self, session_id=None):
|
||||
if not session_id:
|
||||
session_id = self.session_id
|
||||
start = time.time()
|
||||
start = time.perf_counter()
|
||||
response = self.client.stop_session(session_id)
|
||||
process_time = time.time() - start
|
||||
process_time = time.perf_counter() - start
|
||||
self.app.statusbar.stop_session_callback(process_time)
|
||||
logging.debug("stopped session(%s), result: %s", session_id, response.result)
|
||||
|
||||
|
|
44
coretk/coretk/dialogs/about.py
Normal file
44
coretk/coretk/dialogs/about.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import tkinter as tk
|
||||
|
||||
from coretk.dialogs.dialog import Dialog
|
||||
from coretk.widgets import CodeText
|
||||
|
||||
LICENSE = """\
|
||||
Copyright (c) 2005-2020, the Boeing Company.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.\
|
||||
"""
|
||||
|
||||
|
||||
class AboutDialog(Dialog):
|
||||
def __init__(self, master, app):
|
||||
super().__init__(master, app, "About CORE", modal=True)
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
self.top.rowconfigure(0, weight=1)
|
||||
|
||||
text = CodeText(self.top)
|
||||
text.insert("1.0", LICENSE)
|
||||
text.config(state=tk.DISABLED)
|
||||
text.grid(sticky="nsew")
|
|
@ -3,6 +3,7 @@ from tkinter import ttk
|
|||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk.dialogs.dialog import Dialog
|
||||
from coretk.widgets import CodeText
|
||||
|
||||
|
||||
class HookDialog(Dialog):
|
||||
|
@ -43,7 +44,7 @@ class HookDialog(Dialog):
|
|||
frame.columnconfigure(0, weight=1)
|
||||
frame.rowconfigure(0, weight=1)
|
||||
frame.grid(row=1, sticky="nsew", pady=2)
|
||||
self.data = tk.Text(frame)
|
||||
self.data = CodeText(frame)
|
||||
self.data.insert(
|
||||
1.0,
|
||||
(
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from tkinter.scrolledtext import ScrolledText
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk.dialogs.dialog import Dialog
|
||||
from coretk.images import ImageEnum, Images
|
||||
from coretk.widgets import ListboxScroll
|
||||
from coretk.widgets import CodeText, ListboxScroll
|
||||
|
||||
|
||||
class ServiceConfiguration(Dialog):
|
||||
|
@ -182,7 +181,7 @@ class ServiceConfiguration(Dialog):
|
|||
button.grid(row=0, column=2)
|
||||
frame.grid(row=3, column=0, sticky="nsew")
|
||||
|
||||
self.service_file_data = ScrolledText(tab1)
|
||||
self.service_file_data = CodeText(tab1)
|
||||
self.service_file_data.grid(row=4, column=0, sticky="nsew")
|
||||
if len(self.filenames) > 0:
|
||||
self.filename_combobox.current(0)
|
||||
|
|
|
@ -4,7 +4,6 @@ import tkinter as tk
|
|||
from PIL import Image, ImageTk
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from core.api.grpc.core_pb2 import NodeType
|
||||
from coretk.dialogs.shapemod import ShapeDialog
|
||||
from coretk.graph.edges import CanvasEdge, CanvasWirelessEdge
|
||||
from coretk.graph.enums import GraphMode, ScaleOption
|
||||
|
@ -64,40 +63,6 @@ class CanvasGraph(tk.Canvas):
|
|||
self.show_grid = tk.BooleanVar(value=True)
|
||||
self.adjust_to_dim = tk.BooleanVar(value=False)
|
||||
|
||||
def create_node_context(self, canvas_node):
|
||||
node = canvas_node.core_node
|
||||
context = tk.Menu(self.master)
|
||||
context.add_command(label="Configure", command=canvas_node.show_config)
|
||||
if node.type == NodeType.WIRELESS_LAN:
|
||||
context.add_command(
|
||||
label="WLAN Config", command=canvas_node.show_wlan_config
|
||||
)
|
||||
if self.master.core.is_runtime():
|
||||
if canvas_node.core_node.id in self.master.core.mobility_players:
|
||||
context.add_command(
|
||||
label="Mobility Player",
|
||||
command=canvas_node.show_mobility_player,
|
||||
)
|
||||
else:
|
||||
context.add_command(
|
||||
label="Mobility Config", command=canvas_node.show_mobility_config
|
||||
)
|
||||
if node.type == NodeType.EMANE:
|
||||
context.add_command(
|
||||
label="EMANE Config", command=canvas_node.show_emane_config
|
||||
)
|
||||
context.add_command(label="Select adjacent", state=tk.DISABLED)
|
||||
context.add_command(label="Create link to", state=tk.DISABLED)
|
||||
context.add_command(label="Assign to", state=tk.DISABLED)
|
||||
context.add_command(label="Move to", state=tk.DISABLED)
|
||||
context.add_command(label="Cut", state=tk.DISABLED)
|
||||
context.add_command(label="Copy", state=tk.DISABLED)
|
||||
context.add_command(label="Paste", state=tk.DISABLED)
|
||||
context.add_command(label="Delete", state=tk.DISABLED)
|
||||
context.add_command(label="Hide", state=tk.DISABLED)
|
||||
context.add_command(label="Services", state=tk.DISABLED)
|
||||
return context
|
||||
|
||||
def reset_and_redraw(self, session):
|
||||
"""
|
||||
Reset the private variables CanvasGraph object, redraw nodes given the new grpc
|
||||
|
@ -517,7 +482,7 @@ class CanvasGraph(tk.Canvas):
|
|||
canvas_node = self.nodes.get(selected)
|
||||
if canvas_node:
|
||||
logging.debug(f"node context: {selected}")
|
||||
self.context = self.create_node_context(canvas_node)
|
||||
self.context = canvas_node.create_context()
|
||||
self.context.post(event.x_root, event.y_root)
|
||||
else:
|
||||
self.context.unpost()
|
||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
|||
import tkinter as tk
|
||||
from tkinter import font
|
||||
|
||||
from core.api.grpc.core_pb2 import NodeType
|
||||
from coretk.dialogs.emaneconfig import EmaneConfigDialog
|
||||
from coretk.dialogs.mobilityconfig import MobilityConfigDialog
|
||||
from coretk.dialogs.nodeconfig import NodeConfigDialog
|
||||
|
@ -36,6 +37,15 @@ class CanvasNode:
|
|||
fill="#0000CD",
|
||||
)
|
||||
self.tooltip = CanvasTooltip(self.canvas)
|
||||
self.edges = set()
|
||||
self.interfaces = []
|
||||
self.wireless_edges = set()
|
||||
self.moving = None
|
||||
self.antennae = []
|
||||
self.setup_bindings()
|
||||
|
||||
def setup_bindings(self):
|
||||
# self.canvas.bind("<Button-3>", self.click_context)
|
||||
self.canvas.tag_bind(self.id, "<ButtonPress-1>", self.click_press)
|
||||
self.canvas.tag_bind(self.id, "<ButtonRelease-1>", self.click_release)
|
||||
self.canvas.tag_bind(self.id, "<B1-Motion>", self.motion)
|
||||
|
@ -43,11 +53,6 @@ class CanvasNode:
|
|||
self.canvas.tag_bind(self.id, "<Control-1>", self.select_multiple)
|
||||
self.canvas.tag_bind(self.id, "<Enter>", self.on_enter)
|
||||
self.canvas.tag_bind(self.id, "<Leave>", self.on_leave)
|
||||
self.edges = set()
|
||||
self.interfaces = []
|
||||
self.wireless_edges = set()
|
||||
self.moving = None
|
||||
self.antennae = []
|
||||
|
||||
def delete(self):
|
||||
self.canvas.delete(self.id)
|
||||
|
@ -186,6 +191,53 @@ class CanvasNode:
|
|||
shape = self.canvas.shapes[object_id]
|
||||
shape.motion(None, x - my_x, y - my_y)
|
||||
|
||||
def create_context(self):
|
||||
is_wlan = self.core_node.type == NodeType.WIRELESS_LAN
|
||||
is_emane = self.core_node.type == NodeType.EMANE
|
||||
context = tk.Menu(self.canvas)
|
||||
if self.app.core.is_runtime():
|
||||
context.add_command(label="Configure", command=self.show_config)
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
context.add_command(label="Services", state=tk.DISABLED)
|
||||
if is_wlan and self.core_node.id in self.app.core.mobility_players:
|
||||
context.add_command(
|
||||
label="Mobility Player", command=self.show_mobility_player
|
||||
)
|
||||
context.add_command(label="Select Adjacent", state=tk.DISABLED)
|
||||
context.add_command(label="Hide", state=tk.DISABLED)
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
context.add_command(label="Shell Window", state=tk.DISABLED)
|
||||
context.add_command(label="Tcpdump", state=tk.DISABLED)
|
||||
context.add_command(label="Tshark", state=tk.DISABLED)
|
||||
context.add_command(label="Wireshark", state=tk.DISABLED)
|
||||
context.add_command(label="View Log", state=tk.DISABLED)
|
||||
else:
|
||||
context.add_command(label="Configure", command=self.show_config)
|
||||
if NodeUtils.is_container_node(self.core_node.type):
|
||||
context.add_command(label="Services", state=tk.DISABLED)
|
||||
if is_emane:
|
||||
context.add_command(
|
||||
label="EMANE Config", command=self.show_emane_config
|
||||
)
|
||||
if is_wlan:
|
||||
context.add_command(label="WLAN Config", command=self.show_wlan_config)
|
||||
context.add_command(
|
||||
label="Mobility Config", command=self.show_mobility_config
|
||||
)
|
||||
if NodeUtils.is_wireless_node(self.core_node.type):
|
||||
context.add_command(label="Link To All MDRs", state=tk.DISABLED)
|
||||
context.add_command(label="Select Members", state=tk.DISABLED)
|
||||
context.add_command(label="Select Adjacent", state=tk.DISABLED)
|
||||
context.add_command(label="Create Link To", state=tk.DISABLED)
|
||||
context.add_command(label="Assign To", state=tk.DISABLED)
|
||||
context.add_command(label="Move To", state=tk.DISABLED)
|
||||
context.add_command(label="Cut", state=tk.DISABLED)
|
||||
context.add_command(label="Copy", state=tk.DISABLED)
|
||||
context.add_command(label="Paste", state=tk.DISABLED)
|
||||
context.add_command(label="Delete", state=tk.DISABLED)
|
||||
context.add_command(label="Hide", state=tk.DISABLED)
|
||||
return context
|
||||
|
||||
def select_multiple(self, event):
|
||||
self.canvas.select_object(self.id, choose_multiple=True)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import grpc
|
|||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk.appconfig import XML_PATH
|
||||
from coretk.dialogs.about import AboutDialog
|
||||
from coretk.dialogs.canvasbackground import CanvasBackgroundDialog
|
||||
from coretk.dialogs.canvassizeandscale import SizeAndScaleDialog
|
||||
from coretk.dialogs.hooks import HooksDialog
|
||||
|
@ -33,10 +34,10 @@ class MenuAction:
|
|||
|
||||
def cleanup_old_session(self, quitapp=False):
|
||||
logging.info("cleaning up old session")
|
||||
start = time.time()
|
||||
start = time.perf_counter()
|
||||
self.app.core.stop_session()
|
||||
self.app.core.delete_session()
|
||||
process_time = time.time() - start
|
||||
process_time = time.perf_counter() - start
|
||||
self.app.statusbar.stop_session_callback(process_time)
|
||||
if quitapp:
|
||||
self.app.quit()
|
||||
|
@ -151,3 +152,7 @@ class MenuAction:
|
|||
def edit_observer_widgets(self):
|
||||
dialog = ObserverDialog(self.app, self.app)
|
||||
dialog.show()
|
||||
|
||||
def show_about(self):
|
||||
dialog = AboutDialog(self.app, self.app)
|
||||
dialog.show()
|
||||
|
|
|
@ -462,5 +462,5 @@ class Menubar(tk.Menu):
|
|||
label="Core Documentation (www)",
|
||||
command=self.menuaction.help_core_documentation,
|
||||
)
|
||||
menu.add_command(label="About", state=tk.DISABLED)
|
||||
menu.add_command(label="About", command=self.menuaction.show_about)
|
||||
self.add_cascade(label="Help", menu=menu)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
from tkinter import ttk
|
||||
from tkinter import font, ttk
|
||||
from tkinter.scrolledtext import ScrolledText
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
|
||||
|
@ -155,3 +156,26 @@ class CheckboxList(FrameScroll):
|
|||
func = partial(self.clicked, name, var)
|
||||
checkbox = ttk.Checkbutton(self.frame, text=name, variable=var, command=func)
|
||||
checkbox.grid(sticky="w")
|
||||
|
||||
|
||||
class CodeFont(font.Font):
|
||||
def __init__(self):
|
||||
super().__init__(font="TkFixedFont", color="green")
|
||||
|
||||
|
||||
class CodeText(ScrolledText):
|
||||
def __init__(self, master, **kwargs):
|
||||
super().__init__(
|
||||
master,
|
||||
bd=0,
|
||||
bg="black",
|
||||
cursor="xterm lime lime",
|
||||
fg="lime",
|
||||
font=CodeFont(),
|
||||
highlightbackground="black",
|
||||
insertbackground="lime",
|
||||
selectbackground="lime",
|
||||
selectforeground="black",
|
||||
relief=tk.FLAT,
|
||||
**kwargs
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue