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
|
|
|
|
2021-02-18 21:04:16 -08:00
|
|
|
from core.gui import images
|
|
|
|
from core.gui.images import ImageEnum
|
2019-12-19 09:30:21 -08:00
|
|
|
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-05-04 22:50:59 -07:00
|
|
|
self,
|
|
|
|
app: "Application",
|
|
|
|
title: str,
|
|
|
|
modal: bool = True,
|
|
|
|
master: tk.BaseWidget = None,
|
2020-06-22 11:04:33 -07:00
|
|
|
) -> None:
|
2020-05-04 22:50:59 -07:00
|
|
|
if master is None:
|
|
|
|
master = app
|
2019-11-13 10:45:43 -08:00
|
|
|
super().__init__(master)
|
2019-10-31 14:06:50 -07:00
|
|
|
self.withdraw()
|
2020-06-22 11:04:33 -07:00
|
|
|
self.app: "Application" = app
|
|
|
|
self.modal: bool = modal
|
2019-10-31 23:17:26 -07:00
|
|
|
self.title(title)
|
|
|
|
self.protocol("WM_DELETE_WINDOW", self.destroy)
|
2021-02-18 21:04:16 -08:00
|
|
|
image = images.from_enum(ImageEnum.CORE, width=images.DIALOG_SIZE)
|
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)
|
2020-06-22 11:04:33 -07:00
|
|
|
self.top: ttk.Frame = ttk.Frame(self, padding=DIALOG_PAD)
|
2020-08-02 10:36:14 -07:00
|
|
|
self.top.grid(sticky=tk.NSEW)
|
2019-10-31 14:06:50 -07:00
|
|
|
|
2020-06-22 11:04:33 -07:00
|
|
|
def show(self) -> None:
|
2019-10-31 14:06:50 -07:00
|
|
|
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-06-22 11:04:33 -07:00
|
|
|
def draw_spacer(self, row: int = None) -> None:
|
2019-12-11 14:09:50 -08:00
|
|
|
frame = ttk.Frame(self.top)
|
2020-08-02 10:36:14 -07:00
|
|
|
frame.grid(row=row, sticky=tk.NSEW)
|
2019-12-11 14:09:50 -08:00
|
|
|
frame.rowconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(frame.grid_info()["row"], weight=1)
|