コード例 #1
0
    def _scheduleDocumentProcessing(self):
        """Start document processing with the thread.
        """
        self._typingTimer.stop()

        document = core.workspace().currentDocument()
        if document is not None:
            language = document.qutepart.language()
            if isMarkdownFile(document):
                language = 'Markdown'
            elif isHtmlFile(document):
                language = 'HTML'

            self._thread.process(document.filePath(), language,
                                 document.qutepart.text)
コード例 #2
0
ファイル: preview.py プロジェクト: emiola/enki
    def _scheduleDocumentProcessing(self):
        """Start document processing with the thread.
        """
        self._typingTimer.stop()

        document = core.workspace().currentDocument()
        if document is not None:
            language = document.qutepart.language()
            text = document.qutepart.text
            if language == 'Markdown':
                text = self._getCurrentTemplate() + text
            elif isHtmlFile(document):
                language = 'HTML'
            # for rest language is already correct
            self._thread.process(document.filePath(), language, text)
コード例 #3
0
ファイル: preview.py プロジェクト: o2edu/enki
    def _scheduleDocumentProcessing(self):
        """Start document processing with the thread.
        """
        if not self._programRunning:
            return

        if self.isHidden():
            return

        self._typingTimer.stop()

        document = core.workspace().currentDocument()
        if document is not None:
            if sphinxEnabledForFile(document.filePath()):
                self._copySphinxProjectTemplate(document.filePath())
            qp = document.qutepart
            language = qp.language()
            text = qp.text
            sphinxCanProcess = sphinxEnabledForFile(document.filePath())
            # Determine if we're in the middle of a build.
            currentlyBuilding = self._widget.prgStatus.text() == 'Building...'

            if language == 'Markdown':
                text = self._getCurrentTemplate() + text
                # Hide the progress bar, since processing is usually short and
                # Markdown produces no errors or warnings to display in the
                # progress bar. See https://github.com/bjones1/enki/issues/36.
                self._widget.prgStatus.setVisible(False)
                # Hide the error log, since Markdown never generates errors or
                # warnings.
                self._widget.teLog.setVisible(False)
            elif isHtmlFile(document):
                # No processing needed -- just display it.
                self._setHtml(document.filePath(), text, None, QUrl())
                # Hide the progress bar, since no processing is necessary.
                self._widget.prgStatus.setVisible(False)
                # Hide the error log, since we do not HTML checking.
                self._widget.teLog.setVisible(False)
                return
            elif ((language == 'reStructuredText') or sphinxCanProcess
                  or canUseCodeChat(document.filePath())):
                # Show the progress bar and error log for reST, CodeChat, or
                # Sphinx builds. It will display progress (Sphinx only) and
                # errors/warnings (for all three).
                self._widget.prgStatus.setVisible(True)
                self._widget.teLog.setVisible(True)
                self._setHtmlProgress('Building...')

            # Determine whether to initiate a build or not. The underlying
            # logic:
            #
            # - If Sphinx can't process this file, just build it.
            # - If Sphinx can process this file:
            #
            #   - If the document isn't internally modified, we're here because
            #     the file was saved or the refresh button was pressed. Build it.
            #   - If the document was internally modified and "insta-build" is
            #     enabled (i.e. build only on save is disabled):
            #
            #     - If the document was not externally modified, then save and
            #       build.
            #     - If the document was externally modified, DANGER! The user
            #       needs to decide which file wins (external changes or
            #       internal changes). Don't save and build, since this would
            #       overwrite external modifications without the user realizing
            #       what happened. Instead, warn the user.
            #
            # As a table, see below. Build, Save, and Warn are the outputs; all
            # others are inputs.
            #
            # ==================  ===================  ===================  =============  =====  ====  ====
            # Sphinx can process  Internally modified  Externally modified  Build on Save  Build  Save  Warn
            # ==================  ===================  ===================  =============  =====  ====  ====
            # No                  X                    X                    X              Yes    No    No
            # Yes                 No                   X                    X              Yes    No    No
            # Yes                 Yes                  No                   No             Yes    Yes   No
            # Yes                 Yes                  Yes                  No             No     No    Yes
            # Yes                 Yes                  X                    Yes            No     No    No
            # ==================  ===================  ===================  =============  =====  ====  ====
            internallyModified = qp.document().isModified()
            externallyModified = document.isExternallyModified()
            buildOnSave = core.config()['Sphinx']['BuildOnSave']
            saveThenBuild = (sphinxCanProcess and internallyModified
                             and not externallyModified and not buildOnSave)
            # If Sphinx is currently building, don't autosave -- this can
            # cause Sphinx to miss changes on its next build. Instead, wait
            # until Sphinx completes, then do a save and build.
            if saveThenBuild and currentlyBuilding:
                self._rebuildNeeded = True
                saveThenBuild = False
            else:
                self._rebuildNeeded = False
            # Save first, if needed.
            if saveThenBuild:
                # If trailing whitespace strip changes the cursor position,
                # restore the whitespace and cursor position.
                lineNum, col = qp.cursorPosition
                lineText = qp.lines[lineNum]
                # Invoking saveFile when Strip Trailing whitespace is enabled
                # causes ``onTextChanged`` (due to whitespace strips) and
                # ``onDocumentChanged`` signals to be emitted. These both
                # re-invoke this routine, causing a double build. So, ignore
                # both these signals.
                self._ignoreDocumentChanged = True
                self._ignoreTextChanges = True
                document.saveFile()
                self._ignoreDocumentChanged = False
                self._ignoreTextChanges = False
                if qp.cursorPosition != (lineNum, col):
                    # Mark this as one operation on the undo stack. To do so,
                    # enclose all editing operations in a context manager. See
                    # "Text modification and Undo/Redo" in the qutepart docs.
                    with qp:
                        qp.lines[lineNum] = lineText
                        qp.cursorPosition = lineNum, col
                    qp.document().setModified(False)
            # Build. Each line is one row in the table above.
            if ((not sphinxCanProcess)
                    or (sphinxCanProcess and not internallyModified)
                    or saveThenBuild):
                # Build the HTML in a separate thread.
                self._runLatest.start(self._setHtmlFuture, self.getHtml,
                                      language, text, document.filePath())
            # Warn.
            if (sphinxCanProcess and internallyModified and externallyModified
                    and not buildOnSave):
                core.mainWindow().appendMessage(
                    'Warning: file modified externally. Auto-save disabled.')
コード例 #4
0
ファイル: preview.py プロジェクト: gpa14/enki
    def _scheduleDocumentProcessing(self):
        """Start document processing with the thread.
        """
        if not self._programRunning:
            return

        if self.isHidden():
            return

        self._typingTimer.stop()

        document = core.workspace().currentDocument()
        if document is not None:
            if sphinxEnabledForFile(document.filePath()):
                self._copySphinxProjectTemplate(document.filePath())
            qp = document.qutepart
            language = qp.language()
            text = qp.text
            sphinxCanProcess = sphinxEnabledForFile(document.filePath())
            # Determine if we're in the middle of a build.
            currentlyBuilding = self._widget.prgStatus.text() == 'Building...'

            if language == 'Markdown':
                text = self._getCurrentTemplate() + text
                # Hide the progress bar, since processing is usually short and
                # Markdown produces no errors or warnings to display in the
                # progress bar. See https://github.com/bjones1/enki/issues/36.
                self._widget.prgStatus.setVisible(False)
                # Hide the error log, since Markdown never generates errors or
                # warnings.
                self._widget.teLog.setVisible(False)
            elif isHtmlFile(document):
                # No processing needed -- just display it.
                self._setHtml(document.filePath(), text)
                # Hide the progress bar, since no processing is necessary.
                self._widget.prgStatus.setVisible(False)
                # Hide the error log, since we do not HTML checking.
                self._widget.teLog.setVisible(False)
                return
            elif ((language == 'Restructured Text') or sphinxCanProcess or
                  canUseCodeChat(document.filePath())):
                # Show the progress bar and error log for reST, CodeChat, or
                # Sphinx builds. It will display progress (Sphinx only) and
                # errors/warnings (for all three).
                self._widget.prgStatus.setVisible(True)
                self._widget.teLog.setVisible(True)
                self._setHtmlProgress('Building...')

            # Determine whether to initiate a build or not. The underlying
            # logic:
            #
            # - If Sphinx can't process this file, just build it.
            # - If Sphinx can process this file:
            #
            #   - If the document isn't internally modified, we're here because
            #     the file was saved or the refresh button was pressed. Build it.
            #   - If the document was internally modified and "insta-build" is
            #     enabled (i.e. build only on save is disabled):
            #
            #     - If the document was not externally modified, then save and
            #       build.
            #     - If the document was externally modified, DANGER! The user
            #       needs to decide which file wins (external changes or
            #       internal changes). Don't save and build, since this would
            #       overwrite external modifications without the user realizing
            #       what happened. Instead, warn the user.
            #
            # As a table, see below. Build, Save, and Warn are the outputs; all
            # others are inputs.
            #
            # ==================  ===================  ===================  =============  =====  ====  ====
            # Sphinx can process  Internally modified  Externally modified  Build on Save  Build  Save  Warn
            # ==================  ===================  ===================  =============  =====  ====  ====
            # No                  X                    X                    X              Yes    No    No
            # Yes                 No                   X                    X              Yes    No    No
            # Yes                 Yes                  No                   No             Yes    Yes   No
            # Yes                 Yes                  Yes                  No             No     No    Yes
            # Yes                 Yes                  X                    Yes            No     No    No
            # ==================  ===================  ===================  =============  =====  ====  ====
            internallyModified = qp.document().isModified()
            externallyModified = document.isExternallyModified()
            buildOnSave = core.config()['Sphinx']['BuildOnSave']
            saveThenBuild = (sphinxCanProcess and internallyModified and
                             not externallyModified and not buildOnSave)
            # If Sphinx is currently building, don't autosave -- this can
            # cause Sphinx to miss changes on its next build. Instead, wait
            # until Sphinx completes, then do a save and build.
            if saveThenBuild and currentlyBuilding:
                self._rebuildNeeded = True
                saveThenBuild = False
            else:
                self._rebuildNeeded = False
            # Save first, if needed.
            if saveThenBuild:
                # If trailing whitespace strip changes the cursor position,
                # restore the whitespace and cursor position.
                lineNum, col = qp.cursorPosition
                lineText = qp.lines[lineNum]
                # Invoking saveFile when Strip Trailing whitespace is enabled
                # causes ``onTextChanged`` (due to whitespace strips) and
                # ``onDocumentChanged`` signals to be emitted. These both
                # re-invoke this routine, causing a double build. So, ignore
                # both these signals.
                self._ignoreDocumentChanged = True
                self._ignoreTextChanges = True
                document.saveFile()
                self._ignoreDocumentChanged = False
                self._ignoreTextChanges = False
                if qp.cursorPosition != (lineNum, col):
                    # Mark this as one operation on the undo stack. To do so,
                    # enclose all editing operations in a context manager. See
                    # "Text modification and Undo/Redo" in the qutepart docs.
                    with qp:
                        qp.lines[lineNum] = lineText
                        qp.cursorPosition = lineNum, col
                    qp.document().setModified(False)
            # Build. Each line is one row in the table above.
            if ((not sphinxCanProcess) or
                    (sphinxCanProcess and not internallyModified) or
                    saveThenBuild):
                # For reST language is already correct.
                self._thread.process(document.filePath(), language, text)
            # Warn.
            if (sphinxCanProcess and internallyModified and
                    externallyModified and not buildOnSave):
                core.mainWindow().appendMessage('Warning: file modified externally. Auto-save disabled.')