type hint
This commit is contained in:
parent
a8a0255624
commit
7bbd6aa353
4 changed files with 74 additions and 52 deletions
|
@ -129,7 +129,7 @@ class CanvasEdge:
|
|||
x, y = self.get_midpoint()
|
||||
self.canvas.coords(self.text_middle, x, y)
|
||||
|
||||
def set_throughput(self, throughput):
|
||||
def set_throughput(self, throughput: float):
|
||||
throughput = 0.001 * throughput
|
||||
value = f"{throughput:.3f} kbps"
|
||||
if self.text_middle is None:
|
||||
|
@ -148,7 +148,7 @@ class CanvasEdge:
|
|||
width = EDGE_WIDTH
|
||||
self.canvas.itemconfig(self.id, fill=color, width=width)
|
||||
|
||||
def complete(self, dst):
|
||||
def complete(self, dst: int):
|
||||
self.dst = dst
|
||||
self.token = tuple(sorted((self.src, self.dst)))
|
||||
x, y = self.canvas.coords(self.dst)
|
||||
|
@ -200,7 +200,7 @@ class CanvasEdge:
|
|||
self.text_middle = None
|
||||
self.canvas.itemconfig(self.id, fill=EDGE_COLOR, width=EDGE_WIDTH)
|
||||
|
||||
def create_context(self, event):
|
||||
def create_context(self, event: tk.Event):
|
||||
logging.debug("create link context")
|
||||
context = tk.Menu(self.canvas)
|
||||
themes.style_menu(context)
|
||||
|
|
|
@ -20,7 +20,7 @@ NODE_TEXT_OFFSET = 5
|
|||
|
||||
|
||||
class CanvasNode:
|
||||
def __init__(self, app, x, y, core_node, image):
|
||||
def __init__(self, app, x: int, y: int, core_node: core_pb2.Node, image):
|
||||
self.app = app
|
||||
self.canvas = app.canvas
|
||||
self.image = image
|
||||
|
@ -95,14 +95,14 @@ class CanvasNode:
|
|||
image_box = self.canvas.bbox(self.id)
|
||||
return image_box[3] + NODE_TEXT_OFFSET
|
||||
|
||||
def move(self, x, y):
|
||||
def move(self, x: int, y: int):
|
||||
x, y = self.canvas.get_scaled_coords(x, y)
|
||||
current_x, current_y = self.canvas.coords(self.id)
|
||||
x_offset = x - current_x
|
||||
y_offset = y - current_y
|
||||
self.motion(x_offset, y_offset, update=False)
|
||||
|
||||
def motion(self, x_offset, y_offset, update=True):
|
||||
def motion(self, x_offset: int, y_offset: int, update: bool = True):
|
||||
original_position = self.canvas.coords(self.id)
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
x, y = self.canvas.coords(self.id)
|
||||
|
@ -144,7 +144,7 @@ class CanvasNode:
|
|||
if self.app.core.is_runtime() and update:
|
||||
self.app.core.edit_node(self.core_node)
|
||||
|
||||
def on_enter(self, event):
|
||||
def on_enter(self, event: tk.Event):
|
||||
if self.app.core.is_runtime() and self.app.core.observer:
|
||||
self.tooltip.text.set("waiting...")
|
||||
self.tooltip.on_enter(event)
|
||||
|
@ -154,16 +154,16 @@ class CanvasNode:
|
|||
except grpc.RpcError as e:
|
||||
show_grpc_error(e)
|
||||
|
||||
def on_leave(self, event):
|
||||
def on_leave(self, event: tk.Event):
|
||||
self.tooltip.on_leave(event)
|
||||
|
||||
def double_click(self, event):
|
||||
def double_click(self, event: tk.Event):
|
||||
if self.app.core.is_runtime():
|
||||
self.canvas.core.launch_terminal(self.core_node.id)
|
||||
else:
|
||||
self.show_config()
|
||||
|
||||
def create_context(self):
|
||||
def create_context(self) -> tk.Menu:
|
||||
is_wlan = self.core_node.type == NodeType.WIRELESS_LAN
|
||||
is_emane = self.core_node.type == NodeType.EMANE
|
||||
context = tk.Menu(self.canvas)
|
||||
|
@ -245,7 +245,7 @@ class CanvasNode:
|
|||
dialog = NodeServiceDialog(self.app.master, self.app, self)
|
||||
dialog.show()
|
||||
|
||||
def has_emane_link(self, interface_id):
|
||||
def has_emane_link(self, interface_id: int) -> bool:
|
||||
result = None
|
||||
for edge in self.edges:
|
||||
if self.id == edge.src:
|
||||
|
|
|
@ -123,7 +123,7 @@ class Shape:
|
|||
font=font,
|
||||
)
|
||||
|
||||
def shape_motion(self, x1, y1):
|
||||
def shape_motion(self, x1: int, y1: int):
|
||||
self.canvas.coords(self.id, self.x1, self.y1, x1, y1)
|
||||
|
||||
def shape_complete(self, x, y):
|
||||
|
@ -135,7 +135,7 @@ class Shape:
|
|||
def disappear(self):
|
||||
self.canvas.delete(self.id)
|
||||
|
||||
def motion(self, x_offset, y_offset):
|
||||
def motion(self, x_offset: int, y_offset: int):
|
||||
original_position = self.canvas.coords(self.id)
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
coords = self.canvas.coords(self.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue