2019-10-31 14:06:50 -07:00
|
|
|
import tkinter as tk
|
2019-11-13 10:45:43 -08:00
|
|
|
from tkinter import ttk
|
2020-01-15 12:59:54 -08:00
|
|
|
from typing import TYPE_CHECKING
|
2019-10-31 14:06:50 -07:00
|
|
|
|
2019-12-19 09:30:21 -08:00
|
|
|
from core.gui.images import ImageEnum, Images
|
|
|
|
from core.gui.themes import DIALOG_PAD
|
2019-11-12 12:47:29 -08:00
|
|
|
|
2020-01-13 15:31:41 -08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
|
2019-10-31 14:06:50 -07:00
|
|
|
|
|
|
|
class Dialog(tk.Toplevel):
|
2020-01-13 15:31:41 -08:00
|
|
|
def __init__(
|
2020-01-15 12:59:54 -08:00
|
|
|
self, master: tk.Widget, app: "Application", title: str, modal: bool = False
|
2020-01-13 15:31:41 -08:00
|
|
|
):
|
2019-11-13 10:45:43 -08:00
|
|
|
super().__init__(master)
|
2019-10-31 14:06:50 -07:00
|
|
|
self.withdraw()
|
2019-10-31 23:17:26 -07:00
|
|
|
self.app = app
|
2019-10-31 14:06:50 -07:00
|
|
|
self.modal = modal
|
2019-10-31 23:17:26 -07:00
|
|
|
self.title(title)
|
|
|
|
self.protocol("WM_DELETE_WINDOW", self.destroy)
|
2019-11-12 17:32:34 -08:00
|
|
|
image = Images.get(ImageEnum.CORE, 16)
|
2019-10-31 23:17:26 -07:00
|
|
|
self.tk.call("wm", "iconphoto", self._w, image)
|
2019-11-13 10:45:43 -08:00
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
self.rowconfigure(0, weight=1)
|
|
|
|
self.top = ttk.Frame(self, padding=DIALOG_PAD)
|
|
|
|
self.top.grid(sticky="nsew")
|
2019-10-31 14:06:50 -07:00
|
|
|
|
|
|
|
def show(self):
|
|
|
|
self.transient(self.master)
|
|
|
|
self.focus_force()
|
|
|
|
self.update()
|
|
|
|
self.deiconify()
|
2019-11-02 23:47:43 -07:00
|
|
|
if self.modal:
|
|
|
|
self.wait_visibility()
|
|
|
|
self.grab_set()
|
2019-11-26 11:32:48 -08:00
|
|
|
self.wait_window()
|
2019-12-11 14:09:50 -08:00
|
|
|
|
2020-01-15 12:59:54 -08:00
|
|
|
def draw_spacer(self, row: int = None):
|
2019-12-11 14:09:50 -08:00
|
|
|
frame = ttk.Frame(self.top)
|
|
|
|
frame.grid(row=row, sticky="nsew")
|
|
|
|
frame.rowconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(frame.grid_info()["row"], weight=1)
|