Skip to content

Commit

Permalink
Merge pull request #4 from tisnik/first-version-of-editor
Browse files Browse the repository at this point in the history
First version of editor
  • Loading branch information
tisnik authored Dec 17, 2024
2 parents 23b4b2d + cf1dd8a commit 913fb80
Show file tree
Hide file tree
Showing 42 changed files with 1,754 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- name: Python version
run: python --version
- name: Mypy install
run: pip install --user mypy pydantic
run: pip install --user mypy pydantic types-PyYAML
- name: Type checks
run: mypy --explicit-package-bases --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs --ignore-missing-imports --disable-error-code attr-defined src/
2 changes: 2 additions & 0 deletions config-editor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export PYTHONDONTWRITEBYTECODE=1
pdm run src/config_editor.py
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ target-version = "py311"
lint.pydocstyle.convention = "google"
line-length = 100


[tool.pylint."MESSAGES CONTROL"]
good-names = ["e"]
disable = ["W1203", "C0103", "C0301", "C0302", "C0415", "E0602", "E0611", "E1101", "R0902", "R0903", "R0913", "R0914", "W0102", "W0212", "W0511", "W0613", "W0621", "W0622", "W0707", "W0718", "W0719", "E0401", "R0801", "R0917"]
49 changes: 49 additions & 0 deletions src/config_editor.py
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()
1 change: 1 addition & 0 deletions src/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Graphical user interface for the Road Core config editor."""
1 change: 1 addition & 0 deletions src/gui/dialogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Implementation of all GUI dialog boxes."""
10 changes: 10 additions & 0 deletions src/gui/dialogs/about_dialog.py
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"
)
41 changes: 41 additions & 0 deletions src/gui/dialogs/auth_dialog.py
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()
70 changes: 70 additions & 0 deletions src/gui/dialogs/cache_dialog.py
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()
41 changes: 41 additions & 0 deletions src/gui/dialogs/check_configuration.py
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()
41 changes: 41 additions & 0 deletions src/gui/dialogs/data_collection_dialog.py
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()
41 changes: 41 additions & 0 deletions src/gui/dialogs/default_model_dialog.py
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()
41 changes: 41 additions & 0 deletions src/gui/dialogs/default_provider_dialog.py
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()
Loading

0 comments on commit 913fb80

Please sign in to comment.