Beispiel #1
0
    def _createDock(self):
        self._dock = NavigatorDock()
        self._dock.setVisible(False)
        self._dock.shown.connect(self._onDockShown)
        self._dock.closed.connect(self._onDockClosed)

        self._thread.tagsReady.connect(self._dock.setTags)
        self._thread.error.connect(self._dock.onError)
Beispiel #2
0
    def _createDock(self):
        self._dock = NavigatorDock()
        self._dock.setVisible(False)
        self._dock.shown.connect(self._onDockShown)
        self._dock.closed.connect(self._onDockClosed)

        self._thread.tagsReady.connect(self._dock.setTags)
        self._thread.error.connect(self._dock.onError)
Beispiel #3
0
class Plugin(QObject):
    """Main class. Interface for the core.
    """
    def __init__(self):
        QObject.__init__(self)
        self._dock = None
        core.workspace().currentDocumentChanged.connect(
            self._onDocumentChanged)
        core.workspace().textChanged.connect(self._onTextChanged)

        core.uiSettingsManager().aboutToExecute.connect(
            self._onSettingsDialogAboutToExecute)
        core.uiSettingsManager().dialogAccepted.connect(
            self._scheduleDocumentProcessing)

        # If we update Tree on every key pressing, freezes are sensible (GUI thread draws tree too slowly
        # This timer is used for drawing Preview 1000 ms After user has stopped typing text
        self._typingTimer = QTimer()
        self._typingTimer.setInterval(1000)
        self._typingTimer.setSingleShot(True)
        self._typingTimer.timeout.connect(self._scheduleDocumentProcessing)

        self._thread = ProcessorThread()

    def del_(self):
        """Uninstall the plugin
        """
        if self._dock is not None:
            self._thread.tagsReady.disconnect(self._dock.setTags)
            self._thread.error.disconnect(self._dock.onError)
            self._dock.remove()
        self._typingTimer.stop()
        self._thread.stopAsync()
        self._thread.wait()

    def _createDock(self):
        self._dock = NavigatorDock()
        self._dock.setVisible(False)
        self._dock.shown.connect(self._onDockShown)
        self._dock.closed.connect(self._onDockClosed)

        self._thread.tagsReady.connect(self._dock.setTags)
        self._thread.error.connect(self._dock.onError)

    def _isEnabled(self):
        return core.config()['Navigator']['Enabled']

    def _isSupported(self, document):
        return document is not None and \
               document.qutepart.language() in _QUTEPART_TO_CTAGS_LANG_MAP

    def _onDockClosed(self):
        """Dock has been closed by a user. Change Enabled option
        """
        if core.config()['Navigator']['Enabled']:
            core.config()['Navigator']['Enabled'] = False
            core.config().flush()
            self._dock.setTags([])

    def _onDockShown(self):
        """Dock has been shown by a user. Change Enabled option
        """
        if not core.config()['Navigator']['Enabled']:
            core.config()['Navigator']['Enabled'] = True
            core.config().flush()
            self._scheduleDocumentProcessing()

    def _onDocumentChanged(self, old, new):
        if self._isSupported(new):
            if self._dock is None:
                self._createDock()
            self._dock.install()
            if self._isEnabled():
                self._dock.show()
                self._scheduleDocumentProcessing()
        else:
            self._clear()
            if self._dock is not None:
                self._dock.remove()

    def _onTextChanged(self):
        if self._isEnabled():
            self._typingTimer.stop()
            self._typingTimer.start()

    def _clear(self):
        if self._dock is not None:
            self._dock.setTags([])

    def _scheduleDocumentProcessing(self):
        """Start document processing with the thread.
        """
        self._typingTimer.stop()

        document = core.workspace().currentDocument()
        if document is not None and \
           document.qutepart.language() in _QUTEPART_TO_CTAGS_LANG_MAP:
            ctagsLang = _QUTEPART_TO_CTAGS_LANG_MAP[
                document.qutepart.language()]
            self._thread.process(
                ctagsLang, document.qutepart.text,
                core.config()['Navigator']['SortAlphabetically'])

    def _onSettingsDialogAboutToExecute(self, dialog):
        """UI settings dialogue is about to execute.
        Add own options
        """
        widget = SettingsWidget(dialog)

        dialog.appendPage(u"Navigator", widget, QIcon(':/enkiicons/goto.png'))

        # Options
        dialog.appendOption(
            TextOption(dialog, core.config(), "Navigator/CtagsPath",
                       widget.leCtagsPath))
        dialog.appendOption(
            CheckableOption(dialog, core.config(),
                            "Navigator/SortAlphabetically",
                            widget.cbSortTagsAlphabetically))
