2019-09-15 16:00:01 -07:00
|
|
|
import tkinter as tk
|
2019-11-12 17:32:34 -08:00
|
|
|
from tkinter import ttk
|
2019-09-15 16:00:01 -07:00
|
|
|
|
2019-12-19 09:30:21 -08: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-15 16:00:01 -07:00
|
|
|
|
2019-12-11 14:09:50 -08:00
|
|
|
WIDTH = 1000
|
|
|
|
HEIGHT = 800
|
|
|
|
|
2019-09-15 16:00:01 -07:00
|
|
|
|
|
|
|
class Application(tk.Frame):
|
|
|
|
def __init__(self, master=None):
|
|
|
|
super().__init__(master)
|
2019-11-15 23:31:41 -08:00
|
|
|
# load node icons
|
|
|
|
NodeUtils.setup()
|
|
|
|
|
2019-11-14 11:26:20 -08:00
|
|
|
# widgets
|
2019-09-15 16:00:01 -07:00
|
|
|
self.menubar = None
|
2019-11-07 15:58:02 -08:00
|
|
|
self.toolbar = None
|
2019-11-07 21:46:40 -08:00
|
|
|
self.canvas = None
|
|
|
|
self.statusbar = None
|
2019-12-10 09:57:12 -08:00
|
|
|
self.validation = None
|
2019-11-14 11:26:20 -08:00
|
|
|
|
|
|
|
# setup
|
2019-11-21 22:03:07 -08:00
|
|
|
self.guiconfig = appconfig.read()
|
2019-11-14 11:26:20 -08:00
|
|
|
self.style = ttk.Style()
|
|
|
|
self.setup_theme()
|
2019-11-01 13:42:49 -07:00
|
|
|
self.core = CoreClient(self)
|
2019-11-01 10:45:47 -07:00
|
|
|
self.setup_app()
|
2019-11-07 15:58:02 -08:00
|
|
|
self.draw()
|
2019-11-01 13:42:49 -07:00
|
|
|
self.core.set_up()
|
2019-10-01 16:25:26 -07:00
|
|
|
|
2019-11-13 10:45:43 -08:00
|
|
|
def setup_theme(self):
|
|
|
|
themes.load(self.style)
|
2019-12-16 14:30:38 -08:00
|
|
|
self.master.bind_class("Menu", "<<ThemeChanged>>", themes.theme_change_menu)
|
|
|
|
self.master.bind("<<ThemeChanged>>", themes.theme_change)
|
2019-11-21 22:03:07 -08:00
|
|
|
self.style.theme_use(self.guiconfig["preferences"]["theme"])
|
2019-11-13 10:45:43 -08:00
|
|
|
|
2019-09-15 23:45:13 -07:00
|
|
|
def setup_app(self):
|
|
|
|
self.master.title("CORE")
|
2019-11-14 11:26:20 -08:00
|
|
|
self.center()
|
2019-11-01 13:57:41 -07:00
|
|
|
self.master.protocol("WM_DELETE_WINDOW", self.on_closing)
|
2019-11-12 17:32:34 -08:00
|
|
|
image = Images.get(ImageEnum.CORE, 16)
|
2019-09-15 23:45:13 -07:00
|
|
|
self.master.tk.call("wm", "iconphoto", self.master._w, image)
|
|
|
|
self.pack(fill=tk.BOTH, expand=True)
|
2019-12-10 09:57:12 -08:00
|
|
|
self.validation = InputValidation(self)
|
2019-09-15 16:38:12 -07:00
|
|
|
|
2019-11-14 11:26:20 -08:00
|
|
|
def center(self):
|
|
|
|
screen_width = self.master.winfo_screenwidth()
|
|
|
|
screen_height = self.master.winfo_screenheight()
|
2019-12-11 14:09:50 -08:00
|
|
|
x = int((screen_width / 2) - (WIDTH / 2))
|
|
|
|
y = int((screen_height / 2) - (HEIGHT / 2))
|
|
|
|
self.master.geometry(f"{WIDTH}x{HEIGHT}+{x}+{y}")
|
2019-11-14 11:26:20 -08:00
|
|
|
|
2019-11-07 15:58:02 -08:00
|
|
|
def draw(self):
|
2019-09-15 16:00:01 -07:00
|
|
|
self.master.option_add("*tearOff", tk.FALSE)
|
2019-11-07 21:46:40 -08:00
|
|
|
self.menubar = Menubar(self.master, self)
|
2019-11-07 15:58:02 -08:00
|
|
|
self.toolbar = Toolbar(self, self)
|
|
|
|
self.toolbar.pack(side=tk.LEFT, fill=tk.Y, ipadx=2, ipady=2)
|
2019-11-07 21:46:40 -08:00
|
|
|
self.draw_canvas()
|
|
|
|
self.draw_status()
|
2019-09-15 16:00:01 -07:00
|
|
|
|
2019-10-10 17:02:28 -07:00
|
|
|
def draw_canvas(self):
|
2019-11-27 09:54:43 -08:00
|
|
|
width = self.guiconfig["preferences"]["width"]
|
|
|
|
height = self.guiconfig["preferences"]["height"]
|
2019-12-10 14:33:52 -08:00
|
|
|
self.canvas = CanvasGraph(self, self.core, width, height)
|
2019-09-15 16:00:01 -07:00
|
|
|
self.canvas.pack(fill=tk.BOTH, expand=True)
|
2019-11-12 17:32:34 -08:00
|
|
|
scroll_x = ttk.Scrollbar(
|
2019-09-15 16:00:01 -07:00
|
|
|
self.canvas, orient=tk.HORIZONTAL, command=self.canvas.xview
|
|
|
|
)
|
|
|
|
scroll_x.pack(side=tk.BOTTOM, fill=tk.X)
|
2019-11-12 17:32:34 -08:00
|
|
|
scroll_y = ttk.Scrollbar(self.canvas, command=self.canvas.yview)
|
2019-09-15 16:00:01 -07: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-07 21:46:40 -08:00
|
|
|
def draw_status(self):
|
2019-11-22 12:59:22 -08:00
|
|
|
self.statusbar = StatusBar(master=self, app=self)
|
2019-11-07 21:46:40 -08:00
|
|
|
self.statusbar.pack(side=tk.BOTTOM, fill=tk.X)
|
2019-09-15 16:00:01 -07:00
|
|
|
|
2019-10-10 17:02:28 -07:00
|
|
|
def on_closing(self):
|
|
|
|
menu_action = MenuAction(self, self.master)
|
|
|
|
menu_action.on_quit()
|
2019-10-18 16:42:00 -07:00
|
|
|
|
2019-11-11 15:35:48 -08:00
|
|
|
def save_config(self):
|
2019-11-21 22:03:07 -08:00
|
|
|
appconfig.save(self.guiconfig)
|
2019-11-11 15:35:48 -08:00
|
|
|
|
2019-12-09 16:23:09 -08:00
|
|
|
def close(self):
|
|
|
|
self.master.destroy()
|