2020-02-03 17:10:46 +00:00
|
|
|
import logging
|
|
|
|
import os
|
2019-09-25 16:29:34 +01:00
|
|
|
import tkinter as tk
|
2019-11-11 21:23:02 +00:00
|
|
|
from functools import partial
|
2020-01-14 19:06:52 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-12-19 17:30:21 +00:00
|
|
|
import core.gui.menuaction as action
|
|
|
|
from core.gui.coreclient import OBSERVERS
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-14 19:06:52 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
class Menubar(tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Core menubar
|
|
|
|
"""
|
|
|
|
|
2020-01-14 19:06:52 +00:00
|
|
|
def __init__(self, master: tk.Tk, app: "Application", cnf={}, **kwargs):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create a CoreMenubar instance
|
|
|
|
"""
|
2019-11-08 05:46:40 +00:00
|
|
|
super().__init__(master, cnf, **kwargs)
|
|
|
|
self.master.config(menu=self)
|
2019-11-01 20:42:49 +00:00
|
|
|
self.app = app
|
|
|
|
self.menuaction = action.MenuAction(app, master)
|
2020-02-04 21:49:46 +00:00
|
|
|
self.recent_menu = None
|
2019-11-08 05:46:40 +00:00
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
"""
|
|
|
|
Create core menubar and bind the hot keys to their matching command
|
|
|
|
"""
|
|
|
|
self.draw_file_menu()
|
|
|
|
self.draw_edit_menu()
|
|
|
|
self.draw_canvas_menu()
|
|
|
|
self.draw_view_menu()
|
|
|
|
self.draw_tools_menu()
|
|
|
|
self.draw_widgets_menu()
|
|
|
|
self.draw_session_menu()
|
|
|
|
self.draw_help_menu()
|
|
|
|
|
|
|
|
def draw_file_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create file menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
2019-12-12 19:06:52 +00:00
|
|
|
menu.add_command(
|
|
|
|
label="New Session",
|
|
|
|
accelerator="Ctrl+N",
|
|
|
|
command=self.app.core.create_new_session,
|
|
|
|
)
|
|
|
|
self.app.bind_all("<Control-n>", lambda e: self.app.core.create_new_session())
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_command(
|
|
|
|
label="Open...", command=self.menuaction.file_open_xml, accelerator="Ctrl+O"
|
2019-09-25 16:29:34 +01:00
|
|
|
)
|
2019-11-08 05:46:40 +00:00
|
|
|
self.app.bind_all("<Control-o>", self.menuaction.file_open_xml)
|
2020-01-17 23:59:12 +00:00
|
|
|
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save)
|
2019-11-27 19:41:54 +00:00
|
|
|
menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
|
2020-01-17 23:59:12 +00:00
|
|
|
self.app.bind_all("<Control-s>", self.save)
|
2020-02-03 18:53:24 +00:00
|
|
|
|
2020-02-04 21:49:46 +00:00
|
|
|
self.recent_menu = tk.Menu(menu)
|
|
|
|
for i in self.app.guiconfig["recentfiles"]:
|
|
|
|
self.recent_menu.add_command(
|
|
|
|
label=i, command=partial(self.open_recent_files, i)
|
|
|
|
)
|
|
|
|
menu.add_cascade(label="Recent files", menu=self.recent_menu)
|
2019-11-08 18:07:23 +00:00
|
|
|
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)
|
|
|
|
menu.add_command(
|
|
|
|
label="Execute Python script with options...", state=tk.DISABLED
|
|
|
|
)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Open current file in editor...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Print...", underline=0, state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Save screenshot...", state=tk.DISABLED)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(
|
|
|
|
label="Quit", accelerator="Ctrl+Q", command=self.menuaction.on_quit
|
|
|
|
)
|
|
|
|
self.app.bind_all("<Control-q>", self.menuaction.on_quit)
|
|
|
|
self.add_cascade(label="File", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_edit_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create edit menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
2019-12-11 22:09:50 +00:00
|
|
|
menu.add_command(label="Preferences", command=self.menuaction.gui_preferences)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_command(label="Undo", accelerator="Ctrl+Z", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Redo", accelerator="Ctrl+Y", state=tk.DISABLED)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Cut", accelerator="Ctrl+X", state=tk.DISABLED)
|
2019-12-20 00:15:29 +00:00
|
|
|
menu.add_command(
|
|
|
|
label="Copy", accelerator="Ctrl+C", command=self.menuaction.copy
|
|
|
|
)
|
|
|
|
menu.add_command(
|
|
|
|
label="Paste", accelerator="Ctrl+V", command=self.menuaction.paste
|
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Select all", accelerator="Ctrl+A", state=tk.DISABLED)
|
|
|
|
menu.add_command(
|
|
|
|
label="Select Adjacent", accelerator="Ctrl+J", state=tk.DISABLED
|
|
|
|
)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Find...", accelerator="Ctrl+F", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Clear marker", state=tk.DISABLED)
|
|
|
|
self.add_cascade(label="Edit", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-12-20 00:15:29 +00:00
|
|
|
self.app.master.bind_all("<Control-c>", self.menuaction.copy)
|
|
|
|
self.app.master.bind_all("<Control-v>", self.menuaction.paste)
|
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_canvas_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create canvas menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
|
|
|
menu.add_command(
|
2019-11-08 05:46:40 +00:00
|
|
|
label="Size/scale...", command=self.menuaction.canvas_size_and_scale
|
2019-10-22 21:17:47 +01:00
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_command(
|
2019-11-08 05:46:40 +00:00
|
|
|
label="Wallpaper...", command=self.menuaction.canvas_set_wallpaper
|
2019-10-25 00:50:24 +01:00
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_separator()
|
2019-12-12 19:06:52 +00:00
|
|
|
menu.add_command(label="New", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Manage...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Delete", state=tk.DISABLED)
|
|
|
|
menu.add_separator()
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_command(label="Previous", accelerator="PgUp", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Next", accelerator="PgDown", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="First", accelerator="Home", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Last", accelerator="End", state=tk.DISABLED)
|
|
|
|
self.add_cascade(label="Canvas", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_view_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create view menu
|
|
|
|
"""
|
2019-11-08 05:46:40 +00:00
|
|
|
view_menu = tk.Menu(self)
|
2019-09-25 16:29:34 +01:00
|
|
|
self.create_show_menu(view_menu)
|
2019-11-08 18:07:23 +00:00
|
|
|
view_menu.add_command(label="Show hidden nodes", state=tk.DISABLED)
|
|
|
|
view_menu.add_command(label="Locked", state=tk.DISABLED)
|
|
|
|
view_menu.add_command(label="3D GUI...", state=tk.DISABLED)
|
2019-09-25 16:29:34 +01:00
|
|
|
view_menu.add_separator()
|
2019-11-08 18:07:23 +00:00
|
|
|
view_menu.add_command(label="Zoom in", accelerator="+", state=tk.DISABLED)
|
|
|
|
view_menu.add_command(label="Zoom out", accelerator="-", state=tk.DISABLED)
|
|
|
|
self.add_cascade(label="View", menu=view_menu)
|
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_show_menu(self, view_menu: tk.Menu):
|
2019-11-08 18:07:23 +00:00
|
|
|
"""
|
|
|
|
Create the menu items in View/Show
|
|
|
|
"""
|
|
|
|
menu = tk.Menu(view_menu)
|
|
|
|
menu.add_command(label="All", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="None", state=tk.DISABLED)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Interface Names", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="IPv4 Addresses", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="IPv6 Addresses", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Node Labels", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Annotations", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Grid", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="API Messages", state=tk.DISABLED)
|
|
|
|
view_menu.add_cascade(label="Show", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_experimental_menu(self, tools_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create experimental menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(tools_menu)
|
|
|
|
menu.add_command(label="Plugins...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="ns2immunes converter...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Topology partitioning...", state=tk.DISABLED)
|
|
|
|
tools_menu.add_cascade(label="Experimental", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_random_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create random menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
# list of number of random nodes to create
|
|
|
|
nums = [1, 5, 10, 15, 20, 30, 40, 50, 75, 100]
|
|
|
|
for i in nums:
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"R({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Random", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_grid_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create grid menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
# list of number of nodes to create
|
|
|
|
nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 100]
|
|
|
|
for i in nums:
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"G({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Grid", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_connected_grid_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create connected grid menu items and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for i in range(1, 11, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
submenu = tk.Menu(menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for j in range(1, 11, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"{i} X {j}"
|
|
|
|
submenu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
label = str(i) + " X N"
|
|
|
|
menu.add_cascade(label=label, menu=submenu)
|
|
|
|
topology_generator_menu.add_cascade(label="Connected Grid", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_chain_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create chain menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
# number of nodes to create
|
|
|
|
nums = list(range(2, 25, 1)) + [32, 64, 128]
|
|
|
|
for i in nums:
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"P({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Chain", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_star_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create star menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for i in range(3, 26, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"C({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Star", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_cycle_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create cycle menu item and the sub items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for i in range(3, 25, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"C({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Cycle", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_wheel_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create wheel menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for i in range(4, 26, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"W({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Wheel", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_cube_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create cube menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for i in range(2, 7, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"Q({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Cube", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_clique_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create clique menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for i in range(3, 25, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"K({i})"
|
|
|
|
menu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
topology_generator_menu.add_cascade(label="Clique", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_bipartite_menu(self, topology_generator_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create bipartite menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(topology_generator_menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
temp = 24
|
|
|
|
for i in range(1, 13, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
submenu = tk.Menu(menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
for j in range(i, temp, 1):
|
2019-11-08 18:07:23 +00:00
|
|
|
label = f"K({i} X {j})"
|
|
|
|
submenu.add_command(label=label, state=tk.DISABLED)
|
|
|
|
label = f"K({i})"
|
|
|
|
menu.add_cascade(label=label, menu=submenu)
|
2019-09-25 16:29:34 +01:00
|
|
|
temp = temp - 1
|
2019-11-08 18:07:23 +00:00
|
|
|
topology_generator_menu.add_cascade(label="Bipartite", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_topology_generator_menu(self, tools_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create topology menu item and its sub menu items
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(tools_menu)
|
|
|
|
self.create_random_menu(menu)
|
|
|
|
self.create_grid_menu(menu)
|
|
|
|
self.create_connected_grid_menu(menu)
|
|
|
|
self.create_chain_menu(menu)
|
|
|
|
self.create_star_menu(menu)
|
|
|
|
self.create_cycle_menu(menu)
|
|
|
|
self.create_wheel_menu(menu)
|
|
|
|
self.create_cube_menu(menu)
|
|
|
|
self.create_clique_menu(menu)
|
|
|
|
self.create_bipartite_menu(menu)
|
|
|
|
tools_menu.add_cascade(label="Topology generator", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_tools_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create tools menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
|
|
|
menu.add_command(label="Auto rearrange all", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Auto rearrange selected", state=tk.DISABLED)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Align to grid", state=tk.DISABLED)
|
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Traffic...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="IP addresses...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="MAC addresses...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Build hosts file...", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Renumber nodes...", state=tk.DISABLED)
|
|
|
|
self.create_experimental_menu(menu)
|
|
|
|
self.create_topology_generator_menu(menu)
|
|
|
|
menu.add_command(label="Debugger...", state=tk.DISABLED)
|
|
|
|
self.add_cascade(label="Tools", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_observer_widgets_menu(self, widget_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create observer widget menu item and create the sub menu items inside
|
|
|
|
"""
|
2019-11-11 21:23:02 +00:00
|
|
|
var = tk.StringVar(value="none")
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(widget_menu)
|
2019-11-11 21:23:02 +00:00
|
|
|
menu.var = var
|
2019-11-11 21:33:37 +00:00
|
|
|
menu.add_command(
|
|
|
|
label="Edit Observers", command=self.menuaction.edit_observer_widgets
|
|
|
|
)
|
|
|
|
menu.add_separator()
|
2019-11-11 21:23:02 +00:00
|
|
|
menu.add_radiobutton(
|
|
|
|
label="None",
|
|
|
|
variable=var,
|
|
|
|
value="none",
|
|
|
|
command=lambda: self.app.core.set_observer(None),
|
|
|
|
)
|
2019-11-11 23:35:48 +00:00
|
|
|
for name in sorted(OBSERVERS):
|
|
|
|
cmd = OBSERVERS[name]
|
2019-11-11 21:23:02 +00:00
|
|
|
menu.add_radiobutton(
|
|
|
|
label=name,
|
|
|
|
variable=var,
|
|
|
|
value=name,
|
|
|
|
command=partial(self.app.core.set_observer, cmd),
|
|
|
|
)
|
2019-11-11 21:33:37 +00:00
|
|
|
for name in sorted(self.app.core.custom_observers):
|
2019-11-11 22:04:50 +00:00
|
|
|
observer = self.app.core.custom_observers[name]
|
2019-11-11 21:33:37 +00:00
|
|
|
menu.add_radiobutton(
|
|
|
|
label=name,
|
|
|
|
variable=var,
|
|
|
|
value=name,
|
2019-11-11 22:04:50 +00:00
|
|
|
command=partial(self.app.core.set_observer, observer.cmd),
|
2019-11-11 21:33:37 +00:00
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
widget_menu.add_cascade(label="Observer Widgets", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
def create_adjacency_menu(self, widget_menu: tk.Menu):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create adjacency menu item and the sub menu items inside
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(widget_menu)
|
|
|
|
menu.add_command(label="OSPFv2", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="OSPFv3", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="OSLR", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="OSLRv2", state=tk.DISABLED)
|
|
|
|
widget_menu.add_cascade(label="Adjacency", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_widgets_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create widget menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
|
|
|
self.create_observer_widgets_menu(menu)
|
|
|
|
self.create_adjacency_menu(menu)
|
2019-12-09 16:53:54 +00:00
|
|
|
menu.add_checkbutton(label="Throughput", command=self.menuaction.throughput)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Configure Adjacency...", state=tk.DISABLED)
|
2019-12-20 19:56:51 +00:00
|
|
|
menu.add_command(
|
|
|
|
label="Configure Throughput...", command=self.menuaction.config_throughput
|
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
self.add_cascade(label="Widgets", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_session_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create session menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
|
|
|
menu.add_command(
|
2019-12-11 22:09:50 +00:00
|
|
|
label="Sessions...", command=self.menuaction.session_change_sessions
|
2019-09-25 16:29:34 +01:00
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_separator()
|
|
|
|
menu.add_command(label="Options...", command=self.menuaction.session_options)
|
2019-12-11 22:09:50 +00:00
|
|
|
menu.add_command(label="Servers...", command=self.menuaction.session_servers)
|
|
|
|
menu.add_command(label="Hooks...", command=self.menuaction.session_hooks)
|
|
|
|
menu.add_command(label="Reset Nodes", state=tk.DISABLED)
|
|
|
|
menu.add_command(label="Comments...", state=tk.DISABLED)
|
2019-11-08 18:07:23 +00:00
|
|
|
self.add_cascade(label="Session", menu=menu)
|
2019-09-25 16:29:34 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_help_menu(self):
|
2019-09-25 16:29:34 +01:00
|
|
|
"""
|
|
|
|
Create help menu
|
|
|
|
"""
|
2019-11-08 18:07:23 +00:00
|
|
|
menu = tk.Menu(self)
|
|
|
|
menu.add_command(
|
2019-11-22 06:39:39 +00:00
|
|
|
label="Core GitHub (www)", command=self.menuaction.help_core_github
|
2019-09-25 16:29:34 +01:00
|
|
|
)
|
2019-11-08 18:07:23 +00:00
|
|
|
menu.add_command(
|
2019-10-11 01:02:28 +01:00
|
|
|
label="Core Documentation (www)",
|
2019-11-08 05:46:40 +00:00
|
|
|
command=self.menuaction.help_core_documentation,
|
2019-09-25 16:29:34 +01:00
|
|
|
)
|
2019-12-06 19:13:43 +00:00
|
|
|
menu.add_command(label="About", command=self.menuaction.show_about)
|
2019-11-08 18:07:23 +00:00
|
|
|
self.add_cascade(label="Help", menu=menu)
|
2020-01-17 23:59:12 +00:00
|
|
|
|
2020-02-03 17:10:46 +00:00
|
|
|
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)
|
|
|
|
|
2020-02-04 21:49:46 +00:00
|
|
|
def update_recent_files(self):
|
|
|
|
self.recent_menu.delete(0, tk.END)
|
|
|
|
for i in self.app.guiconfig["recentfiles"]:
|
|
|
|
self.recent_menu.add_command(
|
|
|
|
label=i, command=partial(self.open_recent_files, i)
|
|
|
|
)
|
|
|
|
|
2020-02-04 21:00:00 +00:00
|
|
|
def save(self, event=None):
|
2020-01-17 23:59:12 +00:00
|
|
|
xml_file = self.app.core.xml_file
|
|
|
|
if xml_file:
|
|
|
|
self.app.core.save_xml(xml_file)
|
|
|
|
else:
|
|
|
|
self.menuaction.file_save_as_xml()
|