2019-09-16 00:00:01 +01:00
|
|
|
import tkinter as tk
|
2020-02-12 16:35:14 +00:00
|
|
|
from tkinter import font, ttk
|
2019-09-16 00:00:01 +01:00
|
|
|
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui import appconfig, themes
|
|
|
|
from core.gui.coreclient import CoreClient
|
|
|
|
from core.gui.graph.graph import CanvasGraph
|
|
|
|
from core.gui.images import ImageEnum, Images
|
|
|
|
from core.gui.menuaction import MenuAction
|
|
|
|
from core.gui.menubar import Menubar
|
|
|
|
from core.gui.nodeutils import NodeUtils
|
|
|
|
from core.gui.statusbar import StatusBar
|
|
|
|
from core.gui.toolbar import Toolbar
|
|
|
|
from core.gui.validation import InputValidation
|
2019-09-16 00:00:01 +01:00
|
|
|
|
2019-12-11 22:09:50 +00:00
|
|
|
WIDTH = 1000
|
|
|
|
HEIGHT = 800
|
|
|
|
|
2019-09-16 00:00:01 +01:00
|
|
|
|
|
|
|
class Application(tk.Frame):
|
2020-01-15 18:55:29 +00:00
|
|
|
def __init__(self, proxy: bool):
|
2020-01-15 06:15:00 +00:00
|
|
|
super().__init__(master=None)
|
2019-11-16 07:31:41 +00:00
|
|
|
# load node icons
|
|
|
|
NodeUtils.setup()
|
|
|
|
|
2019-11-14 19:26:20 +00:00
|
|
|
# widgets
|
2019-09-16 00:00:01 +01:00
|
|
|
self.menubar = None
|
2019-11-07 23:58:02 +00:00
|
|
|
self.toolbar = None
|
2019-11-08 05:46:40 +00:00
|
|
|
self.canvas = None
|
|
|
|
self.statusbar = None
|
2019-12-10 17:57:12 +00:00
|
|
|
self.validation = None
|
2019-11-14 19:26:20 +00:00
|
|
|
|
2020-02-17 19:10:13 +00:00
|
|
|
# fonts
|
|
|
|
self.fonts_size = None
|
|
|
|
self.icon_text_font = None
|
|
|
|
self.edge_font = None
|
|
|
|
|
2019-11-14 19:26:20 +00:00
|
|
|
# setup
|
2019-11-22 06:03:07 +00:00
|
|
|
self.guiconfig = appconfig.read()
|
2020-02-17 19:10:13 +00:00
|
|
|
self.app_scale = self.guiconfig["scale"]
|
|
|
|
self.setup_scaling()
|
2019-11-14 19:26:20 +00:00
|
|
|
self.style = ttk.Style()
|
|
|
|
self.setup_theme()
|
2020-01-15 06:15:00 +00:00
|
|
|
self.core = CoreClient(self, proxy)
|
2019-11-01 17:45:47 +00:00
|
|
|
self.setup_app()
|
2019-11-07 23:58:02 +00:00
|
|
|
self.draw()
|
2019-11-01 20:42:49 +00:00
|
|
|
self.core.set_up()
|
2019-10-02 00:25:26 +01:00
|
|
|
|
2020-02-17 19:10:13 +00:00
|
|
|
def setup_scaling(self):
|
|
|
|
self.fonts_size = {name: font.nametofont(name)["size"] for name in font.names()}
|
2020-02-17 23:14:52 +00:00
|
|
|
themes.scale_fonts(self.fonts_size, self.app_scale)
|
2020-02-17 19:10:13 +00:00
|
|
|
self.icon_text_font = font.Font(
|
|
|
|
family="TkIconFont", size=int(12 * self.app_scale)
|
|
|
|
)
|
|
|
|
self.edge_font = font.Font(family="TkDefaultFont", size=int(8 * self.app_scale))
|
|
|
|
|
2019-11-13 18:45:43 +00:00
|
|
|
def setup_theme(self):
|
|
|
|
themes.load(self.style)
|
2019-12-16 22:30:38 +00:00
|
|
|
self.master.bind_class("Menu", "<<ThemeChanged>>", themes.theme_change_menu)
|
|
|
|
self.master.bind("<<ThemeChanged>>", themes.theme_change)
|
2019-11-22 06:03:07 +00:00
|
|
|
self.style.theme_use(self.guiconfig["preferences"]["theme"])
|
2019-11-13 18:45:43 +00:00
|
|
|
|
2019-09-16 07:45:13 +01:00
|
|
|
def setup_app(self):
|
|
|
|
self.master.title("CORE")
|
2019-11-14 19:26:20 +00:00
|
|
|
self.center()
|
2019-11-01 20:57:41 +00:00
|
|
|
self.master.protocol("WM_DELETE_WINDOW", self.on_closing)
|
2019-11-13 01:32:34 +00:00
|
|
|
image = Images.get(ImageEnum.CORE, 16)
|
2019-09-16 07:45:13 +01:00
|
|
|
self.master.tk.call("wm", "iconphoto", self.master._w, image)
|
|
|
|
self.pack(fill=tk.BOTH, expand=True)
|
2019-12-10 17:57:12 +00:00
|
|
|
self.validation = InputValidation(self)
|
2019-09-16 00:38:12 +01:00
|
|
|
|
2019-11-14 19:26:20 +00:00
|
|
|
def center(self):
|
|
|
|
screen_width = self.master.winfo_screenwidth()
|
|
|
|
screen_height = self.master.winfo_screenheight()
|
2020-02-17 23:14:52 +00:00
|
|
|
x = int((screen_width / 2) - (WIDTH * self.app_scale / 2))
|
|
|
|
y = int((screen_height / 2) - (HEIGHT * self.app_scale / 2))
|
2020-02-17 19:10:13 +00:00
|
|
|
self.master.geometry(
|
|
|
|
f"{int(WIDTH * self.app_scale)}x{int(HEIGHT * self.app_scale)}+{x}+{y}"
|
|
|
|
)
|
2019-11-14 19:26:20 +00:00
|
|
|
|
2019-11-07 23:58:02 +00:00
|
|
|
def draw(self):
|
2019-09-16 00:00:01 +01:00
|
|
|
self.master.option_add("*tearOff", tk.FALSE)
|
2019-11-08 05:46:40 +00:00
|
|
|
self.menubar = Menubar(self.master, self)
|
2019-11-07 23:58:02 +00:00
|
|
|
self.toolbar = Toolbar(self, self)
|
|
|
|
self.toolbar.pack(side=tk.LEFT, fill=tk.Y, ipadx=2, ipady=2)
|
2019-11-08 05:46:40 +00:00
|
|
|
self.draw_canvas()
|
|
|
|
self.draw_status()
|
2019-09-16 00:00:01 +01:00
|
|
|
|
2019-10-11 01:02:28 +01:00
|
|
|
def draw_canvas(self):
|
2019-11-27 17:54:43 +00:00
|
|
|
width = self.guiconfig["preferences"]["width"]
|
|
|
|
height = self.guiconfig["preferences"]["height"]
|
2019-12-10 22:33:52 +00:00
|
|
|
self.canvas = CanvasGraph(self, self.core, width, height)
|
2019-09-16 00:00:01 +01:00
|
|
|
self.canvas.pack(fill=tk.BOTH, expand=True)
|
2019-11-13 01:32:34 +00:00
|
|
|
scroll_x = ttk.Scrollbar(
|
2019-09-16 00:00:01 +01:00
|
|
|
self.canvas, orient=tk.HORIZONTAL, command=self.canvas.xview
|
|
|
|
)
|
|
|
|
scroll_x.pack(side=tk.BOTTOM, fill=tk.X)
|
2019-11-13 01:32:34 +00:00
|
|
|
scroll_y = ttk.Scrollbar(self.canvas, command=self.canvas.yview)
|
2019-09-16 00:00:01 +01:00
|
|
|
scroll_y.pack(side=tk.RIGHT, fill=tk.Y)
|
|
|
|
self.canvas.configure(xscrollcommand=scroll_x.set)
|
|
|
|
self.canvas.configure(yscrollcommand=scroll_y.set)
|
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def draw_status(self):
|
2019-11-22 20:59:22 +00:00
|
|
|
self.statusbar = StatusBar(master=self, app=self)
|
2019-11-08 05:46:40 +00:00
|
|
|
self.statusbar.pack(side=tk.BOTTOM, fill=tk.X)
|
2019-09-16 00:00:01 +01:00
|
|
|
|
2019-10-11 01:02:28 +01:00
|
|
|
def on_closing(self):
|
|
|
|
menu_action = MenuAction(self, self.master)
|
|
|
|
menu_action.on_quit()
|
2019-10-19 00:42:00 +01:00
|
|
|
|
2019-11-11 23:35:48 +00:00
|
|
|
def save_config(self):
|
2019-11-22 06:03:07 +00:00
|
|
|
appconfig.save(self.guiconfig)
|
2019-11-11 23:35:48 +00:00
|
|
|
|
2019-12-31 00:34:44 +00:00
|
|
|
def joined_session_update(self):
|
|
|
|
self.statusbar.progress_bar.stop()
|
|
|
|
if self.core.is_runtime():
|
|
|
|
self.toolbar.set_runtime()
|
|
|
|
else:
|
|
|
|
self.toolbar.set_design()
|
|
|
|
|
2019-12-10 00:23:09 +00:00
|
|
|
def close(self):
|
|
|
|
self.master.destroy()
|