Exemple #1
0
 def onSphinxPath(self):
     """Set the Sphinx path to the current project path."""
     assert core.project().path()
     core.config()["Sphinx"]["ProjectPath"] = core.project().path()
     core.config().flush()
     if core.config()["Preview"]["Enabled"] and self._dock is not None:
         self._dock._scheduleDocumentProcessing()
Exemple #2
0
    def _updateMainWindowTitle(self):
        """Update window title after current project, document or it's modified state has been changed
        """
        projPath = core.project().path()
        if projPath is not None:
            homePath = os.path.expanduser("~" + os.sep)

            if projPath.startswith(homePath):
                projPath = os.path.relpath(projPath, homePath)

        document = self.currentDocument()
        if document:
            filePath = document.filePath()
            if filePath is None:
                filePath = 'untitled'
            elif core.project().path() is not None and \
                    filePath.startswith(core.project().path()):
                filePath = os.path.relpath(filePath, core.project().path())

            if document.qutepart.document().isModified():
                filePath += '*'
        else:
            filePath = None

        if projPath is not None and filePath is not None:
            title = u'{} - {}'.format(projPath, filePath)
        elif projPath is not None:
            title = projPath
        elif filePath is not None:
            title = filePath
        else:
            title = 'Enki v.{}'.format(enki.core.defines.PACKAGE_VERSION)

        self._mainWindow().setWindowTitle(title)
Exemple #3
0
    def _onRestoreSession(self):
        """Enki initialisation finished.
        Now restore session
        """
        # if have documents except 'untitled' new doc, don't restore session
        if core.workspace().currentDocument() is not None:
            return

        if not os.path.exists(_SESSION_FILE_PATH):
            return

        session = enki.core.json_wrapper.load(_SESSION_FILE_PATH, 'session', None)

        if session is not None:
            for filePath in session['opened']:
                if os.path.exists(filePath):
                    core.workspace().openFile(filePath)

            if session['current'] is not None:
                document = self._documentForPath(session['current'])
                if document is not None:  # document might be already deleted
                    core.workspace().setCurrentDocument(document)

            if 'project' in session:
                path = session['project']
                if path is not None and os.path.isdir(path):
                    core.project().open(path)
Exemple #4
0
    def test_03(self):
        """ Upper case files are opened """
        core.project().open(PROJ_ROOT)  # not scanned yet

        self.openDialog(self._openDialog, lambda d: self._enter(d, 'uisetui'))

        path = os.path.join(PROJ_ROOT, 'ui', 'UISettings.ui')
        self.assertEqual(core.workspace().currentDocument().filePath(), path)
Exemple #5
0
    def _onProjectOpenTriggered(self):
        """Handler of File->Open Project
        """
        dirPath = QFileDialog.getExistingDirectory(
            core.mainWindow(), "Classic open project dialog. Main menu -> Navigation -> Locator is better")

        if dirPath:
            core.project().open(dirPath)
    def test_09(self):
        """ Open .. """
        core.project().open(PROJ_ROOT)

        def inDialogFunc(dialog):
            self.keyClicks('p ..')
            self.keyClick(Qt.Key_Enter)
        self.openDialog(self._openDialog, inDialogFunc)
        self.assertEqual(core.project().path(), os.path.dirname(PROJ_ROOT))
    def test_10(self):
        """ Open ./ """
        core.project().open(PROJ_ROOT)

        def inDialogFunc(dialog):
            self.keyClicks('p ./core')
            self.keyClick(Qt.Key_Enter)
        self.openDialog(self._openDialog, inDialogFunc)
        self.assertEqual(core.project().path(), os.path.join(PROJ_ROOT, 'core'))
    def test_08(self):
        """ Open project """
        core.project().open(os.path.dirname(self.TEST_FILE_DIR))

        self.assertNotEqual(core.project().path(), self.TEST_FILE_DIR)

        def inDialogFunc(dialog):
            self.keyClicks('p ' + self.TEST_FILE_DIR.replace('\\', '\\\\'))
            self.keyClick(Qt.Key_Enter)

        self.openDialog(self._openDialog, inDialogFunc)

        self.assertEqual(core.project().path(), self.TEST_FILE_DIR)
