Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
v3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
xayam authored Sep 17, 2023
1 parent 5bc5e7a commit 1e057b0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
26 changes: 15 additions & 11 deletions src/model/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Config:

RUS_ORIG = "rus.orig.html"
ENG_ORIG = "eng.orig.html"
RUS_MAP = "rus.map.json"
ENG_MAP = "eng.map.json"
RUS_WAV = "rus.wav"
ENG_WAV = "eng.wav"

BOOK_SCHEME = [
RUS_ANNOT, ENG_ANNOT, RUS_SYNC,
Expand All @@ -51,27 +55,27 @@ def __init__(self, app=None):
self.app = app
self.locale = EN
self.books = []
self.options = {LOCALE: EN,
FG: "black",
BG: "white",
SEL: "yellow",
FONT: "Arial",
FONTSIZE: 20,
POSITIONS: {i: {POSI: "0.0\n0.0\n0.0", AUDIO: EN} for i in self.books}
}
self.option = {LOCALE: EN,
FG: "#000000",
BG: "#ffffff",
SEL: "#c5f150",
FONT: "Arial",
FONTSIZE: 20,
POSITIONS: {i: {POSI: "0.0\n0.0\n0.0", AUDIO: EN} for i in self.books}
}
self.load_options()
self.save_options()
self.set_locale(self.options[LOCALE])
self.set_locale(self.option[LOCALE])

def set_locale(self, locale):
self.locale = locale

def load_options(self):
if os.path.exists(self.OPTIONS_JSON):
with open(self.OPTIONS_JSON, mode="r") as opt:
self.options = json.load(opt)
self.option = json.load(opt)

def save_options(self):
json_string = json.dumps(self.options)
json_string = json.dumps(self.option)
with open(self.OPTIONS_JSON, mode="w") as opt:
opt.write(json_string)
14 changes: 14 additions & 0 deletions src/model/l18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@
"viewing of two books in two languages (Russian and English). "
"The catalog contains several classic books."}

CATALOG_IN_DEV = {RU: "В разработке", EN: "In development"}

OPTIONS_COLOR = {RU: "Цвет", EN: "Color"}
OPTIONS_FONT = {RU: "Шрифт", EN: "Font"}
OPTIONS_COLOR_SELECTION = {RU: "Выбор цвета", EN: "Color selection"}
OPTIONS_COLOR_FG = {RU: "Цвет текста", EN: "Text color"}
OPTIONS_COLOR_BG = {RU: "Цвет фона", EN: "Background color"}
OPTIONS_COLOR_SEL = {RU: "Цвет выделения", EN: "Highlight color"}
OPTIONS_FONT_SELECTION = {RU: "Выбор шрифта", EN: "Font selection"}

SCELETON_DATA_NOT_FOUND = {RU: "Папка '../data' не найдена", EN: "Folder '../data' not found"}
SCELETON_BOOKS_NOT_FOUND = {RU: "Книги в папке '../data' не найдены",
EN: "Books in folder '../data' not found"}

STATUS_AUDIO = {RU: 'Аудио', EN: 'Audio'}
STATUS_POSITION = {RU: 'Позиция', EN: 'Position'}
STATUS_TELEGRAM = {RU: 'Телеграм', EN: 'Telegram'}
4 changes: 2 additions & 2 deletions src/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def pre_load(self):
self.app.book_other = self.app.rus_book

def music_load(self):
if self.app.options[POSITIONS][self.app.current_select][AUDIO] == EN:
if self.app.option[POSITIONS][self.app.current_select][AUDIO] == EN:
pygame.mixer.music.load(self.app.current_dir + self.app.ENG_FLAC)
self.app.annotation_text_area1.after_idle(self.app.annotation_text_area1.focus_set)
self.app.annotation_text_area = self.app.annotation_text_area1
Expand All @@ -63,6 +63,6 @@ def music_load(self):
self.app.book = self.app.rus_book
self.app.statusbar_label1.configure(
text=STATUS_AUDIO[self.app.locale] + ": " +
self.app.options[POSITIONS][self.app.current_select][AUDIO])
self.app.option[POSITIONS][self.app.current_select][AUDIO])
self.app.root.update()
self.app.play()
20 changes: 18 additions & 2 deletions src/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def find_max_path(alist, a=0, b=0, path=None):


def distance(mx, my, a, b):
return abs(b*my + a*mx)/((a*a + b*b)**0.5)
return abs(b * my + a * mx) / ((a * a + b * b) ** 0.5)


def find_max_path_v2(array):
Expand All @@ -191,7 +191,7 @@ def find_max_path_v2(array):
array[i][j] = 0
buffer.sort()
path = []
for x in buffer[0:20*int((len(array)**2 + len(array[0])**2)**0.5)]:
for x in buffer[0:20 * int((len(array) ** 2 + len(array[0]) ** 2) ** 0.5)]:
path.append((x[1], x[2]))
path.sort()
result = []
Expand Down Expand Up @@ -264,3 +264,19 @@ def r_map(data):
pass

return r_start, r_end, r_word


def get_luminance(hex_color):
color = hex_color[1:]
hex_red = int(color[0:2], base=16)
hex_green = int(color[2:4], base=16)
hex_blue = int(color[4:6], base=16)
return hex_red * 0.2126 + hex_green * 0.7152 + hex_blue * 0.0722


def color_contrast(hex_color):
luminance = get_luminance(hex_color=hex_color)
if luminance < 140:
return "white"
else:
return "black"

0 comments on commit 1e057b0

Please sign in to comment.