scale antenna and mobility player buttons
This commit is contained in:
parent
1d911a763f
commit
87c9492d32
9 changed files with 52 additions and 40 deletions
|
@ -47,13 +47,7 @@ class Application(tk.Frame):
|
|||
|
||||
def setup_scaling(self):
|
||||
self.fonts_size = {name: font.nametofont(name)["size"] for name in font.names()}
|
||||
for name in font.names():
|
||||
f = font.nametofont(name)
|
||||
if name in self.fonts_size:
|
||||
if name == "TkSmallCaptionFont":
|
||||
f.config(size=int(self.fonts_size[name] * self.app_scale * 8 / 9))
|
||||
else:
|
||||
f.config(size=int(self.fonts_size[name] * self.app_scale))
|
||||
themes.scale_fonts(self.fonts_size, self.app_scale)
|
||||
self.icon_text_font = font.Font(
|
||||
family="TkIconFont", size=int(12 * self.app_scale)
|
||||
)
|
||||
|
@ -77,8 +71,8 @@ class Application(tk.Frame):
|
|||
def center(self):
|
||||
screen_width = self.master.winfo_screenwidth()
|
||||
screen_height = self.master.winfo_screenheight()
|
||||
x = int((screen_width / 2) - (WIDTH / 2))
|
||||
y = int((screen_height / 2) - (HEIGHT / 2))
|
||||
x = int((screen_width / 2) - (WIDTH * self.app_scale / 2))
|
||||
y = int((screen_height / 2) - (HEIGHT * self.app_scale / 2))
|
||||
self.master.geometry(
|
||||
f"{int(WIDTH * self.app_scale)}x{int(HEIGHT * self.app_scale)}+{x}+{y}"
|
||||
)
|
||||
|
|
|
@ -794,7 +794,7 @@ class CoreClient:
|
|||
image=image,
|
||||
emane=emane,
|
||||
)
|
||||
if NodeUtils.is_custom(model):
|
||||
if NodeUtils.is_custom(node_type, model):
|
||||
services = NodeUtils.get_custom_node_services(self.app.guiconfig, model)
|
||||
node.services[:] = services
|
||||
logging.info(
|
||||
|
|
|
@ -100,17 +100,17 @@ class MobilityPlayerDialog(Dialog):
|
|||
for i in range(3):
|
||||
frame.columnconfigure(i, weight=1)
|
||||
|
||||
image = Images.get(ImageEnum.START, width=ICON_SIZE)
|
||||
image = Images.get(ImageEnum.START, width=int(ICON_SIZE * self.app.app_scale))
|
||||
self.play_button = ttk.Button(frame, image=image, command=self.click_play)
|
||||
self.play_button.image = image
|
||||
self.play_button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
||||
|
||||
image = Images.get(ImageEnum.PAUSE, width=ICON_SIZE)
|
||||
image = Images.get(ImageEnum.PAUSE, width=int(ICON_SIZE * self.app.app_scale))
|
||||
self.pause_button = ttk.Button(frame, image=image, command=self.click_pause)
|
||||
self.pause_button.image = image
|
||||
self.pause_button.grid(row=0, column=1, sticky="ew", padx=PADX)
|
||||
|
||||
image = Images.get(ImageEnum.STOP, width=ICON_SIZE)
|
||||
image = Images.get(ImageEnum.STOP, width=int(ICON_SIZE * self.app.app_scale))
|
||||
self.stop_button = ttk.Button(frame, image=image, command=self.click_stop)
|
||||
self.stop_button.image = image
|
||||
self.stop_button.grid(row=0, column=2, sticky="ew", padx=PADX)
|
||||
|
|
|
@ -38,7 +38,7 @@ class NodeServiceDialog(Dialog):
|
|||
if len(services) == 0:
|
||||
# not custom node type and node's services haven't been modified before
|
||||
if not NodeUtils.is_custom(
|
||||
canvas_node.core_node.model
|
||||
canvas_node.core_node.type, canvas_node.core_node.model
|
||||
) and not self.app.core.service_been_modified(self.node_id):
|
||||
services = set(self.app.core.default_services[model])
|
||||
# services of default type nodes were modified to be empty
|
||||
|
|
|
@ -129,16 +129,9 @@ class PreferencesDialog(Dialog):
|
|||
self.app.icon_text_font.config(size=int(12 * app_scale))
|
||||
self.app.edge_font.config(size=int(8 * app_scale))
|
||||
|
||||
# scale application widow size
|
||||
screen_width = self.app.master.winfo_screenwidth()
|
||||
screen_height = self.app.master.winfo_screenheight()
|
||||
scaled_width = WIDTH * app_scale
|
||||
scaled_height = HEIGHT * app_scale
|
||||
x = int(screen_width / 2 - scaled_width / 2)
|
||||
y = int(screen_height / 2 - scaled_height / 2)
|
||||
self.app.master.geometry(f"{int(scaled_width)}x{int(scaled_height)}+{x}+{y}")
|
||||
# scale application window
|
||||
self.app.center()
|
||||
|
||||
# scale toolbar icons and picker icons
|
||||
# scale toolbar and canvas items
|
||||
self.app.toolbar.scale()
|
||||
|
||||
self.app.canvas.scale_graph()
|
||||
|
|
|
@ -13,6 +13,8 @@ if TYPE_CHECKING:
|
|||
TEXT_DISTANCE = 0.30
|
||||
EDGE_WIDTH = 3
|
||||
EDGE_COLOR = "#ff0000"
|
||||
WIRELESS_WIDTH = 1.5
|
||||
WIRELESS_COLOR = "#009933"
|
||||
|
||||
|
||||
class CanvasWirelessEdge:
|
||||
|
@ -32,8 +34,8 @@ class CanvasWirelessEdge:
|
|||
self.id = self.canvas.create_line(
|
||||
*position,
|
||||
tags=tags.WIRELESS_EDGE,
|
||||
width=1.5 * self.canvas.app.app_scale,
|
||||
fill="#009933",
|
||||
width=WIRELESS_WIDTH * self.canvas.app.app_scale,
|
||||
fill=WIRELESS_COLOR,
|
||||
)
|
||||
|
||||
def delete(self):
|
||||
|
|
|
@ -927,7 +927,9 @@ class CanvasGraph(tk.Canvas):
|
|||
def scale_graph(self):
|
||||
for nid, canvas_node in self.nodes.items():
|
||||
img = None
|
||||
if NodeUtils.is_custom(canvas_node.core_node.model):
|
||||
if NodeUtils.is_custom(
|
||||
canvas_node.core_node.type, canvas_node.core_node.model
|
||||
):
|
||||
for custom_node in self.app.guiconfig["nodes"]:
|
||||
if custom_node["name"] == canvas_node.core_node.model:
|
||||
img = Images.get_custom(
|
||||
|
@ -942,6 +944,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.itemconfig(nid, image=img)
|
||||
canvas_node.image = img
|
||||
canvas_node.scale_text()
|
||||
canvas_node.scale_antennas()
|
||||
|
||||
for edge_id in self.find_withtag(tags.EDGE):
|
||||
self.itemconfig(edge_id, width=int(EDGE_WIDTH * self.app.app_scale))
|
||||
|
|
|
@ -16,7 +16,8 @@ from core.gui.dialogs.wlanconfig import WlanConfigDialog
|
|||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.graph import tags
|
||||
from core.gui.graph.tooltip import CanvasTooltip
|
||||
from core.gui.nodeutils import NodeUtils
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.nodeutils import ANTENNA_SIZE, NodeUtils
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
@ -54,7 +55,8 @@ class CanvasNode:
|
|||
self.edges = set()
|
||||
self.interfaces = []
|
||||
self.wireless_edges = set()
|
||||
self.antennae = []
|
||||
self.antennas = []
|
||||
self.antenna_images = {}
|
||||
self.setup_bindings()
|
||||
|
||||
def setup_bindings(self):
|
||||
|
@ -70,33 +72,37 @@ class CanvasNode:
|
|||
|
||||
def add_antenna(self):
|
||||
x, y = self.canvas.coords(self.id)
|
||||
offset = len(self.antennae) * 8
|
||||
offset = len(self.antennas) * 8 * self.app.app_scale
|
||||
img = Images.get(ImageEnum.ANTENNA, int(ANTENNA_SIZE * self.app.app_scale))
|
||||
antenna_id = self.canvas.create_image(
|
||||
x - 16 + offset,
|
||||
y - 23,
|
||||
y - int(23 * self.app.app_scale),
|
||||
anchor=tk.CENTER,
|
||||
image=NodeUtils.ANTENNA_ICON,
|
||||
image=img,
|
||||
tags=tags.ANTENNA,
|
||||
)
|
||||
self.antennae.append(antenna_id)
|
||||
self.antennas.append(antenna_id)
|
||||
self.antenna_images[antenna_id] = img
|
||||
|
||||
def delete_antenna(self):
|
||||
"""
|
||||
delete one antenna
|
||||
"""
|
||||
logging.debug("Delete an antenna on %s", self.core_node.name)
|
||||
if self.antennae:
|
||||
antenna_id = self.antennae.pop()
|
||||
if self.antennas:
|
||||
antenna_id = self.antennas.pop()
|
||||
self.canvas.delete(antenna_id)
|
||||
self.antenna_images.pop(antenna_id, None)
|
||||
|
||||
def delete_antennas(self):
|
||||
"""
|
||||
delete all antennas
|
||||
"""
|
||||
logging.debug("Remove all antennas for %s", self.core_node.name)
|
||||
for antenna_id in self.antennae:
|
||||
for antenna_id in self.antennas:
|
||||
self.canvas.delete(antenna_id)
|
||||
self.antennae.clear()
|
||||
self.antennas.clear()
|
||||
self.antenna_images.clear()
|
||||
|
||||
def redraw(self):
|
||||
self.canvas.itemconfig(self.id, image=self.image)
|
||||
|
@ -135,7 +141,7 @@ class CanvasNode:
|
|||
self.canvas.move_selection(self.id, x_offset, y_offset)
|
||||
|
||||
# move antennae
|
||||
for antenna_id in self.antennae:
|
||||
for antenna_id in self.antennas:
|
||||
self.canvas.move(antenna_id, x_offset, y_offset)
|
||||
|
||||
# move edges
|
||||
|
@ -299,3 +305,17 @@ class CanvasNode:
|
|||
if core_node.type == core_pb2.NodeType.DEFAULT and core_node.model == "mdr":
|
||||
self.canvas.create_edge(self, self.canvas.nodes[canvas_nid])
|
||||
self.canvas.clear_selection()
|
||||
|
||||
def scale_antennas(self):
|
||||
for i in range(len(self.antennas)):
|
||||
antenna_id = self.antennas[i]
|
||||
image = Images.get(
|
||||
ImageEnum.ANTENNA, int(ANTENNA_SIZE * self.app.app_scale)
|
||||
)
|
||||
self.canvas.itemconfig(antenna_id, image=image)
|
||||
self.antenna_images[antenna_id] = image
|
||||
node_x, node_y = self.canvas.coords(self.id)
|
||||
x, y = self.canvas.coords(antenna_id)
|
||||
dx = node_x - 16 + (i * 8 * self.app.app_scale) - x
|
||||
dy = node_y - int(23 * self.app.app_scale) - y
|
||||
self.canvas.move(antenna_id, dx, dy)
|
||||
|
|
|
@ -123,8 +123,8 @@ class NodeUtils:
|
|||
return image
|
||||
|
||||
@classmethod
|
||||
def is_custom(cls, model: str) -> bool:
|
||||
return model not in cls.NODE_MODELS
|
||||
def is_custom(cls, node_type: NodeType, model: str) -> bool:
|
||||
return node_type == NodeType.DEFAULT and model not in cls.NODE_MODELS
|
||||
|
||||
@classmethod
|
||||
def get_custom_node_services(
|
||||
|
|
Loading…
Reference in a new issue