Beispiel #4
0
class Plugin(QObject):
    """Main class. Interface for the core.
    """
    def __init__(self):
        QObject.__init__(self)
        self._dock = None
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)
        core.workspace().textChanged.connect(self._onTextChanged)

        core.uiSettingsManager().aboutToExecute.connect(self._onSettingsDialogAboutToExecute)
        core.uiSettingsManager().dialogAccepted.connect(self._scheduleDocumentProcessing)

        # If we update Tree on every key pressing, freezes are sensible (GUI thread draws tree too slowly
        # This timer is used for drawing Preview 1000 ms After user has stopped typing text
        self._typingTimer = QTimer()
        self._typingTimer.setInterval(1000)
        self._typingTimer.setSingleShot(True)
        self._typingTimer.timeout.connect(self._scheduleDocumentProcessing)

        self._thread = ProcessorThread()

    def del_(self):
        """Uninstall the plugin
        """
        if self._dock is not None:
            self._thread.tagsReady.disconnect(self._dock.setTags)
            self._thread.error.disconnect(self._dock.onError)
            self._dock.remove()
        self._typingTimer.stop()
        self._thread.stopAsync()
        self._thread.wait()

    def _createDock(self):
        self._dock = NavigatorDock()
        self._dock.setVisible(False)
        self._dock.shown.connect(self._onDockShown)
        self._dock.closed.connect(self._onDockClosed)

        self._thread.tagsReady.connect(self._dock.setTags)
        self._thread.error.connect(self._dock.onError)

    def _isEnabled(self):
        return core.config()['Navigator']['Enabled']

    def _isSupported(self, document):
        return document is not None and \
               document.qutepart.language() in _QUTEPART_TO_CTAGS_LANG_MAP

    def _onDockClosed(self):
        """Dock has been closed by a user. Change Enabled option
        """
        if core.config()['Navigator']['Enabled']:
            core.config()['Navigator']['Enabled'] = False
            core.config().flush()
            self._dock.setTags([])

    def _onDockShown(self):
        """Dock has been shown by a user. Change Enabled option
        """
        if not core.config()['Navigator']['Enabled']:
            core.config()['Navigator']['Enabled'] = True
            core.config().flush()
            self._scheduleDocumentProcessing()

    def _onDocumentChanged(self, old, new):
        if self._isSupported(new):
            if self._dock is None:
                self._createDock()
            self._dock.install()
            if self._isEnabled():
                self._dock.show()
                self._scheduleDocumentProcessing()
        else:
            self._clear()
            if self._dock is not None:
                self._dock.remove()

    def _onTextChanged(self):
        if self._isEnabled():
            self._typingTimer.stop()
            self._typingTimer.start()

    def _clear(self):
        if self._dock is not None:
            self._dock.setTags([])

    def _scheduleDocumentProcessing(self):
        """Start document processing with the thread.
        """
        self._typingTimer.stop()

        document = core.workspace().currentDocument()
        if document is not None and \
           document.qutepart.language() in _QUTEPART_TO_CTAGS_LANG_MAP:
            ctagsLang = _QUTEPART_TO_CTAGS_LANG_MAP[document.qutepart.language()]
            self._thread.process(ctagsLang, document.qutepart.text,
                                 core.config()['Navigator']['SortAlphabetically'])

    def _onSettingsDialogAboutToExecute(self, dialog):
        """UI settings dialogue is about to execute.
        Add own options
        """
        widget = SettingsWidget(dialog)

        dialog.appendPage(u"Navigator", widget, QIcon(':/enkiicons/goto.png'))

        # Options
        dialog.appendOption(TextOption(dialog, core.config(),
                                       "Navigator/CtagsPath", widget.leCtagsPath))
        dialog.appendOption(CheckableOption(dialog, core.config(),
                                            "Navigator/SortAlphabetically",
                                            widget.cbSortTagsAlphabetically))