Exemplo n.º 1
0
    def toggleSpellcheck(self, v):
        self.spellcheck = v
        if enchant and self.spellcheck and not self._dict:
            if self.currentDict and enchant.dict_exists(self.currentDict):
                self._dict = enchant.Dict(self.currentDict)
            elif enchant.get_default_language() and enchant.dict_exists(enchant.get_default_language()):
                self._dict = enchant.Dict(enchant.get_default_language())
            else:
                self.spellcheck = False

        if self.highlighter:
            self.highlighter.rehighlight()
        else:
            self.spellcheck = False
Exemplo n.º 2
0
    def toggleSpellcheck(self, v):
        self.spellcheck = v
        if enchant and self.spellcheck and not self._dict:
            if self.currentDict:
                self._dict = enchant.Dict(self.currentDict)
            elif enchant.get_default_language() and enchant.dict_exists(enchant.get_default_language()):
                self._dict = enchant.Dict(enchant.get_default_language())
            else:
                self.spellcheck = False

        if self.highlighter:
            self.highlighter.rehighlight()
        else:
            self.spellcheck = False
Exemplo n.º 3
0
    def getDefaultLocale(self):
        default_locale = enchant.get_default_language()
        if default_locale is None:
            default_locale = QLocale.system().name()
        if default_locale is None:
            default_locale = enchant.list_dicts()[0][0]

        return default_locale
Exemplo n.º 4
0
    def getDefaultLocale(self):
        default_locale = enchant.get_default_language()
        if default_locale is None:
            default_locale = QLocale.system().name()
        if default_locale is None:
            default_locale = enchant.list_dicts()[0][0]

        return default_locale
Exemplo n.º 5
0
    def getDefaultDictionary():
        if not EnchantDictionary.isInstalled():
            return None

        default_locale = enchant.get_default_language()
        if default_locale and not enchant.dict_exists(default_locale):
            default_locale = None

        if default_locale is None:
            default_locale = QLocale.system().name()
        if default_locale is None:
            default_locale = self.availableDictionaries()[0]

        return default_locale
Exemplo n.º 6
0
 def _create_new_dir_config(self) -> Dict[str, object]:
     """
     Create a new config file with default values.
     :return: New configuration dictionary.
     """
     return {
         self.CONF_WORKING_DIR:
         Strings.home_directory,
         self.CONF_POSITION:
         '0,0',
         self.CONF_SIZE:
         str(Numbers.minimal_window_size_width) + ',' +
         str(Numbers.minimal_window_size_height),
         self.CONF_GLOBAL_TITLE:
         '',
         self.CONF_AUTHOR:
         Strings.author,
         self.CONF_CONTACT:
         '',
         self.CONF_KEYWORDS:
         '',
         self.CONF_DESCRIPTION:
         '',
         self.CONF_SCRIPT:
         '',
         self.CONF_BLACK_TXT:
         '',
         self.CONF_RED_TXT:
         '',
         self.CONF_PAGE_URL:
         '',
         self.CONF_IP:
         '',
         self.CONF_USER:
         '',
         self.CONF_KEYFILE:
         '',
         self.CONF_ONLINE_TEST:
         '1',
         self.CONF_SPELLCHECK_TEST:
         '1',
         self.CONF_LANG:
         enchant.get_default_language(),
         self.CONF_LAST_IMG_DIR:
         Strings.home_directory,
         self.CONF_NEWS:
         str(Numbers.default_news),
         self.CONF_UNUPLOADED: []
     }
Exemplo n.º 7
0
    def get_spelling_lang(self) -> str:
        """
        Get spelling language for spellchecker or default language if the required is not found.
        :return: Spelling language code for spellchecker.
        """
        # If spelling language is not set, use default.
        default_language = enchant.get_default_language()
        if self.CONF_LANG not in self._dir_conf.keys():
            self._dir_conf[self.CONF_LANG] = default_language

        # Use default language if the language package set in config is not installed.
        language: str = self._dir_conf[self.CONF_LANG]
        if language not in enchant.list_languages():
            self.store_spelling_language(language)
        return language
Exemplo n.º 8
0
    def updateMenuDict(self):

        if not enchant:
            return

        self.menuDict.clear()
        for i in enchant.list_dicts():
            a = QAction(str(i[0]), self)
            a.setCheckable(True)
            if settings.dict is None:
                settings.dict = enchant.get_default_language()
            if str(i[0]) == settings.dict:
                a.setChecked(True)
            a.triggered.connect(self.setDictionary, AUC)
            self.menuDictGroup.addAction(a)
            self.menuDict.addAction(a)
Exemplo n.º 9
0
    def updateMenuDict(self):

        if not enchant:
            return

        self.menuDict.clear()
        for i in enchant.list_dicts():
            a = QAction(str(i[0]), self)
            a.setCheckable(True)
            if settings.dict is None:
                settings.dict = enchant.get_default_language()
            if str(i[0]) == settings.dict:
                a.setChecked(True)
            a.triggered.connect(self.setDictionary, AUC)
            self.menuDictGroup.addAction(a)
            self.menuDict.addAction(a)
Exemplo n.º 10
0
    def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="",
                 autoResize=False):
        QTextEdit.__init__(self, parent)
        self._column = Outline.text.value
        self._index = None
        self._indexes = None
        self._model = None
        self._placeholderText = self.placeholderText()
        self._updating = False
        self._item = None
        self._highlighting = highlighting
        self._textFormat = "text"
        self.setAcceptRichText(False)
        # When setting up a theme, this becomes true.
        self._fromTheme = False

        self.spellcheck = spellcheck
        self.currentDict = dict if dict else settings.dict
        self.highlighter = None
        self.setAutoResize(autoResize)
        self._defaultBlockFormat = QTextBlockFormat()
        self._defaultCharFormat = QTextCharFormat()
        self.highlightWord = ""
        self.highligtCS = False
        self.defaultFontPointSize = qApp.font().pointSize()
        self._dict = None
        # self.document().contentsChanged.connect(self.submit, AUC)

        # Submit text changed only after 500ms without modifications
        self.updateTimer = QTimer()
        self.updateTimer.setInterval(500)
        self.updateTimer.setSingleShot(True)
        self.updateTimer.timeout.connect(self.submit)
        # self.updateTimer.timeout.connect(lambda: print("Timeout"))

        self.updateTimer.stop()
        self.document().contentsChanged.connect(self.updateTimer.start, AUC)
        # self.document().contentsChanged.connect(lambda: print("Document changed"))

        # self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))

        self.setEnabled(False)

        if index:
            self.setCurrentModelIndex(index)

        elif html:
            self.document().setHtml(html)
            self.setReadOnly(True)

        # Spellchecking
        if enchant and self.spellcheck:
            try:
                self._dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
            except enchant.errors.DictNotFoundError:
                self.spellcheck = False

        else:
            self.spellcheck = False

        if self._highlighting and not self.highlighter:
            self.highlighter = basicHighlighter(self)
            self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
Exemplo n.º 11
0
    def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="",
                 autoResize=False):
        QTextEdit.__init__(self, parent)
        self._column = Outline.text.value
        self._index = None
        self._indexes = None
        self._model = None
        self._placeholderText = self.placeholderText()
        self._updating = False
        self._item = None
        self._highlighting = highlighting
        self._textFormat = "text"
        self.setAcceptRichText(False)
        # When setting up a theme, this becomes true.
        self._fromTheme = False

        self.spellcheck = spellcheck
        self.currentDict = dict if dict else settings.dict
        self.highlighter = None
        self.setAutoResize(autoResize)
        self._defaultBlockFormat = QTextBlockFormat()
        self._defaultCharFormat = QTextCharFormat()
        self.highlightWord = ""
        self.highligtCS = False
        self.defaultFontPointSize = qApp.font().pointSize()
        self._dict = None
        # self.document().contentsChanged.connect(self.submit, AUC)

        # Submit text changed only after 500ms without modifications
        self.updateTimer = QTimer()
        self.updateTimer.setInterval(500)
        self.updateTimer.setSingleShot(True)
        self.updateTimer.timeout.connect(self.submit)
        # self.updateTimer.timeout.connect(lambda: print("Timeout"))

        self.updateTimer.stop()
        self.document().contentsChanged.connect(self.updateTimer.start, AUC)
        # self.document().contentsChanged.connect(lambda: print("Document changed"))

        # self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))

        self.setEnabled(False)

        if index:
            self.setCurrentModelIndex(index)

        elif html:
            self.document().setHtml(html)
            self.setReadOnly(True)

        # Spellchecking
        if enchant and self.spellcheck:
            try:
                self._dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
            except enchant.errors.DictNotFoundError:
                self.spellcheck = False

        else:
            self.spellcheck = False

        if self._highlighting and not self.highlighter:
            self.highlighter = basicHighlighter(self)
            self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
Exemplo n.º 12
0
    user_files = ["config.json", "wordlist.txt", "parsed_stylesheet.css"]

    # Change resource directory depending on if it is running from source or running compiled
    if sys.platform == "linux" or os.path.basename(__file__) == "CONSTANTS.py":
        base_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),"resources", "base")
    else:
        base_path = os.path.join(os.path.dirname(__file__),"resources", "base")

    if filepath in user_files:
        base_path = config_dir


    return os.path.join(base_path, filepath)

# Load system default dictionary
spell_lang = enchant.get_default_language() if enchant.dict_exists(enchant.get_default_language()) else "en_US"
# Load spell dictionary
spell_dict = enchant.DictWithPWL(spell_lang, get_resource("wordlist.txt"))

# Load icons and themes
with open(get_resource("icons.json")) as icons:
    icons = json.loads(icons.read())

theme = "light"
with open(get_resource("colors.json")) as colors:
    colors = json.loads(colors.read())

version = "1.0.8"

light_palette = QtWidgets.QApplication.palette()
if not sys.platform.startswith("linux"):