Skip to content

Commit

Permalink
#46 - Basic startup project manager window
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHlavna committed Jan 9, 2025
1 parent cb90f2d commit b3c2da3
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 25 deletions.
35 changes: 31 additions & 4 deletions hector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import platform
import sys
import tkinter as tk
from tkinter import messagebox
from tkinter import messagebox, ttk

from ttkthemes import ThemedTk

from src.backend.run_context import RunContext
from src.backend.service.import_service import ImportService
from src.backend.service.nlp_service import NlpService
from src.backend.service.spellcheck_service import SpellcheckService
from src.const.colors import ACCENT_COLOR, PRIMARY_COLOR, ACCENT_2_COLOR, GREY
from src.const.values import VERSION
from src.gui.main_window import MainWindow
from src.gui.project_selector_window import ProjectSelectorWindow
from src.gui.splash_window import SplashWindow
from src.utils import Utils

Expand All @@ -30,9 +33,20 @@ def handle_error(text):
parser.add_argument("--github_user", help="Run with this github token for all github calls")

args = parser.parse_args()

root = ThemedTk(theme="clam")
root.title("Hector")
style = ttk.Style(root)
# CUSTOM SCROLLBAR
style.configure("Vertical.TScrollbar", gripcount=0, troughcolor=PRIMARY_COLOR, bordercolor=PRIMARY_COLOR,
background=ACCENT_COLOR, lightcolor=ACCENT_COLOR, darkcolor=ACCENT_2_COLOR)

style.layout('arrowless.Vertical.TScrollbar',
[('Vertical.Scrollbar.trough',
{'children': [('Vertical.Scrollbar.thumb',
{'expand': '1', 'sticky': 'nswe'})],
'sticky': 'ns'})])
style.configure("Grey.TSeparator",
background=ACCENT_2_COLOR)
photo = tk.PhotoImage(file=Utils.resource_path('images/hector-icon.png'))
root.wm_iconphoto(True, photo)
splash = SplashWindow(root)
Expand Down Expand Up @@ -71,6 +85,19 @@ def handle_error(text):
has_available_update = Utils.check_updates(VERSION, False,
github_token=args.github_token, github_user=args.github_user)
splash.update_status("inicializujem textový processor...")
ctx = RunContext()
ctx2 = RunContext()
ctx.nlp = nlp
ctx.spellcheck_dictionary = dictionaries["spellcheck"]
ctx.thesaurus = dictionaries["thesaurus"]
ctx.has_available_update = has_available_update
splash.close()
main_window = MainWindow(root, nlp, dictionaries["spellcheck"], dictionaries["thesaurus"], has_available_update)
main_window.start_main_loop()
# OPEN WINDOW IN MAXIMIZED STATE
# FOR WINDOWS AND MAC OS SET STATE ZOOMED
# FOR LINUX SET ATTRIBUTE ZOOMED
if platform.system() == "Windows" or platform.system() == "Darwin":
root.state("zoomed")
else:
root.attributes('-zoomed', True)
startup_window = ProjectSelectorWindow(root)
startup_window.start_main_loop()
Binary file added images/hector-logo-white-text-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/backend/run_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class RunContext(object):
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(RunContext, cls).__new__(cls)
self = cls.instance
self.nlp = None
self.thesaurus = None
self.spellcheck_dictionary = None
self.has_available_update = None
return cls.instance

18 changes: 17 additions & 1 deletion src/backend/service/metadata_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os
import string

from src.domain.metadata import Metadata
from src.domain.metadata import Metadata, RecentProject
from src.domain.project import Project


class MetadataService:
Expand Down Expand Up @@ -40,3 +41,18 @@ def put_recent_file(metadata: Metadata, file_path: string):
metadata.recent_files.insert(0, file_path)
if len(metadata.recent_files) > 10:
metadata.recent_files.pop()

@staticmethod
def put_recent_project(metadata: Metadata, project: Project, file_path: string):
rp = RecentProject()
rp.path = file_path
rp.name = project.name
# MOVE RECENT FILE TO TOP, OR ADD NEW
MetadataService.remove_recent_project(metadata, file_path)
metadata.recent_projects.insert(0, rp)
if len(metadata.recent_projects) > 10:
metadata.recent_projects.pop()

