Exemple #1
0
    def initSpellchecker(self):
        # TODO: disable spellchecker icon in case of not working enchant
        try:
            import enchant
            spellDictDir = settings.get('spellchecker:directory')
            if spellDictDir:
                if enchant.__ver_major__ >= 1 and enchant.__ver_minor__ >= 6:
                    enchant.set_param("enchant.myspell.dictionary.path",
                                      spellDictDir)
                else:
                    print "Your pyenchant version is to old. Please " \
                          "upgrade to version 1.6.0 or higher, if you want " \
                          "to use spellchecker."
                    return None

            spellLang = settings.get('spellchecker:lang')
            if enchant.dict_exists(spellLang):
                self.dict = enchant.Dict(spellLang)
            else:
                # try dictionary based on the current locale
                try:
                    self.dict = enchant.Dict()
                    settings.set('spellchecker:lang', self.dict.tag)
                except:  # we don not have working dictionary...
                    return None
            if self.dict:
                self.usePWL(self.dict)

        except:
            print "can not start spellchecker!!!"
            import traceback
            traceback.print_exc()
            return None
Exemple #2
0
    def saveAs(self):
        if settings.get("file_dialog_dir"):
            self.curDir = '~/'
        else:
            self.curDir = settings.get("file_dialog_dir")

        filename = unicode(QFileDialog.getSaveFileName(self,
                self.tr("Save document"), self.curDir,
                self.tr("ODT document (*.odt);;Text file (*.txt);;"
                        "HTML file (*.html);;PDF file(*.pdf)")
                ))
        if not filename: return

        self.curDir = os.path.dirname(filename)
        settings.set("file_dialog_dir", self.curDir)

        dw = QtGui.QTextDocumentWriter()
        dw.setFormat('ODF')  # Default format

        # Check for alternative output format
        if filename.rsplit('.', 1)[1] == "txt":
            dw.setFormat('plaintext')
        if filename.rsplit('.', 1)[1] in ("html", "htm"):
            dw.setFormat('HTML')
        if filename.rsplit('.', 1)[1] in ("PDF", "pdf"):
            self.filePrintPdf(filename)
            return
        dw.setFileName(filename)
        dw.write(self.document())
Exemple #3
0
    def initSpellchecker(self):
        # TODO: disable spellchecker icon in case of not working enchant
        try:
            import enchant
            spellDictDir = settings.get('spellchecker:directory')
            if spellDictDir:
                if enchant.__ver_major__ >= 1 and enchant.__ver_minor__ >= 6:
                    enchant.set_param("enchant.myspell.dictionary.path",
                                      spellDictDir)
                else:
                    print "Your pyenchant version is to old. Please " \
                          "upgrade to version 1.6.0 or higher, if you want " \
                          "to use spellchecker."
                    return None

            spellLang = settings.get('spellchecker:lang')
            if enchant.dict_exists(spellLang):
                self.dict = enchant.Dict(spellLang)
            else:
                # try dictionary based on the current locale
                try:
                    self.dict = enchant.Dict()
                    settings.set('spellchecker:lang', self.dict.tag)
                except:  # we don not have working dictionary...
                    return None
            if self.dict:
                self.usePWL(self.dict)

        except:
            print "can not start spellchecker!!!"
            import traceback
            traceback.print_exc()
            return None
Exemple #4
0
    def saveAs(self):
        if settings.get("file_dialog_dir"):
            self.curDir = '~/'
        else:
            self.curDir = settings.get("file_dialog_dir")

        filename = unicode(
            QFileDialog.getSaveFileName(
                self, self.tr("Save document"), self.curDir,
                self.tr("ODT document (*.odt);;Text file (*.txt);;"
                        "HTML file (*.html);;PDF file(*.pdf)")))
        if not filename: return

        self.curDir = os.path.dirname(filename)
        settings.set("file_dialog_dir", self.curDir)

        dw = QtGui.QTextDocumentWriter()
        dw.setFormat('ODF')  # Default format

        # Check for alternative output format
        if filename.rsplit('.', 1)[1] == "txt":
            dw.setFormat('plaintext')
        if filename.rsplit('.', 1)[1] in ("html", "htm"):
            dw.setFormat('HTML')
        if filename.rsplit('.', 1)[1] in ("PDF", "pdf"):
            self.filePrintPdf(filename)
            return
        dw.setFileName(filename)
        dw.write(self.document())
Exemple #5
0
    def accept(self):
        """ Store settings on OK
        """
        settings.set('scanner:height', self.ui.sbHeight.value())
        settings.set('scanner:width', self.ui.sbWidth.value())
        settings.set('scanner:resolution', self.ui.sbResolution.value())
        settings.set('scanner:mode', self.ui.combColor.currentText())
        settings.set('scanner:device',
                     self.sane_list[self.ui.combScanner.currentIndex()][0])

        QDialog.accept(self)
    def accept(self):
        """ Store settings on OK
        """
        settings.set('scanner:height', self.ui.sbHeight.value())
        settings.set('scanner:width', self.ui.sbWidth.value())
        settings.set('scanner:resolution', self.ui.sbResolution.value())
        settings.set('scanner:mode',
                     self.ui.combColor.currentText())
        settings.set('scanner:device',
                     self.sane_list[self.ui.combScanner.currentIndex()][0])

        QDialog.accept(self)
Exemple #7
0
 def togglewhiteSpace(self, state=True):
     """
     Show or hide whitespace and line ending markers
     """
     option = QTextOption()
     if state:
         option.setFlags(QTextOption.ShowTabsAndSpaces |
                         QTextOption.ShowLineAndParagraphSeparators)
     else:
         option.setFlags(option.flags() & ~option.ShowTabsAndSpaces &
                         ~option.ShowLineAndParagraphSeparators)
     self.document().setDefaultTextOption(option)
     settings.set('editor:whiteSpace', state)
