This commit is contained in:
Huy Pham 2020-01-14 11:06:52 -08:00
parent b9b8e3a5f1
commit 6c8a2526d9
40 changed files with 219 additions and 141 deletions

View file

@ -1,13 +1,16 @@
import logging
import tkinter as tk
from tkinter.font import Font
from typing import Tuple
from typing import TYPE_CHECKING, Any, Tuple
from core.gui import themes
from core.gui.dialogs.linkconfig import LinkConfigurationDialog
from core.gui.graph import tags
from core.gui.nodeutils import NodeUtils
if TYPE_CHECKING:
from core.gui.graph.graph import CanvasGraph
TEXT_DISTANCE = 0.30
EDGE_WIDTH = 3
EDGE_COLOR = "#ff0000"
@ -16,11 +19,11 @@ EDGE_COLOR = "#ff0000"
class CanvasWirelessEdge:
def __init__(
self,
token: Tuple[int, int],
position: Tuple[int, int, int, int],
token: Tuple[Any, ...],
position: Tuple[float, float, float, float],
src: int,
dst: int,
canvas,
canvas: "CanvasGraph",
):
self.token = token
self.src = src
@ -39,10 +42,17 @@ class CanvasEdge:
Canvas edge class
"""
def __init__(self, x1: int, y1: int, x2: int, y2: int, src: int, canvas):
def __init__(
self,
x1: float,
y1: float,
x2: float,
y2: float,
src: int,
canvas: "CanvasGraph",
):
"""
Create an instance of canvas edge object
:param coretk.graph.graph.GraphCanvas canvas: canvas object
"""
self.src = src
self.dst = None
@ -69,7 +79,7 @@ class CanvasEdge:
self.link = link
self.draw_labels()
def get_coordinates(self) -> [int, int, int, int]:
def get_coordinates(self) -> [float, float, float, float]:
x1, y1, x2, y2 = self.canvas.coords(self.id)
v1 = x2 - x1
v2 = y2 - y1

View file

@ -1,6 +1,6 @@
import logging
import tkinter as tk
from typing import List, Optional
from typing import TYPE_CHECKING, List, Optional, Tuple
from PIL import Image, ImageTk
@ -16,12 +16,15 @@ from core.gui.graph.shapeutils import ShapeType, is_draw_shape, is_marker
from core.gui.images import Images
from core.gui.nodeutils import NodeUtils
if TYPE_CHECKING:
from core.gui.coreclient import CoreClient
ZOOM_IN = 1.1
ZOOM_OUT = 0.9
class CanvasGraph(tk.Canvas):
def __init__(self, master, core, width, height):
def __init__(self, master, core: "CoreClient", width: int, height: int):
super().__init__(master, highlightthickness=0, background="#cccccc")
self.app = master
self.core = core
@ -68,7 +71,7 @@ class CanvasGraph(tk.Canvas):
self.draw_canvas()
self.draw_grid()
def draw_canvas(self, dimensions=None):
def draw_canvas(self, dimensions: Optional[Tuple[int, int]] = None):
if self.grid is not None:
self.delete(self.grid)
if not dimensions:
@ -185,9 +188,6 @@ class CanvasGraph(tk.Canvas):
def add_wireless_edge(self, src: CanvasNode, dst: CanvasNode):
"""
add a wireless edge between 2 canvas nodes
:param CanvasNode src: source node
:param CanvasNode dst: destination node
"""
token = tuple(sorted((src.id, dst.id)))
x1, y1 = self.coords(src.id)
@ -319,9 +319,6 @@ class CanvasGraph(tk.Canvas):
def click_release(self, event: tk.Event):
"""
Draw a node or finish drawing an edge according to the current graph mode
:param event: mouse event
:return: nothing
"""
logging.debug("click release")
x, y = self.canvas_xy(event)
@ -760,7 +757,7 @@ class CanvasGraph(tk.Canvas):
self.redraw_canvas((image.width(), image.height()))
self.draw_wallpaper(image)
def redraw_canvas(self, dimensions: Optional[List[int]] = None):
def redraw_canvas(self, dimensions: Tuple[int, int] = None):
logging.info("redrawing canvas to dimensions: %s", dimensions)
# reset scale and move back to original position

View file

@ -253,7 +253,7 @@ class CanvasNode:
dialog = NodeServiceDialog(self.app.master, self.app, self)
dialog.show()
def has_emane_link(self, interface_id: int) -> bool:
def has_emane_link(self, interface_id: int) -> core_pb2.Node:
result = None
for edge in self.edges:
if self.id == edge.src:

View file

@ -1,24 +1,28 @@
import logging
from typing import List, Optional, Union
from typing import TYPE_CHECKING, Dict, List, Union
from core.gui.dialogs.shapemod import ShapeDialog
from core.gui.graph import tags
from core.gui.graph.shapeutils import ShapeType
if TYPE_CHECKING:
from core.gui.app import Application
from core.gui.graph.graph import CanvasGraph
class AnnotationData:
def __init__(
self,
text: Optional[str] = "",
font: Optional[str] = "Arial",
font_size: Optional[int] = 12,
text_color: Optional[str] = "#000000",
fill_color: Optional[str] = "",
border_color: Optional[str] = "#000000",
border_width: Optional[int] = 1,
bold: Optional[bool] = False,
italic: Optional[bool] = False,
underline: Optional[bool] = False,
text: str = "",
font: str = "Arial",
font_size: int = 12,
text_color: str = "#000000",
fill_color: str = "",
border_color: str = "#000000",
border_width: int = 1,
bold: bool = False,
italic: bool = False,
underline: bool = False,
):
self.text = text
self.font = font
@ -33,7 +37,17 @@ class AnnotationData:
class Shape:
def __init__(self, app, canvas, shape_type, x1, y1, x2=None, y2=None, data=None):
def __init__(
self,
app: "Application",
canvas: "CanvasGraph",
shape_type: ShapeType,
x1: float,
y1: float,
x2: float = None,
y2: float = None,
data: AnnotationData = None,
):
self.app = app
self.canvas = canvas
self.shape_type = shape_type
@ -152,7 +166,7 @@ class Shape:
self.canvas.delete(self.id)
self.canvas.delete(self.text_id)
def metadata(self):
def metadata(self) -> Dict[str, Union[str, int, bool]]:
coords = self.canvas.coords(self.id)
# update coords to actual positions
if len(coords) == 4:

View file

@ -1,9 +1,12 @@
import tkinter as tk
from tkinter import ttk
from typing import Optional
from typing import TYPE_CHECKING
from core.gui.themes import Styles
if TYPE_CHECKING:
from core.gui.graph.graph import CanvasGraph
class CanvasTooltip:
"""
@ -20,7 +23,14 @@ class CanvasTooltip:
Alberto Vassena on 2016.12.10.
"""
def __init__(self, canvas, *, pad=(5, 3, 5, 3), waittime=400, wraplength=600):
def __init__(
self,
canvas: "CanvasGraph",
*,
pad=(5, 3, 5, 3),
waittime: int = 400,
wraplength: int = 600
):
# in miliseconds, originally 500
self.waittime = waittime
# in pixels, originally 180
@ -31,10 +41,10 @@ class CanvasTooltip:
self.id = None
self.tw = None
def on_enter(self, event: Optional[tk.Event] = None):
def on_enter(self, event: tk.Event = None):
self.schedule()
def on_leave(self, event: Optional[tk.Event] = None):
def on_leave(self, event: tk.Event = None):
self.unschedule()
self.hide()
@ -48,7 +58,7 @@ class CanvasTooltip:
if id_:
self.canvas.after_cancel(id_)
def show(self, event: Optional[tk.Event] = None):
def show(self, event: tk.Event = None):
def tip_pos_calculator(canvas, label, *, tip_delta=(10, 5), pad=(5, 3, 5, 3)):
c = canvas
s_width, s_height = c.winfo_screenwidth(), c.winfo_screenheight()