Exemple #9
0
    def test_05(self):
        """ scan """
        core.project().open(PROJ_ROOT)  # not scanned yet

        def inDialogFunc(dialog):
            self.keyClicks('scan')
            self.keyClick(Qt.Key_Enter)

        self.openDialog(self._openDialog, inDialogFunc)

        self.assertTrue(core.project().isScanning())
        self._waitFiles()
        self.assertFalse(core.project().isScanning())
Exemple #10
0
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)
        core.workspace().languageChanged.connect(self._onDocumentChanged)

        # Install our CodeChat page into the settings dialog.
        core.uiSettingsManager().aboutToExecute.connect(self._onSettingsDialogAboutToExecute)
        # Update preview dock when the settings dialog (which contains the
        # CodeChat enable checkbox) is changed.
        core.uiSettingsManager().dialogAccepted.connect(self._onDocumentChanged)

        # Provide a "Set Sphinx Path" menu item.
        core.uiSettingsManager().dialogAccepted.connect(self._setSphinxActionVisibility)
        self._sphinxAction = QAction('Set Sphinx path', self._dock)
        self._sphinxAction.setShortcut(QKeySequence('Alt+Shift+S'))
        core.actionManager().addAction('mTools/aSetSphinxPath',
                                       self._sphinxAction)
        self._sphinxAction.triggered.connect(self.onSphinxPath)
        # Only enable this command if the File browser has a valid path.
        self.onFileBrowserPathChanged()
        core.project().changed.connect(self.onFileBrowserPathChanged)

        # If user's config .json file lacks it, populate CodeChat's default
        # config key and Sphinx's default config key.
        if not 'CodeChat' in core.config():
            core.config()['CodeChat'] = {}
            core.config()['CodeChat']['Enabled'] = False
            core.config().flush()
        if not 'Sphinx' in core.config():
            core.config()['Sphinx'] = {}
            core.config()['Sphinx']['Enabled'] = False
            core.config()['Sphinx']['Executable'] = 'sphinx-build'
            core.config()['Sphinx']['ProjectPath'] = ''
            core.config()['Sphinx']['BuildOnSave'] = False
            core.config()['Sphinx']['OutputPath'] = os.path.join('_build',
                                                                 'html')
            core.config()['Sphinx']['AdvancedMode'] = False
            core.config()['Sphinx']['Cmdline'] = ('sphinx-build -d ' +
                                                  os.path.join('_build', 'doctrees') + ' . ' +
                                                  os.path.join('_build', 'html'))
            core.config().flush()

        self._setSphinxActionVisibility()
Exemple #11
0
    def test_02(self):
        """ Open mainwindow.py (second choice) """
        core.project().open(PROJ_ROOT)  # not scanned yet

        def inDialogFunc(dialog):
            self.keyClicks('cowo')
            self._waitFiles()
            self._waitCompletion(dialog)
            self.keyClick(Qt.Key_Down)
            self.keyClick(Qt.Key_Enter)

        self.openDialog(self._openDialog, inDialogFunc)

        path = os.path.join(PROJ_ROOT, 'core', 'mainwindow.py')
        self.assertEqual(core.workspace().currentDocument().filePath(), path)
