forked from tanjeffreyz/auto-maple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
89 lines (67 loc) · 2.58 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""User friendly GUI to interact with Auto Maple."""
import config
import tkinter as tk
from tkinter import ttk
import settings
from gui_components import Menu, View, Edit, Settings
class GUI:
RESOLUTIONS = {
'DEFAULT': '800x800',
'Edit': '1400x800'
}
def __init__(self):
config.gui = self
self.root = tk.Tk()
self.root.title('Auto Maple')
icon = tk.PhotoImage(file='assets/icon.png')
self.root.iconphoto(False, icon)
self.root.geometry(GUI.RESOLUTIONS['DEFAULT'])
self.root.resizable(False, False)
# Initialize GUI variables
self.routine_var = tk.StringVar()
# Build the GUI
self.menu = Menu(self.root)
self.root.config(menu=self.menu)
self.navigation = ttk.Notebook(self.root)
self.view = View(self.navigation)
self.edit = Edit(self.navigation)
self.settings = Settings(self.navigation)
self.navigation.pack(expand=True, fill='both')
self.navigation.bind('<<NotebookTabChanged>>', self._resize_window)
def set_routine(self, arr):
self.routine_var.set(arr)
def clear_routine_info(self):
"""
Clears information in various GUI elements regarding the current routine.
Does not clear Listboxes containing routine Components, as that is handled by Routine.
"""
self.view.details.clear_info()
self.view.status.set_routine('')
self.edit.minimap.redraw()
self.edit.routine.commands.clear_contents()
self.edit.routine.commands.update_display()
self.edit.editor.reset()
def _resize_window(self, e):
"""Callback to resize entire Tkinter window every time a new Page is selected."""
nav = e.widget
curr_id = nav.select()
nav.nametowidget(curr_id).focus() # Focus the current Tab
page = nav.tab(curr_id, 'text')
if self.root.state() != 'zoomed':
if page in GUI.RESOLUTIONS:
self.root.geometry(GUI.RESOLUTIONS[page])
else:
self.root.geometry(GUI.RESOLUTIONS['DEFAULT'])
def start(self):
"""Starts the GUI as well as any scheduled functions."""
self.view.minimap.display_minimap()
self._save_layout()
self.root.mainloop()
def _save_layout(self):
"""Periodically saves the current Layout object."""
if config.layout is not None and settings.record_layout:
config.layout.save()
self.root.after(5000, self._save_layout)
if __name__ == '__main__':
gui = GUI()
gui.start()