-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
93 lines (79 loc) · 3.18 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
90
91
92
93
"""
CircuitPython Bundle Manager v2 - a Python program to easily manage
modules on a CircuitPython device!
Copyright (C) 2021 UnsignedArduino
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import logging
import tkinter as tk
from PIL.ImageTk import PhotoImage
from TkZero.Dialog import ask_yes_or_no
from TkZero.MainWindow import MainWindow
from TkZero.Notebook import Notebook
from circuitpython_bundle_manager import CircuitPythonBundleManager
from constants import *
from helpers.create_logger import create_logger
from helpers.resize import make_resizable
from ui.bundle_tab import BundleTab
from ui.drive_tab import DriveTab
from ui.modules_tab import ModulesTab
from ui.other_tab import OtherTab
logger = create_logger(name=__name__, level=logging.DEBUG)
class CircuitPythonBundleManagerGUI(MainWindow):
"""
The GUI for the CircuitPython Bundle Manager v2.
"""
def __init__(self, settings_path: Path):
super().__init__()
self.settings_path = settings_path
logger.debug("Initialize CircuitPythonBundleManager")
self.cpybm = CircuitPythonBundleManager(settings_path)
logger.debug("Creating GUI")
self.create_gui()
self.title = "CircuitPython Bundle Manager v2"
self.load_icon()
self.bind("<Escape>", lambda _: self.on_close_func())
def on_close_func(self):
"""
Asks if we really want to exit then exit if yes
"""
if ask_yes_or_no(self,
title="CircuitPython Bundle Manager v2: Confirm",
message="Are you really sure you want to exit?"):
self.destroy()
def create_gui(self):
"""
Create the widgets.
"""
logger.debug("Creating widgets")
self.create_notebook()
def create_notebook(self):
"""
Create the main notebook.
"""
logger.debug("Creating notebook")
self.notebook = Notebook(self)
self.notebook.grid(row=0, column=0, padx=1, pady=1, sticky=tk.NSEW)
make_resizable(self, 0, 0)
self.notebook.tabs += [BundleTab(self.notebook, self.cpybm),
ModulesTab(self.notebook, self.cpybm),
DriveTab(self.notebook, self.cpybm),
OtherTab(self.notebook, self.cpybm, self.settings_path)]
self.notebook.update_tabs()
def load_icon(self):
"""
Load the icon for the window.
"""
logger.debug(f"Loading icon from {ICON_PATH}")
icon = PhotoImage(file=ICON_PATH)
# self.icon = icon
self.tk.call("wm", "iconphoto", self, "-default", icon)