diff --git a/src/view/catalog.py b/src/view/catalog.py index 5dc67d2..1d634f1 100644 --- a/src/view/catalog.py +++ b/src/view/catalog.py @@ -20,7 +20,7 @@ def __init__(self, app): self.show_catalog() def _create_catalog(self): - self.label_catalog = tk.Label(self.catalog, text="В разработке") + self.label_catalog = tk.Label(self.catalog, text=CATALOG_IN_DEV[self.app.locale]) self.label_catalog.pack(fill=tk.BOTH, expand=True) def show_catalog(self): diff --git a/src/view/options.py b/src/view/options.py index 1b2b0c6..c30a4b3 100644 --- a/src/view/options.py +++ b/src/view/options.py @@ -1,11 +1,14 @@ import os import tkinter as tk -from model.l18n import * -# from tkinter import ttk +from tkinter import ttk, font +from tkinter.colorchooser import askcolor # from tkinter import scrolledtext # from tkinter import font # from PIL import ImageTk, Image +from model.l18n import * +from model.utils import * + class Options: @@ -19,10 +22,170 @@ def __init__(self, app): self._create_options() self.show_options() - def _create_options(self): - self.label_options = tk.Label(self.options, text="В разработке") - self.label_options.pack(fill=tk.BOTH, expand=True) - def show_options(self): self.options.grab_set() self.options.mainloop() + + def options_color_click(self, entry, button): + result = askcolor(title=OPTIONS_COLOR_SELECTION[self.app.locale]) + if not (result[1] is None): + entry.delete(0, tk.END) + entry.insert(0, str(result[1])) + button["bg"] = str(result[1]) + button["fg"] = color_contrast(str(result[1])), + + def options_font_click(self, event): + w = event.widget + try: + index = int(w.curselection()[0]) + value = w.get(index) + self.options_font_variable.set(value) + except IndexError: + pass + self.options_font_absde["font"] = (self.options_font_entry.get(), int(self.options_fontsize_entry.get())) + + def options_fontsizes_click(self, event): + w = event.widget + try: + index = int(w.curselection()[0]) + value = w.get(index) + self.options_fontsize_variable.set(value) + except IndexError: + pass + self.options_font_absde["font"] = (self.options_font_entry.get(), int(self.options_fontsize_entry.get())) + + def options_button_save_click(self): + self.app.option[FG] = self.options_fg_entry.get() + self.app.option[BG] = self.options_bg_entry.get() + self.app.option[SEL] = self.options_sel_entry.get() + self.app.option[FONT] = self.options_font_entry.get() + try: + self.app.option[FONTSIZE] = int(self.options_fontsize_entry.get()) + except ValueError: + self.app.option[FONTSIZE] = 20 + self.options_fontsize_entry.delete(0, tk.END) + self.options_fontsize_entry.insert(0, str(self.app.option[FONTSIZE])) + self.app.save_options() + if not (self.app.annotation_text_area1 is None): + self.app.annotation_text_area1[FG] = self.app.option[FG] + self.app.annotation_text_area1[BG] = self.app.option[BG] + self.app.annotation_text_area1[FONT] = (self.app.option[FONT], self.app.option[FONTSIZE]) + if not (self.app.annotation_text_area2 is None): + self.app.annotation_text_area2[FG] = self.app.option[FG] + self.app.annotation_text_area2[BG] = self.app.option[BG] + self.app.annotation_text_area2[FONT] = (self.app.option[FONT], self.app.option[FONTSIZE]) + self.options.destroy() + + def _create_options(self): + self.options_tabs = ttk.Notebook(self.options) + self.options_tabs.pack(fill=tk.BOTH, expand=True, pady=5) + self.options_tab_color = tk.Frame(self.options_tabs) + self.options_tab_color.pack(fill=tk.BOTH, expand=True) + self.options_tab_font1 = tk.Frame(self.options_tabs) + self.options_tab_font1.pack(fill=tk.BOTH, expand=True) + self.options_tabs.add(self.options_tab_color, text=OPTIONS_COLOR[self.app.locale]) + self.options_tabs.add(self.options_tab_font1, text=OPTIONS_FONT[self.app.locale]) + + self.options_frame_result = tk.Frame(self.options, padx=10, pady=10) + self.options_frame_result.pack(fill=tk.X, expand=True) + self.options_button_save = tk.Button(self.options, text="Сохранить", padx=5, + command=self.options_button_save_click) + self.options_button_save.pack(side=tk.RIGHT, padx=10, pady=10) + + self.options_fg_label = tk.Label(self.options_tab_color, text=OPTIONS_COLOR_FG[self.app.locale]) + self.options_fg_label.grid(row=0, column=0, sticky=tk.W, padx=5, pady=5) + self.options_fg_entry = tk.Entry(self.options_tab_color) + self.options_fg_entry.grid(row=0, column=1, sticky=tk.W, padx=5, pady=5) + self.options_fg_entry.insert(0, self.app.option[FG]) + self.options_fg_button = tk.Button(self.options_tab_color, text="...", padx=10, + bg=self.app.option[FG], + fg=color_contrast(self.app.option[FG]), + command=lambda: self.options_color_click(self.options_fg_entry, + self.options_fg_button)) + self.options_fg_button.grid(row=0, column=2, sticky=tk.W) + + self.options_bg_label = tk.Label(self.options_tab_color, text=OPTIONS_COLOR_BG[self.app.locale]) + self.options_bg_label.grid(row=1, column=0, sticky=tk.W, padx=5, pady=5) + self.options_bg_entry = tk.Entry(self.options_tab_color) + self.options_bg_entry.grid(row=1, column=1, sticky=tk.W, padx=5, pady=5) + self.options_bg_entry.insert(0, self.app.option[BG]) + self.options_bg_button = tk.Button(self.options_tab_color, text="...", padx=10, + bg=self.app.option[BG], + fg=color_contrast(self.app.option[BG]), + command=lambda: self.options_color_click(self.options_bg_entry, + self.options_bg_button)) + self.options_bg_button.grid(row=1, column=2, sticky=tk.W) + + self.options_sel_label = tk.Label(self.options_tab_color, text=OPTIONS_COLOR_SEL[self.app.locale]) + self.options_sel_label.grid(row=2, column=0, sticky=tk.W, padx=5, pady=5) + self.options_sel_entry = tk.Entry(self.options_tab_color) + self.options_sel_entry.grid(row=2, column=1, sticky=tk.W, padx=5, pady=5) + self.options_sel_entry.insert(0, self.app.option[SEL]) + self.options_sel_button = tk.Button(self.options_tab_color, text="...", padx=10, + bg=self.app.option[SEL], + fg=color_contrast(self.app.option[SEL]), + command=lambda: self.options_color_click(self.options_sel_entry, + self.options_sel_button)) + self.options_sel_button.grid(row=2, column=2, sticky=tk.W) + + self.options_tab_font = tk.Frame(self.options_tab_font1) + self.options_tab_font.pack(fill=tk.BOTH, expand=True, padx=5, pady=5) + + self.options_font_absde = tk.Label(self.options_tab_font1, text="Abcde Абвгде", height=1, + font=(self.app.option[FONT], self.app.option[FONTSIZE])) + self.options_font_absde.pack(fill=tk.X, expand=True, padx=5, pady=5) + + self.options_font_variable = tk.StringVar() + self.options_font_variable.set(self.app.option[FONT]) + self.options_font_entry = tk.Entry(self.options_tab_font, + textvariable=self.options_font_variable, + state="disabled") + self.options_font_entry.grid(row=0, column=0, sticky=tk.NSEW, padx=5, pady=5) + + self.options_fontsize_variable = tk.StringVar() + self.options_fontsize_variable.set(self.app.option[FONTSIZE]) + self.options_fontsize_entry = tk.Entry(self.options_tab_font, + textvariable=self.options_fontsize_variable, + state="disabled") + self.options_fontsize_entry.grid(row=0, column=1, sticky=tk.NSEW, padx=5, pady=5) + + self.fonts = font.families() + self.fonts_var = tk.Variable(value=self.fonts) + self.fonts_frame = tk.Frame(self.options_tab_font) + self.fonts_scrollbar = tk.Scrollbar(self.fonts_frame, orient=tk.VERTICAL) + self.options_fonts_listbox = tk.Listbox(self.fonts_frame, + listvariable=self.fonts_var, + yscrollcommand=self.fonts_scrollbar.set) + self.fonts_scrollbar.config(command=self.options_fonts_listbox.yview) + self.fonts_scrollbar.pack(fill=tk.Y, side=tk.RIGHT) + self.options_fonts_listbox.pack(fill=tk.BOTH, expand=True) + self.options_fonts_listbox.bind('<>', self.options_font_click) + self.fonts_frame.grid(row=1, column=0, sticky=tk.NSEW, padx=5, pady=5) + i = 0 + for f in self.fonts: + if f == self.app.option[FONT]: + self.options_fonts_listbox.see(i) + break + i += 1 + + self.fontsizes = [i for i in range(6, 52, 2)] + self.fontsizes_var = tk.Variable(value=self.fontsizes) + self.fontsizes_frame = tk.Frame(self.options_tab_font) + self.fontsizes_scrollbar = tk.Scrollbar(self.fontsizes_frame, orient=tk.VERTICAL) + self.options_fontsizes_listbox = tk.Listbox(self.fontsizes_frame, + listvariable=self.fontsizes_var, + yscrollcommand=self.fontsizes_scrollbar.set) + self.fontsizes_scrollbar.config(command=self.options_fontsizes_listbox.yview) + self.fontsizes_scrollbar.pack(fill=tk.Y, side=tk.RIGHT) + self.options_fontsizes_listbox.pack(fill=tk.BOTH, expand=True) + self.options_fontsizes_listbox.bind('<>', self.options_fontsizes_click) + self.fontsizes_frame.grid(row=1, column=1, sticky=tk.NSEW, padx=5, pady=5) + i = 0 + for f in self.fontsizes: + if f == self.app.option[FONTSIZE]: + self.options_fontsizes_listbox.see(i) + break + i += 1 + + self.options_tab_font.grid_columnconfigure(0, weight=1, uniform="group2") + self.options_tab_font.grid_columnconfigure(1, weight=1, uniform="group2") diff --git a/src/view/sceleton.py b/src/view/sceleton.py index e060afa..f7812c8 100644 --- a/src/view/sceleton.py +++ b/src/view/sceleton.py @@ -63,29 +63,31 @@ def _create_sceleton(self): self.sceleton_main.pack(fill=tk.BOTH, expand=True) self.sceleton_statusbar = tk.Frame(master=self.app.root, height=32) - self.sceleton_statusbar.pack(fill=tk.X) + self.sceleton_statusbar.pack(fill=tk.X, side=tk.BOTTOM) + + self.sceleton_table = tk.Frame(master=self.sceleton_main) + self.sceleton_table.pack(fill=tk.BOTH, expand=True) + + self.sceleton_splitter_vertical1 = tk.Frame(master=self.sceleton_table) - self.sceleton_splitter_vertical1 = tk.Frame(master=self.sceleton_main, width=300) - self.sceleton_splitter_vertical1.pack(fill=tk.Y, side=tk.LEFT, expand=True) self.sceleton_services = tk.Frame(master=self.sceleton_splitter_vertical1) self.sceleton_ads = tk.Frame(master=self.sceleton_splitter_vertical1) self.sceleton_services.pack(fill=tk.BOTH, expand=True) self.sceleton_ads.pack(fill=tk.X, side=tk.BOTTOM) - self.sceleton_table = tk.Frame(master=self.sceleton_main) - self.sceleton_table.pack(fill=tk.BOTH, expand=True) self.sceleton_table1 = tk.Frame(master=self.sceleton_table) self.sceleton_table2 = tk.Frame(master=self.sceleton_table) - self.sceleton_table1.grid(row=0, column=0, sticky="nsew") - self.sceleton_table2.grid(row=0, column=1, sticky="nsew") - self.sceleton_table.grid_columnconfigure(0, weight=1, uniform="group1") + self.sceleton_splitter_vertical1.grid(row=0, column=0, sticky="nsew") + self.sceleton_table1.grid(row=0, column=1, sticky="nsew") + self.sceleton_table2.grid(row=0, column=2, sticky="nsew") self.sceleton_table.grid_columnconfigure(1, weight=1, uniform="group1") + self.sceleton_table.grid_columnconfigure(2, weight=1, uniform="group1") self.sceleton_table.grid_rowconfigure(0, weight=1) def _create_left_list(self): - msg = "Папка ../data не найдена" + msg = SCELETON_DATA_NOT_FOUND[self.app.locale] if os.path.exists("../data/"): - msg = "Книги в папке ./data не найдены" + msg = SCELETON_BOOKS_NOT_FOUND[self.app.locale] dir1 = os.scandir("../data/") for surname in dir1: if surname.is_dir(): @@ -99,10 +101,10 @@ def _create_left_list(self): self.frame_left_list.pack(fill=tk.BOTH, expand=True) for book in self.app.books: try: - if len(self.app.options[POSITIONS][book["full"]]) > 0: + if len(self.app.option[POSITIONS][book["full"]]) > 0: pass except KeyError: - self.app.options[POSITIONS][book["full"]] = {POSI: "0\n0.0\n0.0", AUDIO: EN} + self.app.option[POSITIONS][book["full"]] = {POSI: "0\n0.0\n0.0", AUDIO: EN} self.frames_left.append(tk.Frame(master=self.frame_left_list.interior)) self.frames_left[-1].pack(fill=tk.X, anchor="w", expand=True, padx=5, pady=5) diff --git a/src/view/view.py b/src/view/view.py index 376917a..5519ec9 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -1,10 +1,11 @@ import os import tkinter as tk -from model.utils import * -from .sceleton import Sceleton import pygame from tkinter import scrolledtext +from model.utils import * +from .sceleton import Sceleton + class View(Sceleton): @@ -12,8 +13,8 @@ def __init__(self, app): self.app = app self.root = tk.Tk() self.root.title(self.app.NAME + ' v' + self.app.VERSION) - if os.path.exists('../img/icon.ico'): - self.root.iconbitmap('../img/icon.ico') + if os.path.exists(self.app.ICON_ICO): + self.root.iconbitmap(self.app.ICON_ICO) self.root.geometry('1024x800') self.root.state('normal') @@ -25,16 +26,16 @@ def __init__(self, app): def show_view(self): self.app.frame_content1 = tk.Frame(master=self.app.sceleton_table1) - self.app.frame_content1.pack(fill=tk.Y, side=tk.TOP, expand=True, pady=0) + self.app.frame_content1.pack(fill=tk.BOTH, side=tk.TOP, expand=True, pady=0) self.app.frame_right_annotation1 = tk.Frame(self.app.frame_content1) self.app.frame_right_annotation1.pack(fill=tk.BOTH, side=tk.TOP, expand=True, pady=0) self.app.annotation_text_area1 = scrolledtext.ScrolledText( self.app.frame_right_annotation1, wrap=tk.WORD, - font=(self.app.options[FONT], self.app.options["fontsize"]), - bg=self.app.options[BG], - fg=self.app.options[FG]) + font=(self.app.option[FONT], self.app.option[FONTSIZE]), + bg=self.app.option[BG], + fg=self.app.option[FG]) self.app.annotation_text_area1.pack(fill=tk.BOTH, side=tk.RIGHT, expand=True, pady=5) # self.annotation_text_area1.insert(tk.END, self.annotation) self.app.annotation_text_area1.bind('', self.app.annotation_click) @@ -56,16 +57,16 @@ def show_view(self): self.app.annotation_text.configure(state='disabled') self.app.frame_content2 = tk.Frame(master=self.app.sceleton_table2) - self.app.frame_content2.pack(fill=tk.Y, side=tk.TOP, expand=True, pady=0) + self.app.frame_content2.pack(fill=tk.BOTH, side=tk.TOP, expand=True, pady=0) self.app.frame_right_annotation2 = tk.Frame(self.app.frame_content2) self.app.frame_right_annotation2.pack(fill=tk.BOTH, side=tk.TOP, expand=True, pady=0) self.app.annotation_text_area2 = scrolledtext.ScrolledText(self.app.frame_right_annotation2, wrap=tk.WORD, - font=(self.app.options[FONT], - self.app.options[FONTSIZE]), - bg=self.app.options[BG], - fg=self.app.options[FG]) + font=(self.app.option[FONT], + self.app.option[FONTSIZE]), + bg=self.app.option[BG], + fg=self.app.option[FG]) self.app.annotation_text_area2.pack(fill=tk.BOTH, side=tk.RIGHT, expand=True, pady=5) # self.annotation_text_area2.insert(tk.END, self.annotation) self.app.annotation_text_area2.bind('', self.app.annotation_click)