2019-10-31 21:06:50 +00:00
|
|
|
import logging
|
2020-06-23 03:40:42 +01:00
|
|
|
import tkinter as tk
|
2019-11-12 00:33:51 +00:00
|
|
|
from tkinter import ttk
|
2021-04-23 00:12:33 +01:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2019-10-31 21:06:50 +00:00
|
|
|
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.dialogs.dialog import Dialog
|
|
|
|
from core.gui.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import ConfigFrame
|
2019-10-31 21:06:50 +00:00
|
|
|
|
2021-04-22 05:09:35 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-01-13 23:31:41 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
|
2019-10-31 21:06:50 +00:00
|
|
|
|
|
|
|
class SessionOptionsDialog(Dialog):
|
2020-06-22 19:04:33 +01:00
|
|
|
def __init__(self, app: "Application") -> None:
|
2020-05-05 06:50:59 +01:00
|
|
|
super().__init__(app, "Session Options")
|
2020-06-22 19:04:33 +01:00
|
|
|
self.config_frame: Optional[ConfigFrame] = None
|
|
|
|
self.has_error: bool = False
|
2020-06-23 03:40:42 +01:00
|
|
|
self.enabled: bool = not self.app.core.is_runtime()
|
2020-02-05 23:09:33 +00:00
|
|
|
if not self.has_error:
|
|
|
|
self.draw()
|
2019-10-31 21:06:50 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2019-11-13 18:45:43 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2021-04-23 00:12:33 +01:00
|
|
|
options = self.app.core.session.options
|
|
|
|
self.config_frame = ConfigFrame(self.top, self.app, options, self.enabled)
|
2019-11-06 22:36:36 +00:00
|
|
|
self.config_frame.draw_config()
|
2020-08-02 18:36:14 +01:00
|
|
|
self.config_frame.grid(sticky=tk.NSEW, pady=PADY)
|
2019-11-06 22:36:36 +00:00
|
|
|
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.EW)
|
2019-11-06 22:36:36 +00:00
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2020-06-23 03:40:42 +01:00
|
|
|
state = tk.NORMAL if self.enabled else tk.DISABLED
|
|
|
|
button = ttk.Button(frame, text="Save", command=self.save, state=state)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=0, padx=PADX, sticky=tk.EW)
|
2019-11-12 00:33:51 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=1, sticky=tk.EW)
|
2019-10-31 21:06:50 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def save(self) -> None:
|
2019-11-06 22:36:36 +00:00
|
|
|
config = self.config_frame.parse_config()
|
2021-04-23 00:12:33 +01:00
|
|
|
for key, value in config.items():
|
|
|
|
self.app.core.session.options[key].value = value
|
2019-10-31 21:06:50 +00:00
|
|
|
self.destroy()
|