|
| 1 | +from tkinter import * |
| 2 | +from tkinter import Label as oldLabel |
| 3 | +from tkinter.ttk import * |
| 4 | +from windows.popup import Popup |
| 5 | +from sys import platform |
| 6 | +from webbrowser import open_new |
| 7 | +import os |
| 8 | +import json |
| 9 | + |
| 10 | +class Translators(Popup): |
| 11 | + def __init__(self, parent, main_app): |
| 12 | + width = 330 |
| 13 | + if platform.lower() == "darwin": |
| 14 | + width += 110 |
| 15 | + super().__init__(main_app.text_content["others_menu"]["translators_settings"]["title"], width, 300, parent) |
| 16 | + parent.prevent_record = True |
| 17 | + self.element_per_page = 6 |
| 18 | + |
| 19 | + self.translators_list = [] |
| 20 | + directory_path = os.path.join(os.path.dirname(__file__), '../../langs') |
| 21 | + for filename in os.listdir(directory_path): |
| 22 | + if filename.endswith('.json'): |
| 23 | + filepath = os.path.join(directory_path, filename) |
| 24 | + try: |
| 25 | + with open(filepath, 'r', encoding='utf-8') as json_file: |
| 26 | + data = json.load(json_file) |
| 27 | + information = data.get("information", {}) |
| 28 | + author = information.get("author", "Unknown Author") |
| 29 | + lang_long = information.get("lang_long", "Unknown Language") |
| 30 | + self.translators_list.append(f"{lang_long} - {author}") |
| 31 | + except Exception as e: |
| 32 | + print(f"Error while opening {filename}: {e}") |
| 33 | + |
| 34 | + Label(self, text=main_app.text_content["others_menu"]["translators_settings"]["sub_text"] + "! <3", font=('Arial', 12, 'bold')).pack(side=TOP, pady=5) |
| 35 | + self.translatorsArea = Frame(self) |
| 36 | + self.navigationArea = Frame(self) |
| 37 | + self.pageArea = Frame(self) |
| 38 | + Button(self, text=main_app.text_content["global"]["close_button"], command=self.destroy).pack(side=BOTTOM, pady=5) |
| 39 | + self.display_translators(0, 1, main_app) |
| 40 | + self.wait_window() |
| 41 | + parent.prevent_record = False |
| 42 | + |
| 43 | + def display_translators(self, current_index, page, main_app): |
| 44 | + translators = self.translators_list[current_index:current_index+self.element_per_page] |
| 45 | + for widget in self.navigationArea.winfo_children(): |
| 46 | + widget.destroy() |
| 47 | + for widget in self.translatorsArea.winfo_children(): |
| 48 | + widget.destroy() |
| 49 | + for widget in self.pageArea.winfo_children(): |
| 50 | + widget.destroy() |
| 51 | + for translator in translators: |
| 52 | + Label(self.translatorsArea, text=translator.strip()).pack(side=TOP, pady=2) |
| 53 | + maxPage = (len(self.translators_list) // self.element_per_page) |
| 54 | + if len(self.translators_list) % self.element_per_page > 0: |
| 55 | + maxPage += 1 |
| 56 | + self.translatorsArea.pack(side=TOP) |
| 57 | + if page > 1: |
| 58 | + Button(self.navigationArea, text=main_app.text_content["global"]["previous_text"], |
| 59 | + command=lambda: self.display_translators(current_index - self.element_per_page, page - 1, main_app)).pack( |
| 60 | + side=LEFT, padx=5, pady=5) |
| 61 | + if current_index + self.element_per_page < len(self.translators_list): |
| 62 | + Button(self.navigationArea, text=main_app.text_content["global"]["next_text"], |
| 63 | + command=lambda: self.display_translators(current_index + self.element_per_page, page + 1, main_app)).pack( |
| 64 | + side=LEFT, padx=5, pady=5) |
| 65 | + self.navigationArea.pack(side=BOTTOM) |
| 66 | + Label(self.pageArea, text=f'Page {page} / {maxPage}').pack(side=TOP, pady=2) |
| 67 | + self.pageArea.pack(side=BOTTOM) |
| 68 | + |
| 69 | + |
0 commit comments