Exemple #8
0
 def togglewhiteSpace(self, state=True):
     """
     Show or hide whitespace and line ending markers
     """
     option = QTextOption()
     if state:
         option.setFlags(QTextOption.ShowTabsAndSpaces
                         | QTextOption.ShowLineAndParagraphSeparators)
     else:
         option.setFlags(option.flags() & ~option.ShowTabsAndSpaces
                         & ~option.ShowLineAndParagraphSeparators)
     self.document().setDefaultTextOption(option)
     settings.set('editor:whiteSpace', state)
Exemple #9
0
    def accept(self):
        """ Store all settings
        """
        settings.set('scanner:height', self.ui.sbHeight.value())
        settings.set('scanner:width', self.ui.sbWidth.value())
        settings.set('scanner:resolution', self.ui.sbResolution.value())
        settings.set('scanner:mode',
                     self.colors[self.ui.combColor.currentIndex()])

        settings.set('editor:font', self.ui.fontLabel.font())
        settings.set('editor:clear', self.ui.checkBoxClear.isChecked())
        settings.set('editor:symbols', self.ui.symbolList.toPlainText())

        langIdx =  self.ui.dictBox.currentIndex()
        settings.set('spellchecker:lang', self.ui.dictBox.itemText(langIdx))
        settings.set('spellchecker:directory', self.ui.directoryLine.text())
        settings.set('spellchecker:pwlDict', self.ui.lineEditPWL.text())
        settings.set('spellchecker:pwlLang', self.ui.checkBoxPWL.isChecked())

        settings.set('tesseract-ocr:executable', self.ui.lnTessExec.text())
        settings.set('tesseract-ocr:TESSDATA_PREFIX',
                     self.ui.lnTessData.text())

        if self.ui.cbLog.isChecked():
            filename = self.ui.lnLog.text()
            if filename:
                # TODO(zdposter): check if file is writable
                pass
            else:
                QMessageBox.warning(self, self.tr("Lector"),
                    self.tr("You did not specified file for logging.\n") + \
                    self.tr("Logging will be disabled."), QMessageBox.Ok)
                self.ui.cbLog.setChecked(0)

        settings.set('log:errors', self.ui.cbLog.isChecked())
        settings.set('log:filename', self.ui.lnLog.text())

        uiLangIdx =  self.ui.cbLang.currentIndex()
        uiLocale = self.ui.cbLang.itemText(uiLangIdx)
        settings.set('ui:lang', uiLocale)

        self.settingAccepted.emit()
        QDialog.accept(self)
Exemple #10
0
    def writeSettings(self):
        """ Store settings
        """
        settings.set("pos", self.pos())
        settings.set("size", self.size())
        settings.set("file_dialog_dir", self.curDir)
        settings.set("mainWindowGeometry", self.saveGeometry())
        settings.set("mainWindowState", self.saveState())

        ## save language
        settings.set("rbtn/lang", self.ocrWidget.language)
Exemple #11
0
    def writeSettings(self):
        """ Store settings
        """
        settings.set("pos", self.pos())
        settings.set("size", self.size())
        settings.set("file_dialog_dir", self.curDir)
        settings.set("mainWindowGeometry", self.saveGeometry())
        settings.set("mainWindowState", self.saveState())

        ## save language
        settings.set("rbtn/lang", self.ocrWidget.language)
Exemple #12
0
 def toggleSpell(self, state):
     if state:
         self.initSpellchecker()
     else:
         self.stopSpellchecker()
     settings.set('editor:spell', state)
Exemple #13
0
 def toggleSpell(self, state):
     if state:
         self.initSpellchecker()
     else:
         self.stopSpellchecker()
     settings.set('editor:spell', state)
Exemple #14
0
    def accept(self):
        """ Store all settings
        """
        settings.set('scanner:height', self.ui.sbHeight.value())
        settings.set('scanner:width', self.ui.sbWidth.value())
        settings.set('scanner:resolution', self.ui.sbResolution.value())
        settings.set('scanner:mode',
                     self.colors[self.ui.combColor.currentIndex()])

        settings.set('editor:font', self.ui.fontLabel.font())
        settings.set('editor:clear', self.ui.checkBoxClear.isChecked())
        settings.set('editor:symbols', self.ui.symbolList.toPlainText())

        langIdx = self.ui.dictBox.currentIndex()
        settings.set('spellchecker:lang', self.ui.dictBox.itemText(langIdx))
        settings.set('spellchecker:directory', self.ui.directoryLine.text())
        settings.set('spellchecker:pwlDict', self.ui.lineEditPWL.text())
        settings.set('spellchecker:pwlLang', self.ui.checkBoxPWL.isChecked())

        settings.set('tesseract-ocr:executable', self.ui.lnTessExec.text())
        settings.set('tesseract-ocr:TESSDATA_PREFIX',
                     self.ui.lnTessData.text())

        if self.ui.cbLog.isChecked():
            filename = self.ui.lnLog.text()
            if filename:
                # TODO(zdposter): check if file is writable
                pass
            else:
                QMessageBox.warning(self, self.tr("Lector"),
                    self.tr("You did not specified file for logging.\n") + \
                    self.tr("Logging will be disabled."), QMessageBox.Ok)
                self.ui.cbLog.setChecked(0)

        settings.set('log:errors', self.ui.cbLog.isChecked())
        settings.set('log:filename', self.ui.lnLog.text())

        uiLangIdx = self.ui.cbLang.currentIndex()
        uiLocale = self.ui.cbLang.itemText(uiLangIdx)
        settings.set('ui:lang', uiLocale)

        self.settingAccepted.emit()
        QDialog.accept(self)