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
|
2020-06-22 19:04:33 +01:00
|
|
|
from typing import TYPE_CHECKING, Dict, Optional
|
2019-10-31 21:06:50 +00:00
|
|
|
|
2019-12-10 06:50:26 +00:00
|
|
|
import grpc
|
|
|
|
|
2020-08-27 19:02:02 +01:00
|
|
|
from core.api.grpc.wrappers import ConfigOption
|
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
|
|
|
|
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
|
|
|
|
self.config: Dict[str, ConfigOption] = self.get_config()
|
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 get_config(self) -> Dict[str, ConfigOption]:
|
2019-12-10 06:50:26 +00:00
|
|
|
try:
|
2020-07-28 08:03:15 +01:00
|
|
|
session_id = self.app.core.session.id
|
2021-03-26 17:43:45 +00:00
|
|
|
return self.app.core.client.get_session_options(session_id)
|
2019-12-10 06:50:26 +00:00
|
|
|
except grpc.RpcError as e:
|
2020-05-03 20:42:56 +01:00
|
|
|
self.app.show_grpc_exception("Get Session Options Error", e)
|
2020-02-05 23:09:33 +00:00
|
|
|
self.has_error = True
|
2019-12-10 06:50:26 +00:00
|
|
|
self.destroy()
|
|
|
|
|
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)
|
2020-06-23 03:40:42 +01:00
|
|
|
self.config_frame = ConfigFrame(self.top, self.app, self.config, 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()
|
2019-12-10 06:50:26 +00:00
|
|
|
try:
|
2020-07-28 08:03:15 +01:00
|
|
|
session_id = self.app.core.session.id
|
2021-03-26 17:43:45 +00:00
|
|
|
result = self.app.core.client.set_session_options(session_id, config)
|
|
|
|
logging.info("saved session config: %s", result)
|
2019-12-10 06:50:26 +00:00
|
|
|
except grpc.RpcError as e:
|
2020-05-03 20:42:56 +01:00
|
|
|
self.app.show_grpc_exception("Set Session Options Error", e)
|
2019-10-31 21:06:50 +00:00
|
|
|
self.destroy()
|