@staticmethod
def remove_recent_project(metadata: Metadata, file_path: string):
metadata.recent_projects = [p for p in metadata.recent_projects if p.path != file_path]
24 changes: 24 additions & 0 deletions src/backend/service/project_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
import os
import string

from src.domain.config import Config
from src.domain.project import Project


class ProjectService:
# FUNCTION THAT LOADS PROJECT FROM FILE
@staticmethod
def load(path: string):
if os.path.exists(path):
with open(path, 'r') as file:
p = json.load(file)
return Project(p)
else:
return None

# FUNCTION THAT SAVES CONFIG TO FILE
@staticmethod
def save(p: Project, path: string):
with open(path, 'w') as file:
json.dump(p.to_dict(), file, indent=4)
1 change: 1 addition & 0 deletions src/const/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ACCENT_COLOR = "#3B3B3B"
ACCENT_2_COLOR = "#3B3B3B"
LIGHT_WHITE = "#d7e6e1"
GREY = "#B4B4B8"
PANEL_TEXT_COLOR = "#ffffff"
EDITOR_TEXT_COLOR = "#ffffff"
# Highlight Colors
Expand Down
1 change: 1 addition & 0 deletions src/const/font_awesome_icons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FontAwesomeIcons:
file = '\uf15b'
folder = '\uf07b'
floppy_disk = '\uf0c7'
rotate_left = '\uf2ea'
rotate_right = '\uf2f9'
Expand Down
34 changes: 32 additions & 2 deletions src/domain/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,45 @@ def __init__(self, data=None):
if data is None:
data = {}
self.recent_files = data.get('recent_files', [])
self.recent_projects = data.get('recent_projects', [])
self.recent_projects = []
for rp in data.get('recent_projects', []):
self.recent_projects.append(RecentProject(rp))

def to_dict(self):
recent_projects_maps = []
for recent_project in self.recent_projects:
recent_projects_maps.append(recent_project.to_dict())
"""
Exports the current state of the object to a dictionary.
:return: Dictionary containing the current state of the object.
"""
return {
"recent_files": self.recent_files,
"recent_projects": self.recent_projects,
"recent_projects": recent_projects_maps,
}


class RecentProject:
def __init__(self, data=None):
"""
Constructor accepts a dictionary and sets the class attributes.
If a key is not provided in the dictionary, the default value is used.
:param data: Dictionary containing the data to initialize the object. If not provided, default values are used.
"""
if data is None:
data = {}
self.name = data.get('name', [])
self.path = data.get('path', [])

def to_dict(self):
"""
Exports the current state of the object to a dictionary.
:return: Dictionary containing the current state of the object.
"""
return {
"name": self.name,
"path": self.path,
}
18 changes: 1 addition & 17 deletions src/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,13 @@ class MainWindow:
def __init__(self, r, _nlp: spacy, spellcheck_dictionary: Hunspell, thesaurus: PyThes, has_available_update: bool):
self.root = r
r.overrideredirect(False)
style = ttk.Style(self.root)
# CUSTOM SCROLLBAR
style.configure("Vertical.TScrollbar", gripcount=0, troughcolor=PRIMARY_COLOR, bordercolor=PRIMARY_COLOR,
background=ACCENT_COLOR, lightcolor=ACCENT_COLOR, darkcolor=ACCENT_2_COLOR)

style.layout('arrowless.Vertical.TScrollbar',
[('Vertical.Scrollbar.trough',
{'children': [('Vertical.Scrollbar.thumb',
{'expand': '1', 'sticky': 'nswe'})],
'sticky': 'ns'})])

screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
self.root.geometry("800x600")
x = screen_width / 2 - (800 / 2)
y = screen_height / 2 - (600 / 2)
self.root.geometry("+%d+%d" % (x, y))
# OPEN WINDOW IN MAXIMIZED STATE
# FOR WINDOWS AND MAC OS SET STATE ZOOMED
# FOR LINUX SET ATTRIBUTE ZOOMED
if platform.system() == "Windows" or platform.system() == "Darwin":
self.root.state("zoomed")
else:
self.root.attributes('-zoomed', True)
self.nlp = _nlp
self.spellcheck_dictionary = spellcheck_dictionary
self.thesaurus = thesaurus
Expand Down
Loading

0 comments on commit b3c2da3

Please sign in to comment.