-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tisnik/first-version-of-editor
First version of editor
- Loading branch information
Showing
42 changed files
with
1,754 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export PYTHONDONTWRITEBYTECODE=1 | ||
pdm run src/config_editor.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
"""Configuration editor for Road Core service.""" | ||
|
||
from typing import Optional | ||
|
||
import yaml | ||
|
||
from gui.main_window import MainWindow | ||
|
||
DEFAULT_CONFIGURATION_FILE = "olsconfig.yaml" | ||
|
||
|
||
class ConfigEditor: | ||
"""Class representing instances of configuration editor.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize configuration editor.""" | ||
self.configuration = None | ||
self.filename: Optional[str] = None | ||
|
||
def new_configuration(self) -> None: | ||
"""Create new configuration to be edited.""" | ||
self.configuration = None | ||
|
||
def load_configuration(self, filename: str) -> None: | ||
"""Load configuration from YAML file.""" | ||
with open(filename, encoding="utf-8") as fin: | ||
self.configuration = yaml.safe_load(fin) | ||
self.filename = filename | ||
|
||
def save_configuration_as(self, filename: str) -> None: | ||
"""Store configuration into YAML file.""" | ||
with open(filename, "w", encoding="utf-8") as fout: | ||
yaml.dump(self.configuration, fout) | ||
|
||
def save_configuration(self) -> None: | ||
"""Store configuration into YAML file.""" | ||
if self.filename is None: | ||
return | ||
with open(self.filename, "w", encoding="utf-8") as fout: | ||
yaml.dump(self.configuration, fout) | ||
|
||
def check_configuration(self) -> None: | ||
"""Check if configuration is correct one.""" | ||
|
||
|
||
config_editor = ConfigEditor() | ||
config_editor.load_configuration(DEFAULT_CONFIGURATION_FILE) | ||
|
||
main_window = MainWindow(config_editor) | ||
main_window.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Graphical user interface for the Road Core config editor.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Implementation of all GUI dialog boxes.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Implementation of simple 'About' dialog.""" | ||
|
||
from tkinter import messagebox | ||
|
||
|
||
def about() -> None: | ||
"""Show 'about' dialog.""" | ||
messagebox.showinfo( | ||
"Config editor", "Configuration editor for the Road Core service" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Auth dialog.""" | ||
|
||
import tkinter | ||
|
||
from gui.icons import Icons | ||
|
||
|
||
class AuthDialog(tkinter.Toplevel): | ||
"""Dialog for editing authentication configuration.""" | ||
|
||
def __init__(self, parent: tkinter.Toplevel, icons: Icons) -> None: | ||
"""Initialize authentication configuration dialog.""" | ||
tkinter.Toplevel.__init__(self, parent) | ||
self.title("Authentication configuration") | ||
self.icons = icons | ||
self.parent = parent | ||
|
||
# don't display the dialog in list of opened windows | ||
self.transient(parent) | ||
|
||
# close the dialog on 'x' click | ||
self.protocol("WM_DELETE_WINDOW", self.destroy) | ||
|
||
# get the focus | ||
self.grab_set() | ||
|
||
ok_button = tkinter.Button( | ||
self, | ||
text="OK", | ||
command=self.ok, | ||
compound="left", | ||
image=self.icons.checkbox_icon, | ||
width=200, | ||
) | ||
ok_button.grid(row=2, column=1, sticky="W", padx=10, pady=10) | ||
# get the focus | ||
ok_button.focus_set() | ||
|
||
def ok(self) -> None: | ||
"""Handle Ok button press.""" | ||
self.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Conversation cache dialog.""" | ||
|
||
import tkinter | ||
from tkinter import ttk | ||
|
||
from gui.icons import Icons | ||
|
||
|
||
class ConversationCacheDialog(tkinter.Toplevel): | ||
"""Dialog for editing conversation settings.""" | ||
|
||
def __init__(self, parent: tkinter.Toplevel, icons: Icons) -> None: | ||
"""Initialize dialog for editing conversation settings.""" | ||
tkinter.Toplevel.__init__(self, parent) | ||
self.title("Conversation cache") | ||
self.icons = icons | ||
self.parent = parent | ||
|
||
# don't display the dialog in list of opened windows | ||
self.transient(parent) | ||
|
||
# close the dialog on 'x' click | ||
self.protocol("WM_DELETE_WINDOW", self.destroy) | ||
|
||
# get the focus | ||
self.grab_set() | ||
|
||
# UI groups | ||
self.uigroup = tkinter.LabelFrame( | ||
self, text="Conversation cache", padx=5, pady=8 | ||
) | ||
|
||
label1 = tkinter.Label(self.uigroup, text="Type") | ||
|
||
label1.grid(row=1, column=1, sticky="W", padx=5, pady=5) | ||
|
||
cache_types = ("In-memory", "PostgreSQL", "Redis") | ||
|
||
cache_type = tkinter.StringVar(self.uigroup, cache_types[0], "cache_type") | ||
print(cache_type) | ||
|
||
cb1 = ttk.Combobox( | ||
self.uigroup, | ||
values=cache_types, | ||
# textvariable=app_log_levels, | ||
state="readonly", | ||
) | ||
cb1.current(0) | ||
cb1.grid(row=1, column=2, sticky="W", padx=5, pady=5) | ||
|
||
ok_button = tkinter.Button( | ||
self, | ||
text="OK", | ||
command=self.ok, | ||
compound="left", | ||
image=self.icons.checkbox_icon, | ||
width=200, | ||
) | ||
|
||
# UI groups placement | ||
self.uigroup.grid(row=1, column=1, sticky="NSWE", padx=5, pady=5) | ||
|
||
ok_button.grid(row=2, column=1, sticky="W", padx=10, pady=10) | ||
|
||
# get the focus | ||
ok_button.focus_set() | ||
|
||
def ok(self) -> None: | ||
"""Handle Ok button press.""" | ||
self.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Check configuration dialog.""" | ||
|
||
import tkinter | ||
|
||
from gui.icons import Icons | ||
|
||
|
||
class CheckConfigurationDialog(tkinter.Toplevel): | ||
"""Dialog for checking the configuration.""" | ||
|
||
def __init__(self, parent: tkinter.Toplevel, icons: Icons) -> None: | ||
"""Initialize dialog for checking the configuration.""" | ||
tkinter.Toplevel.__init__(self, parent) | ||
self.title("Check configuration") | ||
self.icons = icons | ||
self.parent = parent | ||
|
||
# don't display the dialog in list of opened windows | ||
self.transient(parent) | ||
|
||
# close the dialog on 'x' click | ||
self.protocol("WM_DELETE_WINDOW", self.destroy) | ||
|
||
# get the focus | ||
self.grab_set() | ||
|
||
ok_button = tkinter.Button( | ||
self, | ||
text="OK", | ||
command=self.ok, | ||
compound="left", | ||
image=self.icons.checkbox_icon, | ||
width=200, | ||
) | ||
ok_button.grid(row=2, column=1, sticky="W", padx=10, pady=10) | ||
# get the focus | ||
ok_button.focus_set() | ||
|
||
def ok(self) -> None: | ||
"""Handle Ok button press.""" | ||
self.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Data collection dialog.""" | ||
|
||
import tkinter | ||
|
||
from gui.icons import Icons | ||
|
||
|
||
class DataCollectionDialog(tkinter.Toplevel): | ||
"""Data collection dialog.""" | ||
|
||
def __init__(self, parent: tkinter.Toplevel, icons: Icons) -> None: | ||
"""Initialize data collection dialog.""" | ||
tkinter.Toplevel.__init__(self, parent) | ||
self.title("Data collection settings") | ||
self.icons = icons | ||
self.parent = parent | ||
|
||
# don't display the dialog in list of opened windows | ||
self.transient(parent) | ||
|
||
# close the dialog on 'x' click | ||
self.protocol("WM_DELETE_WINDOW", self.destroy) | ||
|
||
# get the focus | ||
self.grab_set() | ||
|
||
ok_button = tkinter.Button( | ||
self, | ||
text="OK", | ||
command=self.ok, | ||
compound="left", | ||
image=self.icons.checkbox_icon, | ||
width=200, | ||
) | ||
ok_button.grid(row=2, column=1, sticky="W", padx=10, pady=10) | ||
# get the focus | ||
ok_button.focus_set() | ||
|
||
def ok(self) -> None: | ||
"""Handle Ok button press.""" | ||
self.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Default model selection dialog.""" | ||
|
||
import tkinter | ||
|
||
from gui.icons import Icons | ||
|
||
|
||
class DefaultModelSelection(tkinter.Toplevel): | ||
"""Default model selection dialog.""" | ||
|
||
def __init__(self, parent: tkinter.Toplevel, icons: Icons) -> None: | ||
"""Initialize default model selection dialog.""" | ||
tkinter.Toplevel.__init__(self, parent) | ||
self.title("Default model selection") | ||
self.icons = icons | ||
self.parent = parent | ||
|
||
# don't display the dialog in list of opened windows | ||
self.transient(parent) | ||
|
||
# close the dialog on 'x' click | ||
self.protocol("WM_DELETE_WINDOW", self.destroy) | ||
|
||
# get the focus | ||
self.grab_set() | ||
|
||
ok_button = tkinter.Button( | ||
self, | ||
text="OK", | ||
command=self.ok, | ||
compound="left", | ||
image=self.icons.checkbox_icon, | ||
width=200, | ||
) | ||
ok_button.grid(row=2, column=1, sticky="W", padx=10, pady=10) | ||
# get the focus | ||
ok_button.focus_set() | ||
|
||
def ok(self) -> None: | ||
"""Handle Ok button press.""" | ||
self.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Default provider selection dialog.""" | ||
|
||
import tkinter | ||
|
||
from gui.icons import Icons | ||
|
||
|
||
class DefaultProviderSelection(tkinter.Toplevel): | ||
"""Default provider selection dialog.""" | ||
|
||
def __init__(self, parent: tkinter.Toplevel, icons: Icons) -> None: | ||
"""Initialize default provider selection dialog.""" | ||
tkinter.Toplevel.__init__(self, parent) | ||
self.title("Default provider selection") | ||
self.icons = icons | ||
self.parent = parent | ||
|
||
# don't display the dialog in list of opened windows | ||
self.transient(parent) | ||
|
||
# close the dialog on 'x' click | ||
self.protocol("WM_DELETE_WINDOW", self.destroy) | ||
|
||
# get the focus | ||
self.grab_set() | ||
|
||
ok_button = tkinter.Button( | ||
self, | ||
text="OK", | ||
command=self.ok, | ||
compound="left", | ||
image=self.icons.checkbox_icon, | ||
width=200, | ||
) | ||
ok_button.grid(row=2, column=1, sticky="W", padx=10, pady=10) | ||
# get the focus | ||
ok_button.focus_set() | ||
|
||
def ok(self) -> None: | ||
"""Handle Ok button press.""" | ||
self.destroy() |
Oops, something went wrong.