Exemple #12
0
    def _createUi(self):
        self.setWindowTitle(core.project().path().replace(os.sep, '/') or 'Locator')

        self.setLayout(QVBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.layout().setSpacing(1)

        biggerFont = self.font()
        biggerFont.setPointSizeF(biggerFont.pointSizeF() * 2)
        self.setFont(biggerFont)

        self._edit = _CompletableLineEdit(self)
        self._edit.updateCurrentCommand.connect(self._updateCurrentCommand)
        self._edit.enterPressed.connect(self._onEnterPressed)
        self._edit.installEventFilter(self)  # catch Up, Down
        self._edit.setFont(biggerFont)
        self.layout().addWidget(self._edit)
        self.setFocusProxy(self._edit)

        self._table = QTreeView(self)
        self._table.setFont(biggerFont)
        self._model = _CompleterModel()
        self._table.setModel(self._model)
        self._table.setItemDelegate(HTMLDelegate(self._table))
        self._table.setRootIsDecorated(False)
        self._table.setHeaderHidden(True)
        self._table.clicked.connect(self._onItemClicked)
        self._table.setAlternatingRowColors(True)
        self._table.installEventFilter(self)  # catch focus and give to the edit
        self.layout().addWidget(self._table)

        width = QFontMetrics(self.font()).width('x' * 64)  # width of 64 'x' letters
        self.resize(width, width * 0.62)
Exemple #13
0
 def execute(self):
     path = self._clickedPath
     fullPath = os.path.join(core.project().path(), path)
     if self._line is None:
         core.workspace().goTo(fullPath)
     else:
         core.workspace().goTo(fullPath, line=self._line - 1)
Exemple #14
0
 def _waitFiles(self):
     for _ in range(20):
         QTest.qWait(5000 / 20)
         if core.project().files() is not None:
             break
     else:
         self.fail("Project not scanned")
Exemple #15
0
    def test_1(self):
        """ Parse words
        """
        proj = core.project()

        self.assertEqual(proj.files(), None)

        proj.open(PROJ_ROOT)
        self.assertEqual(proj.path(), PROJ_ROOT)
        self.assertEqual(proj.files(), None)

        proj.startLoadingFiles()
        proj.startLoadingFiles()
        proj.cancelLoadingFiles()
        proj.cancelLoadingFiles()
        self.assertEqual(proj.files(), None)

        proj.startLoadingFiles()
        self.waitUntilPassed(5000, lambda: self.assertIsNotNone(proj.files()))

        corepy = [path for path in proj.files() if path.endswith('core.py')]
        self.assertEqual(len(corepy), 1)

        newPath = os.path.dirname(PROJ_ROOT)
        proj.open(newPath)
        self.assertEqual(proj.path(), newPath)
        self.assertEqual(proj.files(), None)
Exemple #16
0
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)  # Disconnected.
        core.workspace().languageChanged.connect(self._onDocumentChanged)  # Disconnected.

        # Install our CodeChat page into the settings dialog.
        core.uiSettingsManager().aboutToExecute.connect(self._onSettingsDialogAboutToExecute)  # Disconnected.
        # Update preview dock when the settings dialog (which contains the
        # CodeChat enable checkbox) is changed.
        core.uiSettingsManager().dialogAccepted.connect(self._onDocumentChanged)  # Disconnected.

        # Provide a "Set Sphinx Path" menu item.
        core.uiSettingsManager().dialogAccepted.connect(self._setSphinxActionVisibility)
        self._sphinxAction = QAction("Set Sphinx path", self._dock)
        self._sphinxAction.setShortcut(QKeySequence("Alt+Shift+S"))
        core.actionManager().addAction("mTools/aSetSphinxPath", self._sphinxAction)
        self._sphinxAction.triggered.connect(self.onSphinxPath)
        # Only enable this command if the File browser has a valid path.
        self.onFileBrowserPathChanged()
        core.project().changed.connect(self.onFileBrowserPathChanged)

        # If user's config .json file lacks it, populate CodeChat's default
        # config key and Sphinx's default config key.
        if not "CodeChat" in core.config():
            core.config()["CodeChat"] = {}
            core.config()["CodeChat"]["Enabled"] = False
            core.config().flush()
        if not "Sphinx" in core.config():
            core.config()["Sphinx"] = {}
            core.config()["Sphinx"]["Enabled"] = False
            core.config()["Sphinx"]["Executable"] = "sphinx-build"
            core.config()["Sphinx"]["ProjectPath"] = ""
            core.config()["Sphinx"]["BuildOnSave"] = False
            core.config()["Sphinx"]["OutputPath"] = os.path.join("_build", "html")
            core.config()["Sphinx"]["AdvancedMode"] = False
            core.config()["Sphinx"]["Cmdline"] = (
                "sphinx-build -d " + os.path.join("_build", "doctrees") + " . " + os.path.join("_build", "html")
            )
            core.config().flush()

        self._setSphinxActionVisibility()
Exemple #17
0
    def __init__(self, parent):
        DockWidget.__init__(self, parent, "&File Browser", QIcon(':/enkiicons/open.png'), "Alt+F")

        self._comboBox = None
        self._tree = None
        self._smartRecents = None
        self._smartHistory = None

        # restrict areas
        self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)

        core.actionManager().addAction("mView/aFileBrowser", self.showAction())

        core.mainWindow().directoryDropt.connect(self._onDirectoryDropt)
        core.project().changed.connect(self.setCurrentPath)

        self.visibilityChanged.connect(self._onVisibilityChanged)
Exemple #18
0
    def setCurrentPath(self, path):
        """Set current path (root of the tree)
        If there are no documents on workspace, also changes process current directory
        """
        if self._tree is None:
            return

        if self._tree.currentPath() == path:
            return

        self._tree.setCurrentPath(path)
        self._tree.setFocus()

        # set lineedit path
        self._comboBox.setToolTip(path)

        # notify SmartRecents and own slots
        self.rootChanged.emit(path)

        core.project().open(path)
Exemple #19
0
    def _openFiles(self):
        files = [d.filePath()
                 for d in core.workspace().documents()
                 if d.filePath() is not None]
        projPath = core.project().path()
        if projPath:
            for i, path in enumerate(files):
                if files[i].startswith(projPath):
                    files[i] = os.path.relpath(path, projPath)

        return files
Exemple #20
0
    def terminate(self):
        """Uninstall the plugin
        """
        core.actionManager().removeAction("mTools/aSetSphinxPath")
        core.project().changed.disconnect(self.onFileBrowserPathChanged)

        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.terminate()

        core.workspace().currentDocumentChanged.disconnect(self._onDocumentChanged)
        core.workspace().languageChanged.disconnect(self._onDocumentChanged)
        core.uiSettingsManager().aboutToExecute.disconnect(self._onSettingsDialogAboutToExecute)
        core.uiSettingsManager().dialogAccepted.disconnect(self._onDocumentChanged)
        if self._dock:
            self._dock.closed.disconnect(self._onDockClosed)
            self._dock.shown.disconnect(self._onDockShown)
            self._saveAction.triggered.disconnect(self._dock.onPreviewSave)
Exemple #21
0
    def setCurrentPath(self, path):
        """Set current path (root of the tree)
        If there are no documents on workspace, also changes process current directory
        """
        if self._tree is None:
            return

        if self._tree.currentPath() == path:
            return

        self._tree.setCurrentPath(path)
        self._tree.setFocus()

        # set lineedit path
        self._comboBox.setToolTip(path)

        # notify SmartRecents and own slots
        self.rootChanged.emit(path)

        core.project().open(path)
Exemple #22
0
    def __init__(self, mainWindow):
        """ list of opened documents as it is displayed in the Opened Files Explorer.
        List accessed and modified by enki.core.openedfilemodel.OpenedFileModel class
        """
        QStackedWidget.__init__(self, mainWindow)
        mainWindow.setFocusProxy(self)

        self.sortedDocuments = []  # not protected, because available for OpenedFileModel
        self._oldCurrentDocument = None

        # create opened files explorer
        # openedFileExplorer is not protected, because it is available for OpenedFileModel
        self.openedFileExplorer = enki.core.openedfilemodel.OpenedFileExplorer(self)
        mainWindow.addDockWidget(Qt.LeftDockWidgetArea, self.openedFileExplorer)

        self.currentChanged.connect(self._onStackedLayoutIndexChanged)

        self.currentDocumentChanged.connect(self._updateMainWindowTitle)
        core.project().changed.connect(self._updateMainWindowTitle)
        self.currentDocumentChanged.connect(self._onCurrentDocumentChanged)
Exemple #23
0
    def _openFiles(self):
        files = [
            d.filePath() for d in core.workspace().documents()
            if d.filePath() is not None
        ]
        projPath = core.project().path()
        if projPath:
            for i, path in enumerate(files):
                if files[i].startswith(projPath):
                    files[i] = os.path.relpath(path, projPath)

        return files
Exemple #24
0
    def setArgs(self, args):
        if len(args) > 1:
            raise InvalidCmdArgs()

        if args:
            path = args[0]
            if path.startswith('./') or path.startswith('../') \
               or path in ('.', '..'):
                path = os.path.join(core.project().path(), path)

            self._path = path
        else:
            self._path = None
Exemple #25
0
    def terminate(self):
        """Uninstall the plugin
        """
        core.actionManager().removeAction('mTools/aSetSphinxPath')
        core.project().changed.disconnect(self.onFileBrowserPathChanged)

        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.terminate()

        core.workspace().currentDocumentChanged.disconnect(self._onDocumentChanged)
        core.workspace().languageChanged.disconnect(self._onDocumentChanged)
        core.uiSettingsManager().aboutToExecute.disconnect(
            self._onSettingsDialogAboutToExecute)
        core.uiSettingsManager().dialogAccepted.disconnect(
            self._onDocumentChanged)
        if self._dock:
            self._dock.closed.disconnect(self._onDockClosed)
            self._dock.shown.disconnect(self._onDockShown)
            self._saveAction.triggered.disconnect(self._dock.onPreviewSave)
Exemple #26
0
    def setArgs(self, args):
        if len(args) > 1:
            raise InvalidCmdArgs()

        if args:
            path = args[0]
            if path.startswith('./') or path.startswith('../') \
               or path in ('.', '..'):
                path = os.path.join(core.project().path(), path)

            self._path = path
        else:
            self._path = None
Exemple #27
0
    def __init__(self):
        AbstractCommand.__init__(self)
        self._completer = None
        self._clickedPath = None

        core.project().filesReady.connect(self.updateCompleter)
        core.project().scanStatusChanged.connect(self.updateCompleter)
        if not core.project().isScanning():
            core.project().startLoadingFiles()
            self._iHaveStartedScan = True
        else:
            self._iHaveStartedScan = False
Exemple #28
0
    def __init__(self):
        AbstractCommand.__init__(self)
        self._completer = None
        self._clickedPath = None

        core.project().filesReady.connect(self.updateCompleter)
        core.project().scanStatusChanged.connect(self.updateCompleter)
        if not core.project().isScanning():
            core.project().startLoadingFiles()
            self._iHaveStartedScan = True
        else:
            self._iHaveStartedScan = False
Exemple #29
0
    def _initialize(self):
        """Delayed initialization of the widget for quicker start of application
        """
        # central widget
        wdg = QWidget(self)
        self.setWidget(wdg)

        # vertical layout
        vertLayout = QVBoxLayout(wdg)
        vertLayout.setContentsMargins(0, 0, 0, 0)
        vertLayout.setSpacing(3)

        # combo
        self._comboBox = ComboBox(self)
        vertLayout.addWidget(self._comboBox)

        # hline
        hline = QFrame(self)
        hline.setFrameStyle(QFrame.HLine | QFrame.Sunken)
        vertLayout.addWidget(hline)

        # files view
        self._tree = Tree(self)
        vertLayout.addWidget(self._tree)

        # cd up button
        self._aCdUp = QAction(QIcon(':enkiicons/go-up.png'),
                              self.tr("Up"),
                              self)
        self.titleBarWidget().addAction(self._aCdUp)
        self._aCdUp.triggered.connect(self.moveUp)

        # redirirect focus proxy
        self.setFocusProxy(self._tree)

        self._smartRecents = SmartRecents(self)
        self._smartHistory = SmartHistory(self)

        self.setCurrentPath(core.project().path() or _getCurDir())
        core.actionManager().action('mNavigation/mFileBrowser').setVisible(True)
