Esempio n. 1
0
 def _manage_whitelist(self):
     fn = ini.get('paths', 'whitelist')
     if "\\" not in fn or "/" not in fn:  # file in the same directory of pylanggui
         fn = os.path.join(gui_folder, fn)
     wl = WhiteListManager(self.root, "Whitelist Manager",
                           ini.get(section, 'geometry_whitelist_manager'),
                           fn)
Esempio n. 2
0
    def _draw_commands(self):
        # Commands
        fmcmd = ttk.LabelFrame(self._mf, text=' Commands ')
        tk.Label(fmcmd, text='Languages').grid(row=0,
                                               column=0,
                                               padx=5,
                                               pady=0,
                                               ipady=0)
        cmb_lang = ttk.Combobox(fmcmd, textvariable=self._language, width=10)
        cmb_lang['values'] = [lang.name for lang in self._languages]
        lng = ini.get('language', 'default')
        tmplng = [item.code for item in self._languages]
        default_lang = tmplng.index(lng) if lng else -1
        cmb_lang.current(default_lang)
        cmb_lang.grid(row=1, column=0, padx=0, pady=5, ipady=0)

        bt1 = tk.Button(fmcmd,
                        text='Paste text',
                        width=10,
                        command=self._paste)
        bt1.grid(row=2, column=0, padx=5, pady=5)

        bt2 = tk.Button(fmcmd,
                        text='Load from file',
                        width=10,
                        command=self._load)
        bt2.grid(row=3, column=0, padx=5, pady=5)

        bt3 = tk.Button(fmcmd, text='Parse', width=10, command=self._parse)
        bt3.grid(row=4, column=0, padx=5, pady=5)

        bt4 = tk.Button(fmcmd,
                        text='Clear',
                        width=10,
                        command=lambda: self._empty_text(self._text))
        bt4.grid(row=5, column=0, padx=5, pady=5)

        bt5 = tk.Button(fmcmd, text='Copy text', width=10, command=self._parse)
        bt5.grid(row=6, column=0, padx=5, pady=5)

        bt6 = tk.Button(fmcmd,
                        text='Save to file',
                        width=10,
                        command=self._save)
        bt6.grid(row=7, column=0, padx=5, pady=5)
        fmcmd.grid(row=0, column=1, padx=5, pady=5, sticky=tk.NSEW)

        self._setup_tooltips([
            (bt1, "Paste text from the current clipboard"),
            (bt2, "Load the contents of a file"),
            (bt3, "Perform check spelling with text area contents"),
            (bt4, "Clear text area"),
            (bt5, "Copy text area content to clipboard"),
            (bt6, 'Save text area content to file')
        ])
Esempio n. 3
0
 def _addword(self):
     word = self.errors[self._navpos].text_error.strip().lower()
     if word in self._whitelist:
         showinfo(title="Manage whitelist",
                  message=f'{word} already whitelisted')
     self._whitelist.append(word)
     prev_pos = self._navpos
     self.errors = pylt.Error.update_whitelisted(self.errors,
                                                 self._whitelist)
     if self._ignore_whitelisted.get() == 1:
         self.errors = pylt.Error.whitelist_filtered(self.errors)
     if self._wlauto.get() == 1:
         save_whitelist(self._whitelist, ini.get('paths', 'whitelist'))
     self._errors_original = self.errors[:]
Esempio n. 4
0
def get_languages() -> list:
    """
    Retrieve available languages from LangToolWrapper
    If operation fails, append the default language to the return list
    :return: list of `pylt.Languages`
    """
    try:
        languages: list = pylt.get_languages()
    except Exception as exc:
        prompt = (f'Error trying to retrieve languages\n{exc}\n'
                  f'Falling back to the default language\n\n'
                  f'If it\'s a network error the spellckecking may not work '
                  f'anyway')
        showerror("Languages retrieval", prompt)
        languages = list()
    finally:
        # Adds the default language
        lng = ini.get('language', 'default')
        languages.append(pylt.Language(lng, lng, lng))
        return languages
Esempio n. 5
0
 def _save_wl(self):
     save_whitelist(self._whitelist, ini.get('paths', 'whitelist'))
     showinfo(message=f'{len(self._whitelist)} words in whitelist')
Esempio n. 6
0
from tkinter.filedialog import askdirectory, askopenfilename, asksaveasfilename
from tkinter.messagebox import askyesno, askquestion
from tkinter.messagebox import showinfo, showerror, showwarning
import tkinter.ttk as ttk
from typing import Tuple, List

import pylangtoolwrapper as pylt
import entities
from pylanggui.__init__ import ini, get_whitelist, gui_folder
from tk_tooltips import show_tooltip
from tk_whitelists import WhiteListManager

__version__ = '0.2'
DEV_MODE = False
section = 'windows' if os.name == 'nt' else 'unix'
geometry = ini.get(section, 'geometry')
statusbar_len = ini.get(section, 'statusbar')
MAX_CHARS_FOR_REQUEST = ini.getint('misc', 'max_chars_for_request')

# TODO: Message when last error is reached (restart from top, stop ...)


def get_languages() -> list:
    """
    Retrieve available languages from LangToolWrapper
    If operation fails, append the default language to the return list
    :return: list of `pylt.Languages`
    """
    try:
        languages: list = pylt.get_languages()
    except Exception as exc: