Create a class for menubar and start working on toolbar
This commit is contained in:
parent
06979141ad
commit
000da143f9
9 changed files with 1153 additions and 632 deletions
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
|
||||
import coretk.menuaction as action
|
||||
from coretk.coremenubar import CoreMenubar
|
||||
from coretk.coretoolbar import CoreToolbar
|
||||
from coretk.graph import CanvasGraph
|
||||
from coretk.images import Images
|
||||
|
||||
|
@ -33,638 +34,14 @@ class Application(tk.Frame):
|
|||
self.master.tk.call("wm", "iconphoto", self.master._w, image)
|
||||
self.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
def create_file_menu(self):
|
||||
"""
|
||||
Create file menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
file_menu = tk.Menu(self.menubar)
|
||||
file_menu.add_command(
|
||||
label="New", command=action.file_new, accelerator="Ctrl+N", underline=0
|
||||
)
|
||||
file_menu.add_command(
|
||||
label="Open...", command=action.file_open, accelerator="Ctrl+O", underline=0
|
||||
)
|
||||
file_menu.add_command(label="Reload", command=action.file_reload, underline=0)
|
||||
file_menu.add_command(
|
||||
label="Save", command=action.file_save, accelerator="Ctrl+S", underline=0
|
||||
)
|
||||
file_menu.add_command(label="Save As XML...", command=action.file_save_as_xml)
|
||||
file_menu.add_command(label="Save As imn...", command=action.file_save_as_imn)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(
|
||||
label="Export Python script...", command=action.file_export_python_script
|
||||
)
|
||||
file_menu.add_command(
|
||||
label="Execute XML or Python script...",
|
||||
command=action.file_execute_xml_or_python_script,
|
||||
)
|
||||
file_menu.add_command(
|
||||
label="Execute Python script with options...",
|
||||
command=action.file_execute_python_script_with_options,
|
||||
)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(
|
||||
label="Open current file in editor...",
|
||||
command=action.file_open_current_file_in_editor,
|
||||
)
|
||||
file_menu.add_command(label="Print...", command=action.file_print, underline=0)
|
||||
file_menu.add_command(
|
||||
label="Save screenshot...", command=action.file_save_screenshot
|
||||
)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(
|
||||
label="/home/ncs/.core/configs/sample1.imn",
|
||||
command=action.file_example_link,
|
||||
)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(label="Quit", command=self.master.quit, underline=0)
|
||||
self.menubar.add_cascade(label="File", menu=file_menu, underline=0)
|
||||
|
||||
def create_edit_menu(self):
|
||||
"""
|
||||
Create edit menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
edit_menu = tk.Menu(self.menubar)
|
||||
edit_menu.add_command(
|
||||
label="Undo", command=action.edit_undo, accelerator="Ctrl+Z", underline=0
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Redo", command=action.edit_redo, accelerator="Ctrl+Y", underline=0
|
||||
)
|
||||
|
||||
edit_menu.add_separator()
|
||||
|
||||
edit_menu.add_command(
|
||||
label="Cut", command=action.edit_cut, accelerator="Ctrl+X", underline=0
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Copy", command=action.edit_copy, accelerator="Ctrl+C", underline=0
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Paste", command=action.edit_paste, accelerator="Ctrl+V", underline=0
|
||||
)
|
||||
|
||||
edit_menu.add_separator()
|
||||
|
||||
edit_menu.add_command(
|
||||
label="Select all", command=action.edit_select_all, accelerator="Ctrl+A"
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Select Adjacent",
|
||||
command=action.edit_select_adjacent,
|
||||
accelerator="Ctrl+J",
|
||||
)
|
||||
|
||||
edit_menu.add_separator()
|
||||
|
||||
edit_menu.add_command(
|
||||
label="Find...", command=action.edit_find, accelerator="Ctrl+F", underline=0
|
||||
)
|
||||
edit_menu.add_command(label="Clear marker", command=action.edit_clear_marker)
|
||||
edit_menu.add_command(label="Preferences...", command=action.edit_preferences)
|
||||
|
||||
self.menubar.add_cascade(label="Edit", menu=edit_menu, underline=0)
|
||||
|
||||
def create_canvas_menu(self):
|
||||
"""
|
||||
Create canvas menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
canvas_menu = tk.Menu(self.menubar)
|
||||
canvas_menu.add_command(label="New", command=action.canvas_new)
|
||||
canvas_menu.add_command(label="Manage...", command=action.canvas_manage)
|
||||
canvas_menu.add_command(label="Delete", command=action.canvas_delete)
|
||||
|
||||
canvas_menu.add_separator()
|
||||
|
||||
canvas_menu.add_command(label="Size/scale...", command=action.canvas_size_scale)
|
||||
canvas_menu.add_command(label="Wallpaper...", command=action.canvas_wallpaper)
|
||||
|
||||
canvas_menu.add_separator()
|
||||
|
||||
canvas_menu.add_command(
|
||||
label="Previous", command=action.canvas_previous, accelerator="PgUp"
|
||||
)
|
||||
canvas_menu.add_command(
|
||||
label="Next", command=action.canvas_next, accelerator="PgDown"
|
||||
)
|
||||
canvas_menu.add_command(
|
||||
label="First", command=action.canvas_first, accelerator="Home"
|
||||
)
|
||||
canvas_menu.add_command(
|
||||
label="Last", command=action.canvas_last, accelerator="End"
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="Canvas", menu=canvas_menu, underline=0)
|
||||
|
||||
def create_show_menu(self, view_menu):
|
||||
"""
|
||||
Create the menu items in View/Show
|
||||
|
||||
:param tkinter.Menu view_menu: the view menu
|
||||
:return: nothing
|
||||
"""
|
||||
show_menu = tk.Menu(view_menu)
|
||||
show_menu.add_command(label="All", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="None", command=action.sub_menu_items)
|
||||
show_menu.add_separator()
|
||||
show_menu.add_command(label="Interface Names", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="IPv4 Addresses", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="IPv6 Addresses", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="Node Labels", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="Annotations", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="Grid", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="API Messages", command=action.sub_menu_items)
|
||||
|
||||
view_menu.add_cascade(label="Show", menu=show_menu)
|
||||
|
||||
def create_view_menu(self):
|
||||
"""
|
||||
Create view menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
view_menu = tk.Menu(self.menubar)
|
||||
self.create_show_menu(view_menu)
|
||||
view_menu.add_command(
|
||||
label="Show hidden nodes", command=action.view_show_hidden_nodes
|
||||
)
|
||||
view_menu.add_command(label="Locked", command=action.view_locked)
|
||||
view_menu.add_command(label="3D GUI...", command=action.view_3d_gui)
|
||||
|
||||
view_menu.add_separator()
|
||||
|
||||
view_menu.add_command(
|
||||
label="Zoom in", command=action.view_zoom_in, accelerator="+"
|
||||
)
|
||||
view_menu.add_command(
|
||||
label="Zoom out", command=action.view_zoom_out, accelerator="-"
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="View", menu=view_menu, underline=0)
|
||||
|
||||
def create_experimental_menu(self, tools_menu):
|
||||
"""
|
||||
Create experimental menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu tools_menu: tools menu
|
||||
:return: nothing
|
||||
"""
|
||||
experimental_menu = tk.Menu(tools_menu)
|
||||
experimental_menu.add_command(
|
||||
label="Plugins...", command=action.sub_menu_items, underline=0
|
||||
)
|
||||
experimental_menu.add_command(
|
||||
label="ns2immunes converter...", command=action.sub_menu_items, underline=0
|
||||
)
|
||||
experimental_menu.add_command(
|
||||
label="Topology partitioning...", command=action.sub_menu_items
|
||||
)
|
||||
|
||||
tools_menu.add_cascade(
|
||||
label="Experimental", menu=experimental_menu, underline=0
|
||||
)
|
||||
|
||||
def create_random_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create random menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
random_menu = tk.Menu(topology_generator_menu)
|
||||
# list of number of random nodes to create
|
||||
nums = [1, 5, 10, 15, 20, 30, 40, 50, 75, 100]
|
||||
for i in nums:
|
||||
the_label = "R(" + str(i) + ")"
|
||||
random_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Random", menu=random_menu, underline=0
|
||||
)
|
||||
|
||||
def create_grid_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create grid menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology_generator_menu
|
||||
:return: nothing
|
||||
"""
|
||||
grid_menu = tk.Menu(topology_generator_menu)
|
||||
|
||||
# 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:
|
||||
the_label = "G(" + str(i) + ")"
|
||||
grid_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Grid", menu=grid_menu, underline=0)
|
||||
|
||||
def create_connected_grid_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create connected grid menu items and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
grid_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(1, 11, 1):
|
||||
i_n_menu = tk.Menu(grid_menu)
|
||||
for j in range(1, 11, 1):
|
||||
i_j_label = str(i) + " X " + str(j)
|
||||
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
|
||||
i_n_label = str(i) + " X N"
|
||||
grid_menu.add_cascade(label=i_n_label, menu=i_n_menu)
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Connected Grid", menu=grid_menu, underline=0
|
||||
)
|
||||
|
||||
def create_chain_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create chain menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
chain_menu = tk.Menu(topology_generator_menu)
|
||||
# number of nodes to create
|
||||
nums = list(range(2, 25, 1)) + [32, 64, 128]
|
||||
for i in nums:
|
||||
the_label = "P(" + str(i) + ")"
|
||||
chain_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Chain", menu=chain_menu, underline=0)
|
||||
|
||||
def create_star_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create star menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
star_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(3, 26, 1):
|
||||
the_label = "C(" + str(i) + ")"
|
||||
star_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Star", menu=star_menu, underline=0)
|
||||
|
||||
def create_cycle_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create cycle menu item and the sub items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
cycle_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(3, 25, 1):
|
||||
the_label = "C(" + str(i) + ")"
|
||||
cycle_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Cycle", menu=cycle_menu, underline=0)
|
||||
|
||||
def create_wheel_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create wheel menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
wheel_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(4, 26, 1):
|
||||
the_label = "W(" + str(i) + ")"
|
||||
wheel_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Wheel", menu=wheel_menu, underline=0)
|
||||
|
||||
def create_cube_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create cube menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
cube_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(2, 7, 1):
|
||||
the_label = "Q(" + str(i) + ")"
|
||||
cube_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Cube", menu=cube_menu, underline=0)
|
||||
|
||||
def create_clique_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create clique menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
clique_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(3, 25, 1):
|
||||
the_label = "K(" + str(i) + ")"
|
||||
clique_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Clique", menu=clique_menu, underline=0
|
||||
)
|
||||
|
||||
def create_bipartite_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create bipartite menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology_generator_menu
|
||||
:return: nothing
|
||||
"""
|
||||
bipartite_menu = tk.Menu(topology_generator_menu)
|
||||
temp = 24
|
||||
for i in range(1, 13, 1):
|
||||
i_n_menu = tk.Menu(bipartite_menu)
|
||||
for j in range(i, temp, 1):
|
||||
i_j_label = "K(" + str(i) + " X " + str(j) + ")"
|
||||
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
|
||||
i_n_label = "K(" + str(i) + " X N)"
|
||||
bipartite_menu.add_cascade(label=i_n_label, menu=i_n_menu)
|
||||
temp = temp - 1
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Bipartite", menu=bipartite_menu, underline=0
|
||||
)
|
||||
|
||||
def create_topology_generator_menu(self, tools_menu):
|
||||
"""
|
||||
Create topology menu item and its sub menu items
|
||||
|
||||
:param tkinter.Menu tools_menu: tools menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
topology_generator_menu = tk.Menu(tools_menu)
|
||||
|
||||
self.create_random_menu(topology_generator_menu)
|
||||
self.create_grid_menu(topology_generator_menu)
|
||||
self.create_connected_grid_menu(topology_generator_menu)
|
||||
self.create_chain_menu(topology_generator_menu)
|
||||
self.create_star_menu(topology_generator_menu)
|
||||
self.create_cycle_menu(topology_generator_menu)
|
||||
self.create_wheel_menu(topology_generator_menu)
|
||||
self.create_cube_menu(topology_generator_menu)
|
||||
self.create_clique_menu(topology_generator_menu)
|
||||
self.create_bipartite_menu(topology_generator_menu)
|
||||
|
||||
tools_menu.add_cascade(
|
||||
label="Topology generator", menu=topology_generator_menu, underline=0
|
||||
)
|
||||
|
||||
def create_tools_menu(self):
|
||||
"""
|
||||
Create tools menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
tools_menu = tk.Menu(self.menubar)
|
||||
tools_menu.add_command(
|
||||
label="Auto rearrange all",
|
||||
command=action.tools_auto_rearrange_all,
|
||||
underline=0,
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Auto rearrange selected",
|
||||
command=action.tools_auto_rearrange_selected,
|
||||
underline=0,
|
||||
)
|
||||
tools_menu.add_separator()
|
||||
|
||||
tools_menu.add_command(
|
||||
label="Align to grid", command=action.tools_align_to_grid, underline=0
|
||||
)
|
||||
|
||||
tools_menu.add_separator()
|
||||
|
||||
tools_menu.add_command(label="Traffic...", command=action.tools_traffic)
|
||||
tools_menu.add_command(
|
||||
label="IP addresses...", command=action.tools_ip_addresses, underline=0
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="MAC addresses...", command=action.tools_mac_addresses, underline=0
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Build hosts file...",
|
||||
command=action.tools_build_hosts_file,
|
||||
underline=0,
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Renumber nodes...", command=action.tools_renumber_nodes, underline=0
|
||||
)
|
||||
self.create_experimental_menu(tools_menu)
|
||||
self.create_topology_generator_menu(tools_menu)
|
||||
tools_menu.add_command(label="Debugger...", command=action.tools_debugger)
|
||||
|
||||
self.menubar.add_cascade(label="Tools", menu=tools_menu, underline=0)
|
||||
|
||||
def create_observer_widgets_menu(self, widget_menu):
|
||||
"""
|
||||
Create observer widget menu item and create the sub menu items inside
|
||||
|
||||
:param tkinter.Menu widget_menu: widget_menu
|
||||
:return: nothing
|
||||
"""
|
||||
observer_widget_menu = tk.Menu(widget_menu)
|
||||
observer_widget_menu.add_command(label="None", command=action.sub_menu_items)
|
||||
observer_widget_menu.add_command(
|
||||
label="processes", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="ifconfig", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv4 routes", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv6 routes", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="OSPFv2 neighbors", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="OSPFv3 neighbors", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="Listening sockets", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv4 MFC entries", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv6 MFC entries", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="firewall rules", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPsec policies", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="docker logs", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="OSPFv3 MDR level", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="PIM neighbors", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(label="Edit...", command=action.sub_menu_items)
|
||||
|
||||
widget_menu.add_cascade(label="Observer Widgets", menu=observer_widget_menu)
|
||||
|
||||
def create_adjacency_menu(self, widget_menu):
|
||||
"""
|
||||
Create adjacency menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu widget_menu: widget menu
|
||||
:return: nothing
|
||||
"""
|
||||
adjacency_menu = tk.Menu(widget_menu)
|
||||
adjacency_menu.add_command(label="OSPFv2", command=action.sub_menu_items)
|
||||
adjacency_menu.add_command(label="OSPFv3", command=action.sub_menu_items)
|
||||
adjacency_menu.add_command(label="OSLR", command=action.sub_menu_items)
|
||||
adjacency_menu.add_command(label="OSLRv2", command=action.sub_menu_items)
|
||||
|
||||
widget_menu.add_cascade(label="Adjacency", menu=adjacency_menu)
|
||||
|
||||
def create_widgets_menu(self):
|
||||
"""
|
||||
Create widget menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
widget_menu = tk.Menu(self.menubar)
|
||||
self.create_observer_widgets_menu(widget_menu)
|
||||
self.create_adjacency_menu(widget_menu)
|
||||
widget_menu.add_command(label="Throughput", command=action.widgets_throughput)
|
||||
|
||||
widget_menu.add_separator()
|
||||
|
||||
widget_menu.add_command(
|
||||
label="Configure Adjacency...", command=action.widgets_configure_adjacency
|
||||
)
|
||||
widget_menu.add_command(
|
||||
label="Configure Throughput...", command=action.widgets_configure_throughput
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="Widgets", menu=widget_menu, underline=0)
|
||||
|
||||
def create_session_menu(self):
|
||||
"""
|
||||
Create session menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
session_menu = tk.Menu(self.menubar)
|
||||
session_menu.add_command(
|
||||
label="Start", command=action.session_start, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Change sessions...",
|
||||
command=action.session_change_sessions,
|
||||
underline=0,
|
||||
)
|
||||
|
||||
session_menu.add_separator()
|
||||
|
||||
session_menu.add_command(
|
||||
label="Node types...", command=action.session_node_types, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Comments...", command=action.session_comments, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Hooks...", command=action.session_hooks, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Reset node positions",
|
||||
command=action.session_reset_node_positions,
|
||||
underline=0,
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Emulation servers...",
|
||||
command=action.session_emulation_servers,
|
||||
underline=0,
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Options...", command=action.session_options, underline=0
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="Session", menu=session_menu, underline=0)
|
||||
|
||||
def create_help_menu(self):
|
||||
"""
|
||||
Create help menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
help_menu = tk.Menu(self.menubar)
|
||||
help_menu.add_command(
|
||||
label="Core Github (www)", command=action.help_core_github
|
||||
)
|
||||
help_menu.add_command(
|
||||
label="Core Documentation (www)", command=action.help_core_documentation
|
||||
)
|
||||
help_menu.add_command(label="About", command=action.help_about)
|
||||
|
||||
self.menubar.add_cascade(label="Help", menu=help_menu)
|
||||
|
||||
def bind_menubar_shortcut(self):
|
||||
"""
|
||||
Bind hot keys to matching command
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
self.bind_all("<Control-n>", action.file_new_shortcut)
|
||||
self.bind_all("<Control-o>", action.file_open_shortcut)
|
||||
self.bind_all("<Control-s>", action.file_save_shortcut)
|
||||
self.bind_all("<Control-z>", action.edit_undo_shortcut)
|
||||
self.bind_all("<Control-y>", action.edit_redo_shortcut)
|
||||
self.bind_all("<Control-x>", action.edit_cut_shortcut)
|
||||
self.bind_all("<Control-c>", action.edit_copy_shortcut)
|
||||
self.bind_all("<Control-v>", action.edit_paste_shortcut)
|
||||
self.bind_all("<Control-a>", action.edit_select_all_shortcut)
|
||||
self.bind_all("<Control-j>", action.edit_select_adjacent_shortcut)
|
||||
self.bind_all("<Control-f>", action.edit_find_shortcut)
|
||||
self.bind_all("<Prior>", action.canvas_previous_shortcut)
|
||||
self.bind_all("<Next>", action.canvas_next_shortcut)
|
||||
self.bind_all("<Home>", action.canvas_first_shortcut)
|
||||
self.bind_all("<End>", action.canvas_last_shortcut)
|
||||
self.bind_all("<Control-Shift-plus>", action.view_zoom_in_shortcut)
|
||||
self.bind_all("<Control-minus>", action.view_zoom_out_shortcut)
|
||||
|
||||
def create_menu(self):
|
||||
self.master.option_add("*tearOff", tk.FALSE)
|
||||
self.menubar = tk.Menu(self.master)
|
||||
self.create_file_menu()
|
||||
self.create_edit_menu()
|
||||
self.create_canvas_menu()
|
||||
self.create_view_menu()
|
||||
self.create_tools_menu()
|
||||
self.create_widgets_menu()
|
||||
self.create_session_menu()
|
||||
self.create_help_menu()
|
||||
|
||||
core_menu = CoreMenubar(self, self.master, self.menubar)
|
||||
core_menu.create_core_menubar()
|
||||
self.master.config(menu=self.menubar)
|
||||
self.bind_menubar_shortcut()
|
||||
|
||||
# TODO clean up this code
|
||||
def create_network_layer_node(
|
||||
self, edit_frame, radio_value, hub_image, switch_image
|
||||
):
|
||||
|
@ -687,8 +64,72 @@ class Application(tk.Frame):
|
|||
image=switch_image, variable=radio_value, value=8, indicatoron=False
|
||||
)
|
||||
menu_button.pack(side=tk.TOP, pady=1)
|
||||
self.master.update()
|
||||
print(menu_button.winfo_rootx(), menu_button.winfo_rooty())
|
||||
# print(menu_button.winfo_width(), menu_button.winfo_height())
|
||||
# print(self.master.winfo_height())
|
||||
option_frame = tk.Frame(self.master)
|
||||
|
||||
switch_button = tk.Button(option_frame, image=switch_image, width=32, height=32)
|
||||
switch_button.pack(side=tk.LEFT, pady=1)
|
||||
hub_button = tk.Button(option_frame, image=hub_image, width=32, height=32)
|
||||
hub_button.pack(side=tk.LEFT, pady=1)
|
||||
print("Place the button")
|
||||
print(menu_button.winfo_rootx(), menu_button.winfo_rooty())
|
||||
option_frame.place(
|
||||
x=menu_button.winfo_rootx() + 33, y=menu_button.winfo_rooty() - 117
|
||||
)
|
||||
self.update()
|
||||
|
||||
print("option frame: " + str(option_frame.winfo_rooty()))
|
||||
print("option frame x: " + str(option_frame.winfo_rootx()))
|
||||
|
||||
print("frame dimension: " + str(option_frame.winfo_height()))
|
||||
print("button height: " + str(hub_button.winfo_rooty()))
|
||||
|
||||
# TODO switch 177 into the rooty of the selection tool, retrieve image in here
|
||||
def draw_options(self, main_button, radio_value):
|
||||
hub_image = Images.get("hub")
|
||||
switch_image = Images.get("switch")
|
||||
option_frame = tk.Frame(self.master)
|
||||
|
||||
switch_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
image=switch_image,
|
||||
width=32,
|
||||
height=32,
|
||||
variable=radio_value,
|
||||
value=7,
|
||||
indicatoron=False,
|
||||
)
|
||||
switch_button.pack(side=tk.LEFT, pady=1)
|
||||
hub_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
image=hub_image,
|
||||
width=32,
|
||||
height=32,
|
||||
variable=radio_value,
|
||||
value=8,
|
||||
indicatoron=False,
|
||||
)
|
||||
hub_button.pack(side=tk.LEFT, pady=1)
|
||||
self.master.update()
|
||||
option_frame.place(
|
||||
x=main_button.winfo_rootx() + 35 - self.selection_button.winfo_rootx(),
|
||||
y=main_button.winfo_rooty() - self.selection_button.winfo_rooty(),
|
||||
)
|
||||
|
||||
def create_network_layer_node_attempt2(self, edit_frame, radio_value):
|
||||
hub_image = Images.get("hub")
|
||||
main_button = tk.Radiobutton(
|
||||
edit_frame, image=hub_image, width=32, height=32, indicatoron=False
|
||||
)
|
||||
main_button.pack(side=tk.TOP, pady=1)
|
||||
self.draw_options(main_button, radio_value)
|
||||
|
||||
def create_widgets(self):
|
||||
|
||||
"""
|
||||
select_image = Images.get("select")
|
||||
start_image = Images.get("start")
|
||||
link_image = Images.get("link")
|
||||
|
@ -696,11 +137,15 @@ class Application(tk.Frame):
|
|||
hub_image = Images.get("hub")
|
||||
switch_image = Images.get("switch")
|
||||
marker_image = Images.get("marker")
|
||||
"""
|
||||
|
||||
edit_frame = tk.Frame(self)
|
||||
edit_frame.pack(side=tk.LEFT, fill=tk.Y, ipadx=2, ipady=2)
|
||||
core_editbar = CoreToolbar(self.master, edit_frame)
|
||||
core_editbar.create_toolbar()
|
||||
"""
|
||||
radio_value = tk.IntVar()
|
||||
b = tk.Radiobutton(
|
||||
self.selection_button = tk.Radiobutton(
|
||||
edit_frame,
|
||||
indicatoron=False,
|
||||
variable=radio_value,
|
||||
|
@ -709,7 +154,7 @@ class Application(tk.Frame):
|
|||
height=32,
|
||||
image=select_image,
|
||||
)
|
||||
b.pack(side=tk.TOP, pady=1)
|
||||
self.selection_button.pack(side=tk.TOP, pady=1)
|
||||
b = tk.Radiobutton(
|
||||
edit_frame,
|
||||
indicatoron=False,
|
||||
|
@ -763,8 +208,9 @@ class Application(tk.Frame):
|
|||
)
|
||||
b.pack(side=tk.TOP, pady=1)
|
||||
|
||||
self.create_network_layer_node(edit_frame, radio_value, hub_image, switch_image)
|
||||
|
||||
#self.create_network_layer_node(edit_frame, radio_value, hub_image, switch_image)
|
||||
self.create_network_layer_node_attempt2(edit_frame, radio_value)
|
||||
"""
|
||||
self.canvas = CanvasGraph(
|
||||
self, background="#cccccc", scrollregion=(0, 0, 1000, 1000)
|
||||
)
|
||||
|
|
654
coretk/coretk/coremenubar.py
Normal file
654
coretk/coretk/coremenubar.py
Normal file
|
@ -0,0 +1,654 @@
|
|||
import tkinter as tk
|
||||
|
||||
import coretk.menuaction as action
|
||||
|
||||
|
||||
class CoreMenubar(object):
|
||||
"""
|
||||
Core menubar
|
||||
"""
|
||||
|
||||
def __init__(self, application, master, menubar):
|
||||
"""
|
||||
Create a CoreMenubar instance
|
||||
|
||||
:param master:
|
||||
:param tkinter.Menu menubar: menubar object
|
||||
:param coretk.app.Application application: application object
|
||||
"""
|
||||
self.menubar = menubar
|
||||
self.master = master
|
||||
self.application = application
|
||||
|
||||
def create_file_menu(self):
|
||||
"""
|
||||
Create file menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
file_menu = tk.Menu(self.menubar)
|
||||
file_menu.add_command(
|
||||
label="New", command=action.file_new, accelerator="Ctrl+N", underline=0
|
||||
)
|
||||
file_menu.add_command(
|
||||
label="Open...", command=action.file_open, accelerator="Ctrl+O", underline=0
|
||||
)
|
||||
file_menu.add_command(label="Reload", command=action.file_reload, underline=0)
|
||||
file_menu.add_command(
|
||||
label="Save", command=action.file_save, accelerator="Ctrl+S", underline=0
|
||||
)
|
||||
file_menu.add_command(label="Save As XML...", command=action.file_save_as_xml)
|
||||
file_menu.add_command(label="Save As imn...", command=action.file_save_as_imn)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(
|
||||
label="Export Python script...", command=action.file_export_python_script
|
||||
)
|
||||
file_menu.add_command(
|
||||
label="Execute XML or Python script...",
|
||||
command=action.file_execute_xml_or_python_script,
|
||||
)
|
||||
file_menu.add_command(
|
||||
label="Execute Python script with options...",
|
||||
command=action.file_execute_python_script_with_options,
|
||||
)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(
|
||||
label="Open current file in editor...",
|
||||
command=action.file_open_current_file_in_editor,
|
||||
)
|
||||
file_menu.add_command(label="Print...", command=action.file_print, underline=0)
|
||||
file_menu.add_command(
|
||||
label="Save screenshot...", command=action.file_save_screenshot
|
||||
)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(
|
||||
label="/home/ncs/.core/configs/sample1.imn",
|
||||
command=action.file_example_link,
|
||||
)
|
||||
|
||||
file_menu.add_separator()
|
||||
|
||||
file_menu.add_command(label="Quit", command=self.master.quit, underline=0)
|
||||
self.menubar.add_cascade(label="File", menu=file_menu, underline=0)
|
||||
|
||||
def create_edit_menu(self):
|
||||
"""
|
||||
Create edit menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
edit_menu = tk.Menu(self.menubar)
|
||||
edit_menu.add_command(
|
||||
label="Undo", command=action.edit_undo, accelerator="Ctrl+Z", underline=0
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Redo", command=action.edit_redo, accelerator="Ctrl+Y", underline=0
|
||||
)
|
||||
|
||||
edit_menu.add_separator()
|
||||
|
||||
edit_menu.add_command(
|
||||
label="Cut", command=action.edit_cut, accelerator="Ctrl+X", underline=0
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Copy", command=action.edit_copy, accelerator="Ctrl+C", underline=0
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Paste", command=action.edit_paste, accelerator="Ctrl+V", underline=0
|
||||
)
|
||||
|
||||
edit_menu.add_separator()
|
||||
|
||||
edit_menu.add_command(
|
||||
label="Select all", command=action.edit_select_all, accelerator="Ctrl+A"
|
||||
)
|
||||
edit_menu.add_command(
|
||||
label="Select Adjacent",
|
||||
command=action.edit_select_adjacent,
|
||||
accelerator="Ctrl+J",
|
||||
)
|
||||
|
||||
edit_menu.add_separator()
|
||||
|
||||
edit_menu.add_command(
|
||||
label="Find...", command=action.edit_find, accelerator="Ctrl+F", underline=0
|
||||
)
|
||||
edit_menu.add_command(label="Clear marker", command=action.edit_clear_marker)
|
||||
edit_menu.add_command(label="Preferences...", command=action.edit_preferences)
|
||||
|
||||
self.menubar.add_cascade(label="Edit", menu=edit_menu, underline=0)
|
||||
|
||||
def create_canvas_menu(self):
|
||||
"""
|
||||
Create canvas menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
canvas_menu = tk.Menu(self.menubar)
|
||||
canvas_menu.add_command(label="New", command=action.canvas_new)
|
||||
canvas_menu.add_command(label="Manage...", command=action.canvas_manage)
|
||||
canvas_menu.add_command(label="Delete", command=action.canvas_delete)
|
||||
|
||||
canvas_menu.add_separator()
|
||||
|
||||
canvas_menu.add_command(label="Size/scale...", command=action.canvas_size_scale)
|
||||
canvas_menu.add_command(label="Wallpaper...", command=action.canvas_wallpaper)
|
||||
|
||||
canvas_menu.add_separator()
|
||||
|
||||
canvas_menu.add_command(
|
||||
label="Previous", command=action.canvas_previous, accelerator="PgUp"
|
||||
)
|
||||
canvas_menu.add_command(
|
||||
label="Next", command=action.canvas_next, accelerator="PgDown"
|
||||
)
|
||||
canvas_menu.add_command(
|
||||
label="First", command=action.canvas_first, accelerator="Home"
|
||||
)
|
||||
canvas_menu.add_command(
|
||||
label="Last", command=action.canvas_last, accelerator="End"
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="Canvas", menu=canvas_menu, underline=0)
|
||||
|
||||
def create_show_menu(self, view_menu):
|
||||
"""
|
||||
Create the menu items in View/Show
|
||||
|
||||
:param tkinter.Menu view_menu: the view menu
|
||||
:return: nothing
|
||||
"""
|
||||
show_menu = tk.Menu(view_menu)
|
||||
show_menu.add_command(label="All", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="None", command=action.sub_menu_items)
|
||||
show_menu.add_separator()
|
||||
show_menu.add_command(label="Interface Names", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="IPv4 Addresses", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="IPv6 Addresses", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="Node Labels", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="Annotations", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="Grid", command=action.sub_menu_items)
|
||||
show_menu.add_command(label="API Messages", command=action.sub_menu_items)
|
||||
|
||||
view_menu.add_cascade(label="Show", menu=show_menu)
|
||||
|
||||
def create_view_menu(self):
|
||||
"""
|
||||
Create view menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
view_menu = tk.Menu(self.menubar)
|
||||
self.create_show_menu(view_menu)
|
||||
view_menu.add_command(
|
||||
label="Show hidden nodes", command=action.view_show_hidden_nodes
|
||||
)
|
||||
view_menu.add_command(label="Locked", command=action.view_locked)
|
||||
view_menu.add_command(label="3D GUI...", command=action.view_3d_gui)
|
||||
|
||||
view_menu.add_separator()
|
||||
|
||||
view_menu.add_command(
|
||||
label="Zoom in", command=action.view_zoom_in, accelerator="+"
|
||||
)
|
||||
view_menu.add_command(
|
||||
label="Zoom out", command=action.view_zoom_out, accelerator="-"
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="View", menu=view_menu, underline=0)
|
||||
|
||||
def create_experimental_menu(self, tools_menu):
|
||||
"""
|
||||
Create experimental menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu tools_menu: tools menu
|
||||
:return: nothing
|
||||
"""
|
||||
experimental_menu = tk.Menu(tools_menu)
|
||||
experimental_menu.add_command(
|
||||
label="Plugins...", command=action.sub_menu_items, underline=0
|
||||
)
|
||||
experimental_menu.add_command(
|
||||
label="ns2immunes converter...", command=action.sub_menu_items, underline=0
|
||||
)
|
||||
experimental_menu.add_command(
|
||||
label="Topology partitioning...", command=action.sub_menu_items
|
||||
)
|
||||
|
||||
tools_menu.add_cascade(
|
||||
label="Experimental", menu=experimental_menu, underline=0
|
||||
)
|
||||
|
||||
def create_random_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create random menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
random_menu = tk.Menu(topology_generator_menu)
|
||||
# list of number of random nodes to create
|
||||
nums = [1, 5, 10, 15, 20, 30, 40, 50, 75, 100]
|
||||
for i in nums:
|
||||
the_label = "R(" + str(i) + ")"
|
||||
random_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Random", menu=random_menu, underline=0
|
||||
)
|
||||
|
||||
def create_grid_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create grid menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology_generator_menu
|
||||
:return: nothing
|
||||
"""
|
||||
grid_menu = tk.Menu(topology_generator_menu)
|
||||
|
||||
# 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:
|
||||
the_label = "G(" + str(i) + ")"
|
||||
grid_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Grid", menu=grid_menu, underline=0)
|
||||
|
||||
def create_connected_grid_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create connected grid menu items and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
grid_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(1, 11, 1):
|
||||
i_n_menu = tk.Menu(grid_menu)
|
||||
for j in range(1, 11, 1):
|
||||
i_j_label = str(i) + " X " + str(j)
|
||||
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
|
||||
i_n_label = str(i) + " X N"
|
||||
grid_menu.add_cascade(label=i_n_label, menu=i_n_menu)
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Connected Grid", menu=grid_menu, underline=0
|
||||
)
|
||||
|
||||
def create_chain_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create chain menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
chain_menu = tk.Menu(topology_generator_menu)
|
||||
# number of nodes to create
|
||||
nums = list(range(2, 25, 1)) + [32, 64, 128]
|
||||
for i in nums:
|
||||
the_label = "P(" + str(i) + ")"
|
||||
chain_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Chain", menu=chain_menu, underline=0)
|
||||
|
||||
def create_star_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create star menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
star_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(3, 26, 1):
|
||||
the_label = "C(" + str(i) + ")"
|
||||
star_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Star", menu=star_menu, underline=0)
|
||||
|
||||
def create_cycle_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create cycle menu item and the sub items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
cycle_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(3, 25, 1):
|
||||
the_label = "C(" + str(i) + ")"
|
||||
cycle_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Cycle", menu=cycle_menu, underline=0)
|
||||
|
||||
def create_wheel_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create wheel menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
wheel_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(4, 26, 1):
|
||||
the_label = "W(" + str(i) + ")"
|
||||
wheel_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Wheel", menu=wheel_menu, underline=0)
|
||||
|
||||
def create_cube_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create cube menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
cube_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(2, 7, 1):
|
||||
the_label = "Q(" + str(i) + ")"
|
||||
cube_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(label="Cube", menu=cube_menu, underline=0)
|
||||
|
||||
def create_clique_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create clique menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology generator menu
|
||||
:return: nothing
|
||||
"""
|
||||
clique_menu = tk.Menu(topology_generator_menu)
|
||||
for i in range(3, 25, 1):
|
||||
the_label = "K(" + str(i) + ")"
|
||||
clique_menu.add_command(label=the_label, command=action.sub_menu_items)
|
||||
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Clique", menu=clique_menu, underline=0
|
||||
)
|
||||
|
||||
def create_bipartite_menu(self, topology_generator_menu):
|
||||
"""
|
||||
Create bipartite menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu topology_generator_menu: topology_generator_menu
|
||||
:return: nothing
|
||||
"""
|
||||
bipartite_menu = tk.Menu(topology_generator_menu)
|
||||
temp = 24
|
||||
for i in range(1, 13, 1):
|
||||
i_n_menu = tk.Menu(bipartite_menu)
|
||||
for j in range(i, temp, 1):
|
||||
i_j_label = "K(" + str(i) + " X " + str(j) + ")"
|
||||
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
|
||||
i_n_label = "K(" + str(i) + " X N)"
|
||||
bipartite_menu.add_cascade(label=i_n_label, menu=i_n_menu)
|
||||
temp = temp - 1
|
||||
topology_generator_menu.add_cascade(
|
||||
label="Bipartite", menu=bipartite_menu, underline=0
|
||||
)
|
||||
|
||||
def create_topology_generator_menu(self, tools_menu):
|
||||
"""
|
||||
Create topology menu item and its sub menu items
|
||||
|
||||
:param tkinter.Menu tools_menu: tools menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
topology_generator_menu = tk.Menu(tools_menu)
|
||||
|
||||
self.create_random_menu(topology_generator_menu)
|
||||
self.create_grid_menu(topology_generator_menu)
|
||||
self.create_connected_grid_menu(topology_generator_menu)
|
||||
self.create_chain_menu(topology_generator_menu)
|
||||
self.create_star_menu(topology_generator_menu)
|
||||
self.create_cycle_menu(topology_generator_menu)
|
||||
self.create_wheel_menu(topology_generator_menu)
|
||||
self.create_cube_menu(topology_generator_menu)
|
||||
self.create_clique_menu(topology_generator_menu)
|
||||
self.create_bipartite_menu(topology_generator_menu)
|
||||
|
||||
tools_menu.add_cascade(
|
||||
label="Topology generator", menu=topology_generator_menu, underline=0
|
||||
)
|
||||
|
||||
def create_tools_menu(self):
|
||||
"""
|
||||
Create tools menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
tools_menu = tk.Menu(self.menubar)
|
||||
tools_menu.add_command(
|
||||
label="Auto rearrange all",
|
||||
command=action.tools_auto_rearrange_all,
|
||||
underline=0,
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Auto rearrange selected",
|
||||
command=action.tools_auto_rearrange_selected,
|
||||
underline=0,
|
||||
)
|
||||
tools_menu.add_separator()
|
||||
|
||||
tools_menu.add_command(
|
||||
label="Align to grid", command=action.tools_align_to_grid, underline=0
|
||||
)
|
||||
|
||||
tools_menu.add_separator()
|
||||
|
||||
tools_menu.add_command(label="Traffic...", command=action.tools_traffic)
|
||||
tools_menu.add_command(
|
||||
label="IP addresses...", command=action.tools_ip_addresses, underline=0
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="MAC addresses...", command=action.tools_mac_addresses, underline=0
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Build hosts file...",
|
||||
command=action.tools_build_hosts_file,
|
||||
underline=0,
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Renumber nodes...", command=action.tools_renumber_nodes, underline=0
|
||||
)
|
||||
self.create_experimental_menu(tools_menu)
|
||||
self.create_topology_generator_menu(tools_menu)
|
||||
tools_menu.add_command(label="Debugger...", command=action.tools_debugger)
|
||||
|
||||
self.menubar.add_cascade(label="Tools", menu=tools_menu, underline=0)
|
||||
|
||||
def create_observer_widgets_menu(self, widget_menu):
|
||||
"""
|
||||
Create observer widget menu item and create the sub menu items inside
|
||||
|
||||
:param tkinter.Menu widget_menu: widget_menu
|
||||
:return: nothing
|
||||
"""
|
||||
observer_widget_menu = tk.Menu(widget_menu)
|
||||
observer_widget_menu.add_command(label="None", command=action.sub_menu_items)
|
||||
observer_widget_menu.add_command(
|
||||
label="processes", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="ifconfig", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv4 routes", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv6 routes", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="OSPFv2 neighbors", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="OSPFv3 neighbors", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="Listening sockets", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv4 MFC entries", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPv6 MFC entries", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="firewall rules", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="IPsec policies", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="docker logs", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="OSPFv3 MDR level", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(
|
||||
label="PIM neighbors", command=action.sub_menu_items
|
||||
)
|
||||
observer_widget_menu.add_command(label="Edit...", command=action.sub_menu_items)
|
||||
|
||||
widget_menu.add_cascade(label="Observer Widgets", menu=observer_widget_menu)
|
||||
|
||||
def create_adjacency_menu(self, widget_menu):
|
||||
"""
|
||||
Create adjacency menu item and the sub menu items inside
|
||||
|
||||
:param tkinter.Menu widget_menu: widget menu
|
||||
:return: nothing
|
||||
"""
|
||||
adjacency_menu = tk.Menu(widget_menu)
|
||||
adjacency_menu.add_command(label="OSPFv2", command=action.sub_menu_items)
|
||||
adjacency_menu.add_command(label="OSPFv3", command=action.sub_menu_items)
|
||||
adjacency_menu.add_command(label="OSLR", command=action.sub_menu_items)
|
||||
adjacency_menu.add_command(label="OSLRv2", command=action.sub_menu_items)
|
||||
|
||||
widget_menu.add_cascade(label="Adjacency", menu=adjacency_menu)
|
||||
|
||||
def create_widgets_menu(self):
|
||||
"""
|
||||
Create widget menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
widget_menu = tk.Menu(self.menubar)
|
||||
self.create_observer_widgets_menu(widget_menu)
|
||||
self.create_adjacency_menu(widget_menu)
|
||||
widget_menu.add_command(label="Throughput", command=action.widgets_throughput)
|
||||
|
||||
widget_menu.add_separator()
|
||||
|
||||
widget_menu.add_command(
|
||||
label="Configure Adjacency...", command=action.widgets_configure_adjacency
|
||||
)
|
||||
widget_menu.add_command(
|
||||
label="Configure Throughput...", command=action.widgets_configure_throughput
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="Widgets", menu=widget_menu, underline=0)
|
||||
|
||||
def create_session_menu(self):
|
||||
"""
|
||||
Create session menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
session_menu = tk.Menu(self.menubar)
|
||||
session_menu.add_command(
|
||||
label="Start", command=action.session_start, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Change sessions...",
|
||||
command=action.session_change_sessions,
|
||||
underline=0,
|
||||
)
|
||||
|
||||
session_menu.add_separator()
|
||||
|
||||
session_menu.add_command(
|
||||
label="Node types...", command=action.session_node_types, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Comments...", command=action.session_comments, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Hooks...", command=action.session_hooks, underline=0
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Reset node positions",
|
||||
command=action.session_reset_node_positions,
|
||||
underline=0,
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Emulation servers...",
|
||||
command=action.session_emulation_servers,
|
||||
underline=0,
|
||||
)
|
||||
session_menu.add_command(
|
||||
label="Options...", command=action.session_options, underline=0
|
||||
)
|
||||
|
||||
self.menubar.add_cascade(label="Session", menu=session_menu, underline=0)
|
||||
|
||||
def create_help_menu(self):
|
||||
"""
|
||||
Create help menu
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
help_menu = tk.Menu(self.menubar)
|
||||
help_menu.add_command(
|
||||
label="Core Github (www)", command=action.help_core_github
|
||||
)
|
||||
help_menu.add_command(
|
||||
label="Core Documentation (www)", command=action.help_core_documentation
|
||||
)
|
||||
help_menu.add_command(label="About", command=action.help_about)
|
||||
|
||||
self.menubar.add_cascade(label="Help", menu=help_menu)
|
||||
|
||||
def bind_menubar_shortcut(self):
|
||||
"""
|
||||
Bind hot keys to matching command
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
self.application.bind_all("<Control-n>", action.file_new_shortcut)
|
||||
self.application.bind_all("<Control-o>", action.file_open_shortcut)
|
||||
self.application.bind_all("<Control-s>", action.file_save_shortcut)
|
||||
self.application.bind_all("<Control-z>", action.edit_undo_shortcut)
|
||||
self.application.bind_all("<Control-y>", action.edit_redo_shortcut)
|
||||
self.application.bind_all("<Control-x>", action.edit_cut_shortcut)
|
||||
self.application.bind_all("<Control-c>", action.edit_copy_shortcut)
|
||||
self.application.bind_all("<Control-v>", action.edit_paste_shortcut)
|
||||
self.application.bind_all("<Control-a>", action.edit_select_all_shortcut)
|
||||
self.application.bind_all("<Control-j>", action.edit_select_adjacent_shortcut)
|
||||
self.application.bind_all("<Control-f>", action.edit_find_shortcut)
|
||||
self.application.bind_all("<Prior>", action.canvas_previous_shortcut)
|
||||
self.application.bind_all("<Next>", action.canvas_next_shortcut)
|
||||
self.application.bind_all("<Home>", action.canvas_first_shortcut)
|
||||
self.application.bind_all("<End>", action.canvas_last_shortcut)
|
||||
self.application.bind_all("<Control-Shift-plus>", action.view_zoom_in_shortcut)
|
||||
self.application.bind_all("<Control-minus>", action.view_zoom_out_shortcut)
|
||||
|
||||
def create_core_menubar(self):
|
||||
"""
|
||||
Create core menubar and bind the hot keys to their matching command
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
self.create_file_menu()
|
||||
self.create_edit_menu()
|
||||
self.create_canvas_menu()
|
||||
self.create_view_menu()
|
||||
self.create_tools_menu()
|
||||
self.create_widgets_menu()
|
||||
self.create_session_menu()
|
||||
self.create_help_menu()
|
||||
self.bind_menubar_shortcut()
|
421
coretk/coretk/coretoolbar.py
Normal file
421
coretk/coretk/coretoolbar.py
Normal file
|
@ -0,0 +1,421 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
|
||||
from coretk.images import Images
|
||||
|
||||
|
||||
class CoreToolbar(object):
|
||||
"""
|
||||
Core toolbar class
|
||||
"""
|
||||
|
||||
# TODO Temporarily have a radio_value instance here, might have to include the run frame
|
||||
def __init__(self, master, edit_frame):
|
||||
"""
|
||||
Create a CoreToolbar instance
|
||||
|
||||
:param tkinter.Frame edit_frame: edit frame
|
||||
"""
|
||||
self.master = master
|
||||
self.edit_frame = edit_frame
|
||||
self.radio_value = tk.IntVar()
|
||||
|
||||
# Used for drawing the horizontally displayed menu items for network-layer nodes and link-layer node
|
||||
self.selection_tool_button = None
|
||||
# Reference to the option menus
|
||||
self.link_layer_option_menu = None
|
||||
self.marker_option_menu = None
|
||||
self.network_layer_option_menu = None
|
||||
|
||||
def load_toolbar_images(self):
|
||||
"""
|
||||
Load the images that appear in core toolbar
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
Images.load("core", "core-icon.png")
|
||||
Images.load("start", "start.gif")
|
||||
Images.load("switch", "lanswitch.gif")
|
||||
Images.load("marker", "marker.gif")
|
||||
Images.load("router", "router.gif")
|
||||
Images.load("select", "select.gif")
|
||||
Images.load("link", "link.gif")
|
||||
Images.load("hub", "hub.gif")
|
||||
Images.load("wlan", "wlan.gif")
|
||||
Images.load("rj45", "rj45.gif")
|
||||
Images.load("tunnel", "tunnel.gif")
|
||||
Images.load("oval", "oval.gif")
|
||||
Images.load("rectangle", "rectangle.gif")
|
||||
Images.load("text", "text.gif")
|
||||
|
||||
def hide_all_option_menu_frames(self):
|
||||
"""
|
||||
Hide any option menu frame that is displayed on screen so that when a new option menu frame is drawn, only
|
||||
one frame is displayed
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
if self.marker_option_menu:
|
||||
self.marker_option_menu.place_forget()
|
||||
if self.link_layer_option_menu:
|
||||
self.link_layer_option_menu.place_forget()
|
||||
if self.network_layer_option_menu:
|
||||
self.network_layer_option_menu.place_forget()
|
||||
|
||||
def click_selection_tool(self):
|
||||
logging.debug("Click selection tool")
|
||||
|
||||
def create_selection_tool_button(self):
|
||||
"""
|
||||
Create selection tool button
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
selection_tool_image = Images.get("select")
|
||||
self.selection_tool_button = tk.Radiobutton(
|
||||
self.edit_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=1,
|
||||
width=32,
|
||||
height=32,
|
||||
image=selection_tool_image,
|
||||
command=self.click_selection_tool,
|
||||
)
|
||||
self.selection_tool_button.pack(side=tk.TOP, pady=1)
|
||||
|
||||
def create_start_stop_session_button(self):
|
||||
"""
|
||||
Create start stop session button
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
start_image = Images.get("start")
|
||||
start_button = tk.Radiobutton(
|
||||
self.edit_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=2,
|
||||
width=32,
|
||||
height=32,
|
||||
image=start_image,
|
||||
)
|
||||
start_button.pack(side=tk.TOP, pady=1)
|
||||
|
||||
def create_link_tool_button(self):
|
||||
"""
|
||||
Create link tool button
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
link_image = Images.get("link")
|
||||
link_button = tk.Radiobutton(
|
||||
self.edit_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=3,
|
||||
width=32,
|
||||
height=32,
|
||||
image=link_image,
|
||||
)
|
||||
link_button.pack(side=tk.TOP, pady=1)
|
||||
|
||||
def create_network_layer_button(self):
|
||||
"""
|
||||
Create network layer button
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
router_image = Images.get("router")
|
||||
network_layer_button = tk.Radiobutton(
|
||||
self.edit_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=4,
|
||||
width=32,
|
||||
height=32,
|
||||
image=router_image,
|
||||
)
|
||||
network_layer_button.pack(side=tk.TOP, pady=1)
|
||||
|
||||
def pick_hub(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("hub"))
|
||||
if self.radio_value.get() != 5:
|
||||
self.radio_value.set(5)
|
||||
logging.debug("Pick link-layer node HUB")
|
||||
|
||||
def pick_switch(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("switch"))
|
||||
if self.radio_value.get() != 5:
|
||||
self.radio_value.set(5)
|
||||
logging.debug("Pick link-layer node SWITCH")
|
||||
|
||||
def pick_wlan(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("wlan"))
|
||||
if self.radio_value.get() != 5:
|
||||
self.radio_value.set(5)
|
||||
logging.debug("Pick link-layer node WLAN")
|
||||
|
||||
def pick_rj45(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("rj45"))
|
||||
if self.radio_value.get() != 5:
|
||||
self.radio_value.set(5)
|
||||
logging.debug("Pick link-layer node RJ45")
|
||||
|
||||
def pick_tunnel(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("tunnel"))
|
||||
if self.radio_value.get() != 5:
|
||||
self.radio_value.set(5)
|
||||
logging.debug("Pick link-layer node TUNNEL")
|
||||
|
||||
def draw_link_layer_options(self, link_layer_button):
|
||||
# TODO if other buttons are press or nothing is pressed or the button is pressed but frame is forgotten/hidden
|
||||
option_frame = tk.Frame(self.master)
|
||||
current_choice = self.radio_value.get()
|
||||
self.hide_all_option_menu_frames()
|
||||
if (
|
||||
current_choice == 0
|
||||
or current_choice != 5
|
||||
or (current_choice == 5 and not option_frame.winfo_manager())
|
||||
):
|
||||
hub_image = Images.get("hub")
|
||||
switch_image = Images.get("switch")
|
||||
wlan_image = Images.get("wlan")
|
||||
rj45_image = Images.get("rj45")
|
||||
tunnel_image = Images.get("tunnel")
|
||||
|
||||
hub_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=7,
|
||||
width=32,
|
||||
height=32,
|
||||
image=hub_image,
|
||||
command=lambda: self.pick_hub(
|
||||
frame=option_frame, main_button=link_layer_button
|
||||
),
|
||||
)
|
||||
hub_button.pack(side=tk.LEFT, pady=1)
|
||||
switch_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=8,
|
||||
width=32,
|
||||
height=32,
|
||||
image=switch_image,
|
||||
command=lambda: self.pick_switch(
|
||||
frame=option_frame, main_button=link_layer_button
|
||||
),
|
||||
)
|
||||
switch_button.pack(side=tk.LEFT, pady=1)
|
||||
wlan_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=9,
|
||||
width=32,
|
||||
height=32,
|
||||
image=wlan_image,
|
||||
command=lambda: self.pick_wlan(
|
||||
frame=option_frame, main_button=link_layer_button
|
||||
),
|
||||
)
|
||||
wlan_button.pack(side=tk.LEFT, pady=1)
|
||||
rj45_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=10,
|
||||
width=32,
|
||||
height=32,
|
||||
image=rj45_image,
|
||||
command=lambda: self.pick_rj45(
|
||||
frame=option_frame, main_button=link_layer_button
|
||||
),
|
||||
)
|
||||
rj45_button.pack(side=tk.LEFT, pady=1)
|
||||
tunnel_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=11,
|
||||
width=32,
|
||||
height=32,
|
||||
image=tunnel_image,
|
||||
command=lambda: self.pick_tunnel(
|
||||
frame=option_frame, main_button=link_layer_button
|
||||
),
|
||||
)
|
||||
tunnel_button.pack(side=tk.LEFT, pady=1)
|
||||
|
||||
_x = (
|
||||
link_layer_button.winfo_rootx()
|
||||
- self.selection_tool_button.winfo_rootx()
|
||||
+ 33
|
||||
)
|
||||
_y = (
|
||||
link_layer_button.winfo_rooty()
|
||||
- self.selection_tool_button.winfo_rooty()
|
||||
)
|
||||
option_frame.place(x=_x, y=_y)
|
||||
self.link_layer_option_menu = option_frame
|
||||
|
||||
def create_link_layer_button(self):
|
||||
"""
|
||||
Create link-layer node button and the options that represent different link-layer node types
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
hub_image = Images.get("hub")
|
||||
link_layer_button = tk.Radiobutton(
|
||||
self.edit_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=5,
|
||||
width=32,
|
||||
height=32,
|
||||
image=hub_image,
|
||||
command=lambda: self.draw_link_layer_options(link_layer_button),
|
||||
)
|
||||
link_layer_button.pack(side=tk.TOP, pady=1)
|
||||
|
||||
def pick_marker(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("marker"))
|
||||
if self.radio_value.get() != 6:
|
||||
self.radio_value.set(6)
|
||||
logging.debug("Pick marker")
|
||||
|
||||
def pick_oval(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("oval"))
|
||||
if self.radio_value.get() != 6:
|
||||
self.radio_value.set(6)
|
||||
logging.debug("Pick frame")
|
||||
|
||||
def pick_rectangle(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("rectangle"))
|
||||
if self.radio_value.get() != 6:
|
||||
self.radio_value.set(6)
|
||||
logging.debug("Pick rectangle")
|
||||
|
||||
def pick_text(self, frame, main_button):
|
||||
frame.place_forget()
|
||||
main_button.configure(image=Images.get("text"))
|
||||
if self.radio_value.get() != 6:
|
||||
self.radio_value.set(6)
|
||||
logging.debug("Pick text")
|
||||
|
||||
def draw_marker_options(self, main_button):
|
||||
# TODO if no button pressed, or other buttons being pressed, or marker button is being pressed but no frame is drawn
|
||||
option_frame = tk.Frame(self.master)
|
||||
current_choice = self.radio_value.get()
|
||||
self.hide_all_option_menu_frames()
|
||||
# TODO might need to find better way to write this, or might not
|
||||
if (
|
||||
current_choice == 0
|
||||
or current_choice != 6
|
||||
or (current_choice == 6 and not option_frame.winfo_manager())
|
||||
):
|
||||
marker_image = Images.get("marker")
|
||||
oval_image = Images.get("oval")
|
||||
rectangle_image = Images.get("rectangle")
|
||||
text_image = Images.get("text")
|
||||
|
||||
marker_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=12,
|
||||
width=32,
|
||||
height=32,
|
||||
image=marker_image,
|
||||
command=lambda: self.pick_marker(
|
||||
frame=option_frame, main_button=main_button
|
||||
),
|
||||
)
|
||||
marker_button.pack(side=tk.LEFT, pady=1)
|
||||
oval_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=13,
|
||||
width=32,
|
||||
height=32,
|
||||
image=oval_image,
|
||||
command=lambda: self.pick_oval(
|
||||
frame=option_frame, main_button=main_button
|
||||
),
|
||||
)
|
||||
oval_button.pack(side=tk.LEFT, pady=1)
|
||||
rectangle_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=14,
|
||||
width=32,
|
||||
height=32,
|
||||
image=rectangle_image,
|
||||
command=lambda: self.pick_rectangle(
|
||||
frame=option_frame, main_button=main_button
|
||||
),
|
||||
)
|
||||
rectangle_button.pack(side=tk.LEFT, pady=1)
|
||||
text_button = tk.Radiobutton(
|
||||
option_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=15,
|
||||
width=32,
|
||||
height=32,
|
||||
image=text_image,
|
||||
command=lambda: self.pick_text(
|
||||
frame=option_frame, main_button=main_button
|
||||
),
|
||||
)
|
||||
text_button.pack(side=tk.LEFT, pady=1)
|
||||
self.master.update()
|
||||
_x = (
|
||||
main_button.winfo_rootx()
|
||||
- self.selection_tool_button.winfo_rootx()
|
||||
+ 33
|
||||
)
|
||||
_y = main_button.winfo_rooty() - self.selection_tool_button.winfo_rooty()
|
||||
option_frame.place(x=_x, y=_y)
|
||||
self.marker_option_menu = option_frame
|
||||
|
||||
def create_marker_button(self):
|
||||
"""
|
||||
Create marker button and options that represent different marker types
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
marker_image = Images.get("marker")
|
||||
marker_main_button = tk.Radiobutton(
|
||||
self.edit_frame,
|
||||
indicatoron=False,
|
||||
variable=self.radio_value,
|
||||
value=6,
|
||||
width=32,
|
||||
height=32,
|
||||
image=marker_image,
|
||||
command=lambda: self.draw_marker_options(marker_main_button),
|
||||
)
|
||||
marker_main_button.pack(side=tk.TOP, pady=1)
|
||||
|
||||
def create_toolbar(self):
|
||||
self.load_toolbar_images()
|
||||
self.create_selection_tool_button()
|
||||
self.create_start_stop_session_button()
|
||||
self.create_link_tool_button()
|
||||
self.create_network_layer_button()
|
||||
self.create_link_layer_button()
|
||||
self.create_marker_button()
|
BIN
coretk/coretk/oval.gif
Normal file
BIN
coretk/coretk/oval.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 174 B |
BIN
coretk/coretk/rectangle.gif
Normal file
BIN
coretk/coretk/rectangle.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 B |
BIN
coretk/coretk/rj45.gif
Normal file
BIN
coretk/coretk/rj45.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 755 B |
BIN
coretk/coretk/text.gif
Normal file
BIN
coretk/coretk/text.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 127 B |
BIN
coretk/coretk/tunnel.gif
Normal file
BIN
coretk/coretk/tunnel.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 799 B |
BIN
coretk/coretk/wlan.gif
Normal file
BIN
coretk/coretk/wlan.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 146 B |
Loading…
Add table
Reference in a new issue