-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhector.py
127 lines (116 loc) · 5.54 KB
/
hector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import argparse
import ctypes
import platform
import sys
import tkinter as tk
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, PANEL_TEXT_COLOR, TEXT_EDITOR_FRAME_BG
from src.const.values import VERSION
from src.gui.navigator import Navigator
from src.gui.window.main_window import MainWindow
from src.gui.window.project_selector_window import ProjectSelectorWindow
from src.gui.window.splash_window import SplashWindow
from src.utils import Utils
def handle_error(text):
messagebox.showerror('Chyba spúštania!', text)
if __name__ == "__main__":
if platform.system() == 'Windows':
ctypes.windll.shcore.SetProcessDpiAwareness(True)
parser = argparse.ArgumentParser()
parser.add_argument("--github_token", help="Run with this github token for all github calls")
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)
style.configure("panel.TNotebook",
background=PRIMARY_COLOR,
foreground=PRIMARY_COLOR,
bordercolor=ACCENT_2_COLOR,
darkcolor=PRIMARY_COLOR,
lightcolor=PRIMARY_COLOR
)
style.configure("panel.TNotebook.Tab",
background=ACCENT_2_COLOR,
foreground=PANEL_TEXT_COLOR,
bordercolor=ACCENT_2_COLOR, )
style.map(
"panel.TNotebook.Tab",
# "selected" je stav, keď je záložka aktívna
background=[("selected", PRIMARY_COLOR)], # Pozadie aktívnej záložky
foreground=[("selected", PANEL_TEXT_COLOR)], # Text aktívnej záložky
bordercolor=[("selected", ACCENT_2_COLOR)], # Text aktívnej záložky
)
style.configure("panel.Treeview", background=TEXT_EDITOR_FRAME_BG, foreground=PANEL_TEXT_COLOR,
fieldbackground=TEXT_EDITOR_FRAME_BG, bordercolor=ACCENT_2_COLOR, lightcolor=ACCENT_2_COLOR)
photo = tk.PhotoImage(file=Utils.resource_path('images/hector-icon.png'))
root.wm_iconphoto(True, photo)
splash = SplashWindow(root)
splash.update_status("sťahujem a inicializujem jazykový model...")
nlp = NlpService.initialize()
if not nlp:
splash.close()
handle_error("Nepodarilo sa stiahnuť jazykový model. Overte prosím, že máte internetové pripojenie!")
sys.exit(1)
splash.update_status("sťahujem a inicializujem slovník...")
dictionaries = SpellcheckService.initialize(github_token=args.github_token, github_user=args.github_user)
if not nlp:
splash.close()
handle_error("Nepodarilo sa stiahnuť slovníky. Overte prosím, že máte internetové pripojenie!")
sys.exit(1)
splash.update_status("sťahujem pandoc...")
# noinspection PyBroadException
try:
ImportService.ensure_pandoc_available()
except Exception:
splash.close()
handle_error("Nepodarilo sa stiahnuť modul pandoc. Overte prosím, že máte internetové pripojenie!")
sys.exit(1)
if not nlp:
splash.close()
handle_error("Nepodarilo sa stiahnuť jazykový model. Overte prosím, že máte internetové pripojenie!")
sys.exit(1)
splash.update_status("kontrolujem aktualizácie...")
has_available_update = False
build_info = Utils.get_build_info()
if build_info['channel'].lower() == "beta":
has_available_update = Utils.check_updates(VERSION, True,
github_token=args.github_token, github_user=args.github_user)
if build_info['channel'].lower() == "stable":
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()
ctx.nlp = nlp
ctx.spellcheck_dictionary = dictionaries["spellcheck"]
ctx.thesaurus = dictionaries["thesaurus"]
ctx.has_available_update = has_available_update
navigator = Navigator()
navigator.root = root
navigator.windows[Navigator.MAIN_WINDOW] = lambda r: MainWindow(r)
navigator.windows[Navigator.PROJECT_SELECTOR_WINDOW] = lambda r: ProjectSelectorWindow(r)
splash.close()
# 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)
navigator.navigate(Navigator.PROJECT_SELECTOR_WINDOW)
root.mainloop()