<commit_before>import platform

from PyQt4 import QtGui, QtCore

from epubcreator.gui.forms import preferences_general_widget_ui, preferences_docx_widget_ui, preferences_epubbase_widget_ui
from epubcreator.gui.misc import settings_store, utils
from epubcreator.converters.docx import docx_converter
from epubcreator.epubbase import ebook


class PreferencesAbstract(QtGui.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

    def saveSettings(self):
        raise NotImplemented


class GeneralPreferences(PreferencesAbstract, preferences_general_widget_ui.Ui_GeneralPreferences):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)

        self.changeSigilPathButton.clicked.connect(self._changeSigilPath)

        self._loadSettings()

    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.editor = self.editorInput.text().strip()
        settings.sigilPath = self.sigilPathInput.text().strip()

    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.editorInput.setText(settings.editor)
        self.sigilPathInput.setText(settings.sigilPath)

    def _changeSigilPath(self):
        dialogFilter = "Sigil (sigil.exe)"

        if platform.system() == "Linux":
            dialogFilter = "Sigil (sigil)"
        elif platform.system() == "Darwin":
            dialogFilter = "Sigil (Sigil.app)"

        fileName = QtGui.QFileDialog.getOpenFileName(self, "", "", dialogFilter)
        if fileName:
            self.sigilPathInput.setText(fileName)


class DocxPreferences(PreferencesAbstract, preferences_docx_widget_ui.Ui_DocxPreferences):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self._extendUi()

        self._loadSettings()

    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.docxIgnoreEmptyParagraphs = self.ignoreEmptyParagraphsInput.isChecked()

    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.ignoreEmptyParagraphsInput.setCheckState(QtCore.Qt.Checked if settings.docxIgnoreEmptyParagraphs else QtCore.Qt.Unchecked)

    def _extendUi(self):
        description = utils.formatTextForTooltip(docx_converter.DocxConverter.getOptionDescription("ignoreEmptyParagraphs"))
        self.ignoreEmptyParagraphsInput.setToolTip(description)


class EpubBasePreferences(PreferencesAbstract, preferences_epubbase_widget_ui.Ui_EpubBasePreferences):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self._extendUi()

        self._loadSettings()

    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.epubBaseIncludeOptionalFiles = self.includeOptionalFilesInput.isChecked()

    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.includeOptionalFilesInput.setCheckState(QtCore.Qt.Checked if settings.epubBaseIncludeOptionalFiles else QtCore.Qt.Unchecked)

    def _extendUi(self):
        description = utils.formatTextForTooltip(ebook.Ebook.getOptionDescription("includeOptionalFiles"))
        self.includeOptionalFilesInput.setToolTip(description)<commit_msg>Gui: añade algunos tooltips.<commit_after>import platform

from PyQt4 import QtGui, QtCore

from epubcreator.gui.forms import preferences_general_widget_ui, preferences_docx_widget_ui, preferences_epubbase_widget_ui
from epubcreator.gui.misc import settings_store, utils
from epubcreator.converters.docx import docx_converter
from epubcreator.epubbase import ebook


class PreferencesAbstract(QtGui.QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)

    def saveSettings(self):
        raise NotImplemented


class GeneralPreferences(PreferencesAbstract, preferences_general_widget_ui.Ui_GeneralPreferences):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self._extendUi()

        self.changeSigilPathButton.clicked.connect(self._changeSigilPath)

        self._loadSettings()

    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.editor = self.editorInput.text().strip()
        settings.sigilPath = self.sigilPathInput.text().strip()

    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.editorInput.setText(settings.editor)
        self.sigilPathInput.setText(settings.sigilPath)

    def _changeSigilPath(self):
        dialogFilter = "Sigil (sigil.exe)"

        if platform.system() == "Linux":
            dialogFilter = "Sigil (sigil)"
        elif platform.system() == "Darwin":
            dialogFilter = "Sigil (Sigil.app)"

        fileName = QtGui.QFileDialog.getOpenFileName(self, "", "", dialogFilter)
        if fileName:
            self.sigilPathInput.setText(fileName)

    def _extendUi(self):
        self.editorInput.setToolTip(utils.formatTextForTooltip("El alias del editor."))
        self.sigilPathInput.setToolTip(utils.formatTextForTooltip("Si se desea abrir automáticamente con Sigil el epub generado, entonces "
                                                                  "completar este campo con la ruta hacia el ejecutable."))


class DocxPreferences(PreferencesAbstract, preferences_docx_widget_ui.Ui_DocxPreferences):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self._extendUi()

        self._loadSettings()

    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.docxIgnoreEmptyParagraphs = self.ignoreEmptyParagraphsInput.isChecked()

    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.ignoreEmptyParagraphsInput.setCheckState(QtCore.Qt.Checked if settings.docxIgnoreEmptyParagraphs else QtCore.Qt.Unchecked)

    def _extendUi(self):
        description = utils.formatTextForTooltip(docx_converter.DocxConverter.getOptionDescription("ignoreEmptyParagraphs"))
        self.ignoreEmptyParagraphsInput.setToolTip(description)


class EpubBasePreferences(PreferencesAbstract, preferences_epubbase_widget_ui.Ui_EpubBasePreferences):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self._extendUi()

        self._loadSettings()

    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.epubBaseIncludeOptionalFiles = self.includeOptionalFilesInput.isChecked()

    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.includeOptionalFilesInput.setCheckState(QtCore.Qt.Checked if settings.epubBaseIncludeOptionalFiles else QtCore.Qt.Unchecked)

    def _extendUi(self):
        description = utils.formatTextForTooltip(ebook.Ebook.getOptionDescription("includeOptionalFiles"))
        self.includeOptionalFilesInput.setToolTip(description)
{'fraction_non_alphanumeric': 0.08771680409439864, 'fraction_numerical': 0.0002843332385555871, 'mean_word_length': 3.7824609109449354, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6329831', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1927, 'n_words': 315}