Exemple #30
0
    def _createUi(self):
        self.setWindowTitle(core.project().path().replace(os.sep, '/')
                            or 'Locator')

        self.setLayout(QVBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.layout().setSpacing(1)

        biggerFont = self.font()
        biggerFont.setPointSizeF(biggerFont.pointSizeF() * 2)
        self.setFont(biggerFont)

        self._edit = _CompletableLineEdit(self)
        self._edit.updateCurrentCommand.connect(self._updateCurrentCommand)
        self._edit.enterPressed.connect(self._onEnterPressed)
        self._edit.installEventFilter(self)  # catch Up, Down
        self._edit.setFont(biggerFont)
        self.layout().addWidget(self._edit)
        self.setFocusProxy(self._edit)

        self._table = QTreeView(self)
        self._table.setFont(biggerFont)
        self._model = _CompleterModel()
        self._table.setModel(self._model)
        self._table.setItemDelegate(HTMLDelegate(self._table))
        self._table.setRootIsDecorated(False)
        self._table.setHeaderHidden(True)
        self._table.clicked.connect(self._onItemClicked)
        self._table.setAlternatingRowColors(True)
        self._table.installEventFilter(
            self)  # catch focus and give to the edit
        self.layout().addWidget(self._table)

        width = QFontMetrics(self.font()).width('x' *
                                                64)  # width of 64 'x' letters
        self.resize(width, width * 0.62)
Exemple #31
0
    def _saveSession(self, showWarnings=True):
        """Enki is going to be terminated.
        Save session
        """
        fileList = [document.filePath()
                    for document in core.workspace().documents()
                    if document.filePath() is not None and
                    os.path.exists(document.filePath()) and
                    '/.git/' not in document.filePath() and
                    not (document.fileName().startswith('svn-commit') and
                         document.fileName().endswith('.tmp'))]

        if not fileList:
            return

        currentPath = None
        if core.workspace().currentDocument() is not None:
            currentPath = core.workspace().currentDocument().filePath()

        session = {'current': currentPath,
                   'opened': fileList,
                   'project': core.project().path()}

        enki.core.json_wrapper.dump(_SESSION_FILE_PATH, 'session', session, showWarnings)
Exemple #32
0
 def onFileBrowserPathChanged(self):
     """Enable the onSphinxPath command only when there's a valid project
        path."""
     self._sphinxAction.setEnabled(bool(core.project().path()))
Exemple #33
0
 def setUp(self):
     base.TestCase.setUp(self)
     core.project().open(PROJ_ROOT)  # not scanned yet
Exemple #34
0
    def terminate(self):
        if self._iHaveStartedScan:
            core.project().cancelLoadingFiles()

        core.project().filesReady.disconnect(self.updateCompleter)
        core.project().scanStatusChanged.disconnect(self.updateCompleter)
Exemple #35
0
 def execute(self):
     """Execute the command
     """
     core.project().open(self._fullPath())
Exemple #36
0
 def terminate(self):
     """Terminate workspace. Called by the core to clear actions
     """
     self.forceCloseAllDocuments()
     self.openedFileExplorer.terminate()
     core.project().changed.disconnect(self._updateMainWindowTitle)
Exemple #37
0
 def execute(self):
     core.project().startBackgroundScan()
Exemple #38
0
 def setUp(self):
     base.TestCase.setUp(self)
     core.project().open(PROJ_ROOT)  # not scanned yet
Exemple #39
0
 def execute(self):
     """Execute the command
     """
     core.project().open(self._fullPath())
Exemple #40
0
 def completer(self):
     if core.project().files() is not None:
         return FuzzyOpenCompleter(self._pattern, core.project().files())
     else:
         return StatusCompleter("<i>{}</i>".format(
             core.project().scanStatus()))
Exemple #41
0
 def execute(self):
     core.project().startBackgroundScan()
Exemple #42
0
 def terminate(self):
     """Terminate workspace. Called by the core to clear actions
     """
     self.forceCloseAllDocuments()
     self.openedFileExplorer.terminate()
     core.project().changed.disconnect(self._updateMainWindowTitle)
Exemple #43
0
 def onFileBrowserPathChanged(self):
     """Enable the onSphinxPath command only when there's a valid project
        path."""
     self._sphinxAction.setEnabled(bool(core.project().path()))
Exemple #44
0
 def isAvailable():
     return core.project().path() is not None