Пример #1
0
    def __fillApisList(self):
        """
        Private slot to fill the list of API files.
        """
        self.apis[self.__apiKey(
            self.__currentApiLanguage,
            self.__currentApiProjectType)] = self.__editorGetApisFromApiList()

        self.__currentApiLanguage = self.apiLanguageComboBox.currentText()
        self.__currentApiProjectType = self.projectTypeComboBox.itemData(
            self.projectTypeComboBox.currentIndex())
        self.apiList.clear()

        if not self.__currentApiLanguage:
            self.apiGroup.setEnabled(False)
            return

        self.apiGroup.setEnabled(True)
        self.deleteApiFileButton.setEnabled(False)
        self.addApiFileButton.setEnabled(False)
        self.apiFilePicker.clear()

        key = self.__apiKey(self.__currentApiLanguage,
                            self.__currentApiProjectType)
        if key not in self.apis:
            # populate on demand
            self.apis[key] = Preferences.getEditorAPI(
                self.__currentApiLanguage,
                projectType=self.__currentApiProjectType)[:]
        for api in self.apis[key]:
            if api:
                self.apiList.addItem(api)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

        from QScintilla.APIsManager import APIsManager
        self.__currentAPI = APIsManager().getAPIs(
            self.__currentApiLanguage,
            projectType=self.__currentApiProjectType)
        if self.__currentAPI is not None:
            self.__currentAPI.apiPreparationFinished.connect(
                self.__apiPreparationFinished)
            self.__currentAPI.apiPreparationCancelled.connect(
                self.__apiPreparationCancelled)
            self.__currentAPI.apiPreparationStarted.connect(
                self.__apiPreparationStarted)
            self.addInstalledApiFileButton.setEnabled(
                len(self.__currentAPI.installedAPIFiles()) > 0)
        else:
            self.addInstalledApiFileButton.setEnabled(False)

        self.addPluginApiFileButton.setEnabled(
            len(self.pluginManager.getPluginApiFiles(
                self.__currentApiLanguage)) > 0)
Пример #2
0
    def __init__(self):
        """
        Constructor
        """
        ConfigurationPageBase.__init__(self)
        self.setupUi(self)
        self.setObjectName("EditorAPIsPage")

        self.prepareApiButton.setText(self.trUtf8("Compile APIs"))
        self.__apisManager = APIsManager()
        self.__currentAPI = None
        self.__inPreparation = False

        self.apiFileCompleter = E4FileCompleter(self.apiFileEdit)

        # set initial values
        self.pluginManager = e4App().getObject("PluginManager")
        self.apiAutoPrepareCheckBox.setChecked(Preferences.getEditor("AutoPrepareAPIs"))

        self.apis = {}
        apiLanguages = [""] + QScintilla.Lexers.getSupportedLanguages().keys()
        apiLanguages.sort()
        for lang in apiLanguages:
            if lang != "Guessed":
                self.apiLanguageComboBox.addItem(lang)
        self.currentApiLanguage = QString("")
        self.on_apiLanguageComboBox_activated(self.currentApiLanguage)

        for lang in apiLanguages[1:]:
            self.apis[lang] = QStringList(Preferences.getEditorAPI(lang))
Пример #3
0
    def on_apiLanguageComboBox_activated(self, language):
        """
        Private slot to fill the api listbox of the api page.
        
        @param language selected API language (string)
        """
        if self.currentApiLanguage == language:
            return

        self.apis[self.currentApiLanguage] = self.__editorGetApisFromApiList()
        self.currentApiLanguage = language
        self.apiList.clear()

        if not language:
            self.apiGroup.setEnabled(False)
            return

        self.apiGroup.setEnabled(True)
        self.deleteApiFileButton.setEnabled(False)
        self.addApiFileButton.setEnabled(False)
        self.apiFileEdit.clear()

        for api in self.apis[self.currentApiLanguage]:
            if api:
                self.apiList.addItem(api)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

        from QScintilla.APIsManager import APIsManager
        self.__currentAPI = APIsManager().getAPIs(self.currentApiLanguage)
        if self.__currentAPI is not None:
            self.__currentAPI.apiPreparationFinished.connect(
                self.__apiPreparationFinished)
            self.__currentAPI.apiPreparationCancelled.connect(
                self.__apiPreparationCancelled)
            self.__currentAPI.apiPreparationStarted.connect(
                self.__apiPreparationStarted)
            self.addInstalledApiFileButton.setEnabled(
                len(self.__currentAPI.installedAPIFiles()) > 0)
        else:
            self.addInstalledApiFileButton.setEnabled(False)

        self.addPluginApiFileButton.setEnabled(
            len(self.pluginManager.getPluginApiFiles(self.currentApiLanguage))
            > 0)
Пример #4
0
 def on_apiLanguageComboBox_activated(self, language):
     """
     Private slot to fill the api listbox of the api page.
     
     @param language selected API language (string)
     """
     if self.currentApiLanguage == language:
         return
         
     self.apis[self.currentApiLanguage] = self.__editorGetApisFromApiList()
     self.currentApiLanguage = language
     self.apiList.clear()
     
     if not language:
         self.apiGroup.setEnabled(False)
         return
         
     self.apiGroup.setEnabled(True)
     self.deleteApiFileButton.setEnabled(False)
     self.addApiFileButton.setEnabled(False)
     self.apiFilePicker.clear()
     
     for api in self.apis[self.currentApiLanguage]:
         if api:
             self.apiList.addItem(api)
     self.prepareApiButton.setEnabled(self.apiList.count() > 0)
     
     from QScintilla.APIsManager import APIsManager
     self.__currentAPI = APIsManager().getAPIs(self.currentApiLanguage)
     if self.__currentAPI is not None:
         self.__currentAPI.apiPreparationFinished.connect(
             self.__apiPreparationFinished)
         self.__currentAPI.apiPreparationCancelled.connect(
             self.__apiPreparationCancelled)
         self.__currentAPI.apiPreparationStarted.connect(
             self.__apiPreparationStarted)
         self.addInstalledApiFileButton.setEnabled(
             len(self.__currentAPI.installedAPIFiles()) > 0)
     else:
         self.addInstalledApiFileButton.setEnabled(False)
     
     self.addPluginApiFileButton.setEnabled(
         len(self.pluginManager.getPluginApiFiles(self.currentApiLanguage))
         > 0)
Пример #5
0
class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage):
    """
    Class implementing the Editor APIs configuration page.
    """

    def __init__(self):
        """
        Constructor
        """
        ConfigurationPageBase.__init__(self)
        self.setupUi(self)
        self.setObjectName("EditorAPIsPage")

        self.prepareApiButton.setText(self.trUtf8("Compile APIs"))
        self.__apisManager = APIsManager()
        self.__currentAPI = None
        self.__inPreparation = False

        self.apiFileCompleter = E4FileCompleter(self.apiFileEdit)

        # set initial values
        self.pluginManager = e4App().getObject("PluginManager")
        self.apiAutoPrepareCheckBox.setChecked(Preferences.getEditor("AutoPrepareAPIs"))

        self.apis = {}
        apiLanguages = [""] + QScintilla.Lexers.getSupportedLanguages().keys()
        apiLanguages.sort()
        for lang in apiLanguages:
            if lang != "Guessed":
                self.apiLanguageComboBox.addItem(lang)
        self.currentApiLanguage = QString("")
        self.on_apiLanguageComboBox_activated(self.currentApiLanguage)

        for lang in apiLanguages[1:]:
            self.apis[lang] = QStringList(Preferences.getEditorAPI(lang))

    def save(self):
        """
        Public slot to save the Editor APIs configuration.
        """
        Preferences.setEditor("AutoPrepareAPIs", int(self.apiAutoPrepareCheckBox.isChecked()))

        lang = self.apiLanguageComboBox.currentText()
        self.apis[unicode(lang)] = self.__editorGetApisFromApiList()

        for lang, apis in self.apis.items():
            Preferences.setEditorAPI(lang, apis)

    @pyqtSignature("QString")
    def on_apiLanguageComboBox_activated(self, language):
        """
        Private slot to fill the api listbox of the api page.
        
        @param language selected API language (QString)
        """
        if self.currentApiLanguage.compare(language) == 0:
            return

        self.apis[unicode(self.currentApiLanguage)] = self.__editorGetApisFromApiList()
        self.currentApiLanguage = QString(language)
        self.apiList.clear()

        if language.isEmpty():
            self.apiGroup.setEnabled(False)
            return

        self.apiGroup.setEnabled(True)
        for api in self.apis[unicode(self.currentApiLanguage)]:
            if not api.isEmpty():
                self.apiList.addItem(api)
        self.__currentAPI = self.__apisManager.getAPIs(self.currentApiLanguage)
        if self.__currentAPI is not None:
            self.connect(self.__currentAPI, SIGNAL("apiPreparationFinished()"), self.__apiPreparationFinished)
            self.connect(self.__currentAPI, SIGNAL("apiPreparationCancelled()"), self.__apiPreparationCancelled)
            self.connect(self.__currentAPI, SIGNAL("apiPreparationStarted()"), self.__apiPreparationStarted)
            self.addInstalledApiFileButton.setEnabled(not self.__currentAPI.installedAPIFiles().isEmpty())
        else:
            self.addInstalledApiFileButton.setEnabled(False)

        self.addPluginApiFileButton.setEnabled(len(self.pluginManager.getPluginApiFiles(self.currentApiLanguage)) > 0)

    def __editorGetApisFromApiList(self):
        """
        Private slot to retrieve the api filenames from the list.
        
        @return list of api filenames (QStringList)
        """
        apis = QStringList()
        for row in range(self.apiList.count()):
            apis.append(self.apiList.item(row).text())
        return apis

    @pyqtSignature("")
    def on_apiFileButton_clicked(self):
        """
        Private method to select an api file.
        """
        file = KQFileDialog.getOpenFileName(
            self,
            self.trUtf8("Select API file"),
            self.apiFileEdit.text(),
            self.trUtf8("API File (*.api);;All Files (*)"),
        )

        if not file.isEmpty():
            self.apiFileEdit.setText(Utilities.toNativeSeparators(file))

    @pyqtSignature("")
    def on_addApiFileButton_clicked(self):
        """
        Private slot to add the api file displayed to the listbox.
        """
        file = self.apiFileEdit.text()
        if not file.isEmpty():
            self.apiList.addItem(Utilities.toNativeSeparators(file))
            self.apiFileEdit.clear()

    @pyqtSignature("")
    def on_deleteApiFileButton_clicked(self):
        """
        Private slot to delete the currently selected file of the listbox.
        """
        crow = self.apiList.currentRow()
        if crow >= 0:
            itm = self.apiList.takeItem(crow)
            del itm

    @pyqtSignature("")
    def on_addInstalledApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of installed API files
        for the selected lexer language.
        """
        installedAPIFiles = self.__currentAPI.installedAPIFiles()
        if len(installedAPIFiles) > 0:
            installedAPIFilesPath = QFileInfo(installedAPIFiles[0]).path()
            installedAPIFilesShort = QStringList()
            for installedAPIFile in installedAPIFiles:
                installedAPIFilesShort.append(QFileInfo(installedAPIFile).fileName())
            file, ok = KQInputDialog.getItem(
                self,
                self.trUtf8("Add from installed APIs"),
                self.trUtf8("Select from the list of installed API files"),
                installedAPIFilesShort,
                0,
                False,
            )
            if ok:
                self.apiList.addItem(
                    Utilities.toNativeSeparators(QFileInfo(QDir(installedAPIFilesPath), file).absoluteFilePath())
                )
        else:
            KQMessageBox.warning(
                self,
                self.trUtf8("Add from installed APIs"),
                self.trUtf8("""There are no APIs installed yet.""" """ Selection is not available."""),
            )
            self.addInstalledApiFileButton.setEnabled(False)

    @pyqtSignature("")
    def on_addPluginApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of API files installed
        by plugins for the selected lexer language.
        """
        pluginAPIFiles = self.pluginManager.getPluginApiFiles(self.currentApiLanguage)
        pluginAPIFilesDict = {}
        for apiFile in pluginAPIFiles:
            pluginAPIFilesDict[unicode(QFileInfo(apiFile).fileName())] = apiFile
        file, ok = KQInputDialog.getItem(
            self,
            self.trUtf8("Add from Plugin APIs"),
            self.trUtf8("Select from the list of API files installed by plugins"),
            sorted(pluginAPIFilesDict.keys()),
            0,
            False,
        )
        if ok:
            self.apiList.addItem(Utilities.toNativeSeparators(pluginAPIFilesDict[unicode(file)]))

    @pyqtSignature("")
    def on_prepareApiButton_clicked(self):
        """
        Private slot to prepare the API file for the currently selected language.
        """
        if self.__inPreparation:
            self.__currentAPI and self.__currentAPI.cancelPreparation()
        else:
            if self.__currentAPI is not None:
                self.__currentAPI.prepareAPIs(ondemand=True, rawList=QStringList(self.__editorGetApisFromApiList()))

    def __apiPreparationFinished(self):
        """
        Private method called after the API preparation has finished.
        """
        self.prepareApiProgressBar.reset()
        self.prepareApiProgressBar.setRange(0, 100)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.trUtf8("Compile APIs"))
        self.__inPreparation = False

    def __apiPreparationCancelled(self):
        """
        Private slot called after the API preparation has been cancelled.
        """
        self.__apiPreparationFinished()

    def __apiPreparationStarted(self):
        """
        Private method called after the API preparation has started.
        """
        self.prepareApiProgressBar.setRange(0, 0)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.trUtf8("Cancel compilation"))
        self.__inPreparation = True

    def saveState(self):
        """
        Public method to save the current state of the widget.
        
        @return index of the selected lexer language (integer)
        """
        return self.apiLanguageComboBox.currentIndex()

    def setState(self, state):
        """
        Public method to set the state of the widget.
        
        @param state state data generated by saveState
        """
        self.apiLanguageComboBox.setCurrentIndex(state)
        self.on_apiLanguageComboBox_activated(self.apiLanguageComboBox.currentText())
Пример #6
0
class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage):
    """
    Class implementing the Editor APIs configuration page.
    """
    def __init__(self):
        """
        Constructor
        """
        super(EditorAPIsPage, self).__init__()
        self.setupUi(self)
        self.setObjectName("EditorAPIsPage")

        self.apiFileButton.setIcon(UI.PixmapCache.getIcon("open.png"))

        self.prepareApiButton.setText(self.tr("Compile APIs"))
        self.__currentAPI = None
        self.__inPreparation = False

        self.apiFileCompleter = E5FileCompleter(self.apiFileEdit)

        # set initial values
        self.pluginManager = e5App().getObject("PluginManager")
        self.apiAutoPrepareCheckBox.setChecked(
            Preferences.getEditor("AutoPrepareAPIs"))

        import QScintilla.Lexers
        self.apis = {}
        apiLanguages = sorted(
            [''] + list(QScintilla.Lexers.getSupportedLanguages().keys()))
        for lang in apiLanguages:
            if lang != "Guessed":
                self.apiLanguageComboBox.addItem(lang)
        self.currentApiLanguage = ''
        self.on_apiLanguageComboBox_activated(self.currentApiLanguage)

        for lang in apiLanguages[1:]:
            self.apis[lang] = Preferences.getEditorAPI(lang)[:]

    def save(self):
        """
        Public slot to save the Editor APIs configuration.
        """
        Preferences.setEditor("AutoPrepareAPIs",
                              self.apiAutoPrepareCheckBox.isChecked())

        lang = self.apiLanguageComboBox.currentText()
        self.apis[lang] = self.__editorGetApisFromApiList()

        for lang, apis in list(self.apis.items()):
            Preferences.setEditorAPI(lang, apis)

    @pyqtSlot(str)
    def on_apiLanguageComboBox_activated(self, language):
        """
        Private slot to fill the api listbox of the api page.
        
        @param language selected API language (string)
        """
        if self.currentApiLanguage == language:
            return

        self.apis[self.currentApiLanguage] = self.__editorGetApisFromApiList()
        self.currentApiLanguage = language
        self.apiList.clear()

        if not language:
            self.apiGroup.setEnabled(False)
            return

        self.apiGroup.setEnabled(True)
        self.deleteApiFileButton.setEnabled(False)
        self.addApiFileButton.setEnabled(False)
        self.apiFileEdit.clear()

        for api in self.apis[self.currentApiLanguage]:
            if api:
                self.apiList.addItem(api)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

        from QScintilla.APIsManager import APIsManager
        self.__currentAPI = APIsManager().getAPIs(self.currentApiLanguage)
        if self.__currentAPI is not None:
            self.__currentAPI.apiPreparationFinished.connect(
                self.__apiPreparationFinished)
            self.__currentAPI.apiPreparationCancelled.connect(
                self.__apiPreparationCancelled)
            self.__currentAPI.apiPreparationStarted.connect(
                self.__apiPreparationStarted)
            self.addInstalledApiFileButton.setEnabled(
                len(self.__currentAPI.installedAPIFiles()) > 0)
        else:
            self.addInstalledApiFileButton.setEnabled(False)

        self.addPluginApiFileButton.setEnabled(
            len(self.pluginManager.getPluginApiFiles(self.currentApiLanguage))
            > 0)

    def __editorGetApisFromApiList(self):
        """
        Private slot to retrieve the api filenames from the list.
        
        @return list of api filenames (list of strings)
        """
        apis = []
        for row in range(self.apiList.count()):
            apis.append(self.apiList.item(row).text())
        return apis

    @pyqtSlot()
    def on_apiFileButton_clicked(self):
        """
        Private method to select an api file.
        """
        file = E5FileDialog.getOpenFileName(
            self, self.tr("Select API file"), self.apiFileEdit.text(),
            self.tr("API File (*.api);;All Files (*)"))

        if file:
            self.apiFileEdit.setText(Utilities.toNativeSeparators(file))

    @pyqtSlot()
    def on_addApiFileButton_clicked(self):
        """
        Private slot to add the api file displayed to the listbox.
        """
        file = self.apiFileEdit.text()
        if file:
            self.apiList.addItem(Utilities.toNativeSeparators(file))
            self.apiFileEdit.clear()
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_deleteApiFileButton_clicked(self):
        """
        Private slot to delete the currently selected file of the listbox.
        """
        crow = self.apiList.currentRow()
        if crow >= 0:
            itm = self.apiList.takeItem(crow)
            del itm
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_addInstalledApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of installed API files
        for the selected lexer language.
        """
        installedAPIFiles = self.__currentAPI.installedAPIFiles()
        if installedAPIFiles:
            installedAPIFilesPath = QFileInfo(installedAPIFiles[0]).path()
            installedAPIFilesShort = []
            for installedAPIFile in installedAPIFiles:
                installedAPIFilesShort.append(
                    QFileInfo(installedAPIFile).fileName())
            file, ok = QInputDialog.getItem(
                self, self.tr("Add from installed APIs"),
                self.tr("Select from the list of installed API files"),
                installedAPIFilesShort, 0, False)
            if ok:
                self.apiList.addItem(
                    Utilities.toNativeSeparators(
                        QFileInfo(QDir(installedAPIFilesPath),
                                  file).absoluteFilePath()))
        else:
            E5MessageBox.warning(
                self, self.tr("Add from installed APIs"),
                self.tr("""There are no APIs installed yet."""
                        """ Selection is not available."""))
            self.addInstalledApiFileButton.setEnabled(False)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_addPluginApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of API files installed
        by plugins for the selected lexer language.
        """
        pluginAPIFiles = self.pluginManager.getPluginApiFiles(
            self.currentApiLanguage)
        pluginAPIFilesDict = {}
        for apiFile in pluginAPIFiles:
            pluginAPIFilesDict[QFileInfo(apiFile).fileName()] = apiFile
        file, ok = QInputDialog.getItem(
            self, self.tr("Add from Plugin APIs"),
            self.tr("Select from the list of API files installed by plugins"),
            sorted(pluginAPIFilesDict.keys()), 0, False)
        if ok:
            self.apiList.addItem(
                Utilities.toNativeSeparators(pluginAPIFilesDict[file]))
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_prepareApiButton_clicked(self):
        """
        Private slot to prepare the API file for the currently selected
            language.
        """
        if self.__inPreparation:
            self.__currentAPI and self.__currentAPI.cancelPreparation()
        else:
            if self.__currentAPI is not None:
                self.__currentAPI.prepareAPIs(
                    ondemand=True, rawList=self.__editorGetApisFromApiList())

    def __apiPreparationFinished(self):
        """
        Private method called after the API preparation has finished.
        """
        self.prepareApiProgressBar.reset()
        self.prepareApiProgressBar.setRange(0, 100)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.tr("Compile APIs"))
        self.__inPreparation = False

    def __apiPreparationCancelled(self):
        """
        Private slot called after the API preparation has been cancelled.
        """
        self.__apiPreparationFinished()

    def __apiPreparationStarted(self):
        """
        Private method called after the API preparation has started.
        """
        self.prepareApiProgressBar.setRange(0, 0)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.tr("Cancel compilation"))
        self.__inPreparation = True

    def saveState(self):
        """
        Public method to save the current state of the widget.
        
        @return index of the selected lexer language (integer)
        """
        return self.apiLanguageComboBox.currentIndex()

    def setState(self, state):
        """
        Public method to set the state of the widget.
        
        @param state state data generated by saveState
        """
        self.apiLanguageComboBox.setCurrentIndex(state)
        self.on_apiLanguageComboBox_activated(
            self.apiLanguageComboBox.currentText())

    @pyqtSlot()
    def on_apiList_itemSelectionChanged(self):
        """
        Private slot to react on changes of API selections.
        """
        self.deleteApiFileButton.setEnabled(
            len(self.apiList.selectedItems()) > 0)

    @pyqtSlot(str)
    def on_apiFileEdit_textChanged(self, txt):
        """
        Private slot to handle the entering of an API file name.
        
        @param txt text of the line edit (string)
        """
        enable = txt != ""

        if enable:
            # check for already added file
            for row in range(self.apiList.count()):
                if txt == self.apiList.item(row).text():
                    enable = False
                    break

        self.addApiFileButton.setEnabled(enable)
Пример #7
0
class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage):
    """
    Class implementing the Editor APIs configuration page.
    """
    def __init__(self):
        """
        Constructor
        """
        super(EditorAPIsPage, self).__init__()
        self.setupUi(self)
        self.setObjectName("EditorAPIsPage")
        
        self.apiFilePicker.setMode(E5PathPickerModes.OpenFileMode)
        self.apiFilePicker.setToolTip(self.tr(
            "Press to select an API file via a selection dialog"))
        self.apiFilePicker.setFilters(self.tr(
            "API File (*.api);;All Files (*)"))
        
        self.prepareApiButton.setText(self.tr("Compile APIs"))
        self.__currentAPI = None
        self.__inPreparation = False
        
        # set initial values
        self.pluginManager = e5App().getObject("PluginManager")
        self.apiAutoPrepareCheckBox.setChecked(
            Preferences.getEditor("AutoPrepareAPIs"))
        
        import QScintilla.Lexers
        self.apis = {}
        apiLanguages = sorted(
            [''] + list(QScintilla.Lexers.getSupportedLanguages().keys()))
        for lang in apiLanguages:
            if lang != "Guessed":
                self.apiLanguageComboBox.addItem(lang)
        self.currentApiLanguage = ''
        self.on_apiLanguageComboBox_activated(self.currentApiLanguage)
        
        for lang in apiLanguages[1:]:
            self.apis[lang] = Preferences.getEditorAPI(lang)[:]
        
    def save(self):
        """
        Public slot to save the Editor APIs configuration.
        """
        Preferences.setEditor(
            "AutoPrepareAPIs",
            self.apiAutoPrepareCheckBox.isChecked())
        
        lang = self.apiLanguageComboBox.currentText()
        self.apis[lang] = self.__editorGetApisFromApiList()
        
        for lang, apis in list(self.apis.items()):
            Preferences.setEditorAPI(lang, apis)
        
    @pyqtSlot(str)
    def on_apiLanguageComboBox_activated(self, language):
        """
        Private slot to fill the api listbox of the api page.
        
        @param language selected API language (string)
        """
        if self.currentApiLanguage == language:
            return
            
        self.apis[self.currentApiLanguage] = self.__editorGetApisFromApiList()
        self.currentApiLanguage = language
        self.apiList.clear()
        
        if not language:
            self.apiGroup.setEnabled(False)
            return
            
        self.apiGroup.setEnabled(True)
        self.deleteApiFileButton.setEnabled(False)
        self.addApiFileButton.setEnabled(False)
        self.apiFilePicker.clear()
        
        for api in self.apis[self.currentApiLanguage]:
            if api:
                self.apiList.addItem(api)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)
        
        from QScintilla.APIsManager import APIsManager
        self.__currentAPI = APIsManager().getAPIs(self.currentApiLanguage)
        if self.__currentAPI is not None:
            self.__currentAPI.apiPreparationFinished.connect(
                self.__apiPreparationFinished)
            self.__currentAPI.apiPreparationCancelled.connect(
                self.__apiPreparationCancelled)
            self.__currentAPI.apiPreparationStarted.connect(
                self.__apiPreparationStarted)
            self.addInstalledApiFileButton.setEnabled(
                len(self.__currentAPI.installedAPIFiles()) > 0)
        else:
            self.addInstalledApiFileButton.setEnabled(False)
        
        self.addPluginApiFileButton.setEnabled(
            len(self.pluginManager.getPluginApiFiles(self.currentApiLanguage))
            > 0)
        
    def __editorGetApisFromApiList(self):
        """
        Private slot to retrieve the api filenames from the list.
        
        @return list of api filenames (list of strings)
        """
        apis = []
        for row in range(self.apiList.count()):
            apis.append(self.apiList.item(row).text())
        return apis
        
    @pyqtSlot()
    def on_addApiFileButton_clicked(self):
        """
        Private slot to add the api file displayed to the listbox.
        """
        file = self.apiFilePicker.text()
        if file:
            self.apiList.addItem(Utilities.toNativeSeparators(file))
            self.apiFilePicker.clear()
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)
        
    @pyqtSlot()
    def on_deleteApiFileButton_clicked(self):
        """
        Private slot to delete the currently selected file of the listbox.
        """
        crow = self.apiList.currentRow()
        if crow >= 0:
            itm = self.apiList.takeItem(crow)       # __IGNORE_WARNING__
            del itm
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)
        
    @pyqtSlot()
    def on_addInstalledApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of installed API files
        for the selected lexer language.
        """
        installedAPIFiles = self.__currentAPI.installedAPIFiles()
        if installedAPIFiles:
            installedAPIFilesPath = QFileInfo(installedAPIFiles[0]).path()
            installedAPIFilesShort = []
            for installedAPIFile in installedAPIFiles:
                installedAPIFilesShort.append(
                    QFileInfo(installedAPIFile).fileName())
            file, ok = QInputDialog.getItem(
                self,
                self.tr("Add from installed APIs"),
                self.tr("Select from the list of installed API files"),
                installedAPIFilesShort,
                0, False)
            if ok:
                self.apiList.addItem(Utilities.toNativeSeparators(
                    QFileInfo(QDir(installedAPIFilesPath), file)
                    .absoluteFilePath()))
        else:
            E5MessageBox.warning(
                self,
                self.tr("Add from installed APIs"),
                self.tr("""There are no APIs installed yet."""
                        """ Selection is not available."""))
            self.addInstalledApiFileButton.setEnabled(False)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)
        
    @pyqtSlot()
    def on_addPluginApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of API files installed
        by plugins for the selected lexer language.
        """
        pluginAPIFiles = self.pluginManager.getPluginApiFiles(
            self.currentApiLanguage)
        pluginAPIFilesDict = {}
        for apiFile in pluginAPIFiles:
            pluginAPIFilesDict[QFileInfo(apiFile).fileName()] = apiFile
        file, ok = QInputDialog.getItem(
            self,
            self.tr("Add from Plugin APIs"),
            self.tr(
                "Select from the list of API files installed by plugins"),
            sorted(pluginAPIFilesDict.keys()),
            0, False)
        if ok:
            self.apiList.addItem(Utilities.toNativeSeparators(
                pluginAPIFilesDict[file]))
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)
        
    @pyqtSlot()
    def on_prepareApiButton_clicked(self):
        """
        Private slot to prepare the API file for the currently selected
            language.
        """
        if self.__inPreparation:
            self.__currentAPI and self.__currentAPI.cancelPreparation()
        else:
            if self.__currentAPI is not None:
                self.__currentAPI.prepareAPIs(
                    ondemand=True,
                    rawList=self.__editorGetApisFromApiList())
        
    def __apiPreparationFinished(self):
        """
        Private method called after the API preparation has finished.
        """
        self.prepareApiProgressBar.reset()
        self.prepareApiProgressBar.setRange(0, 100)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.tr("Compile APIs"))
        self.__inPreparation = False
    
    def __apiPreparationCancelled(self):
        """
        Private slot called after the API preparation has been cancelled.
        """
        self.__apiPreparationFinished()
    
    def __apiPreparationStarted(self):
        """
        Private method called after the API preparation has started.
        """
        self.prepareApiProgressBar.setRange(0, 0)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.tr("Cancel compilation"))
        self.__inPreparation = True
        
    def saveState(self):
        """
        Public method to save the current state of the widget.
        
        @return index of the selected lexer language (integer)
        """
        return self.apiLanguageComboBox.currentIndex()
        
    def setState(self, state):
        """
        Public method to set the state of the widget.
        
        @param state state data generated by saveState
        """
        self.apiLanguageComboBox.setCurrentIndex(state)
        self.on_apiLanguageComboBox_activated(
            self.apiLanguageComboBox.currentText())
    
    @pyqtSlot()
    def on_apiList_itemSelectionChanged(self):
        """
        Private slot to react on changes of API selections.
        """
        self.deleteApiFileButton.setEnabled(
            len(self.apiList.selectedItems()) > 0)
    
    @pyqtSlot(str)
    def on_apiFilePicker_textChanged(self, txt):
        """
        Private slot to handle the entering of an API file name.
        
        @param txt text of the line edit (string)
        """
        enable = txt != ""
        
        if enable:
            # check for already added file
            for row in range(self.apiList.count()):
                if txt == self.apiList.item(row).text():
                    enable = False
                    break
        
        self.addApiFileButton.setEnabled(enable)
Пример #8
0
class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage):
    """
    Class implementing the Editor APIs configuration page.
    """
    def __init__(self):
        """
        Constructor
        """
        super(EditorAPIsPage, self).__init__()
        self.setupUi(self)
        self.setObjectName("EditorAPIsPage")

        self.apiFilePicker.setMode(E5PathPickerModes.OpenFileMode)
        self.apiFilePicker.setToolTip(
            self.tr("Press to select an API file via a selection dialog"))
        self.apiFilePicker.setFilters(
            self.tr("API File (*.api);;All Files (*)"))

        self.prepareApiButton.setText(self.tr("Compile APIs"))
        self.__currentAPI = None
        self.__inPreparation = False

        # set initial values
        self.pluginManager = e5App().getObject("PluginManager")
        self.apiAutoPrepareCheckBox.setChecked(
            Preferences.getEditor("AutoPrepareAPIs"))

        import QScintilla.Lexers
        self.apis = {}
        apiLanguages = sorted(
            [''] + list(QScintilla.Lexers.getSupportedApiLanguages()))
        for lang in apiLanguages:
            self.apiLanguageComboBox.addItem(
                QScintilla.Lexers.getLanguageIcon(lang, False), lang)
        self.__currentApiLanguage = ""
        self.on_apiLanguageComboBox_activated(self.__currentApiLanguage)

    def __apiKey(self, language, projectType):
        """
        Private method to generate a key for the apis dictionary.
        
        @param language programming language of the API
        @type str
        @param projectType project type of the API
        @type str
        @return key to be used
        @rtype str
        """
        if projectType:
            key = (language, projectType)
        else:
            key = (language, "")
        return key

    def save(self):
        """
        Public slot to save the Editor APIs configuration.
        """
        Preferences.setEditor("AutoPrepareAPIs",
                              self.apiAutoPrepareCheckBox.isChecked())

        language = self.apiLanguageComboBox.currentText()
        projectType = self.projectTypeComboBox.itemData(
            self.projectTypeComboBox.currentIndex())
        key = self.__apiKey(language, projectType)
        self.apis[key] = self.__editorGetApisFromApiList()

        for (language, projectType), apis in self.apis.items():
            Preferences.setEditorAPI(language, projectType, apis)

    @pyqtSlot(int)
    def on_projectTypeComboBox_activated(self, index):
        """
        Private slot to handle the selection of a project type.
        
        @param index index of the selected entry
        @type str
        """
        if self.__currentApiProjectTypeIndex == index:
            return

        self.__currentApiProjectTypeIndex = index
        self.__fillApisList()

    @pyqtSlot(str)
    def on_apiLanguageComboBox_activated(self, language):
        """
        Private slot to fill the api listbox of the api page.
        
        @param language selected API language
        @type str
        """
        if self.__currentApiLanguage == language:
            return

        self.__fillProjectTypeComboBox(language)

    def __fillProjectTypeComboBox(self, language):
        """
        Private slot to fill the selection of available project types for the
        given language.
        
        @param language selected API language
        @type str
        """
        self.projectTypeComboBox.clear()

        apiProjectTypes = sorted(
            [("", "")] + [(trans, ptype) for ptype, trans in e5App().getObject(
                "Project").getProjectTypes(language).items()])
        for projectTypeStr, projectType in apiProjectTypes:
            self.projectTypeComboBox.addItem(projectTypeStr, projectType)

        self.__currentApiProjectTypeIndex = -1
        self.__currentApiProjectType = ""

        self.on_projectTypeComboBox_activated(0)

    def __fillApisList(self):
        """
        Private slot to fill the list of API files.
        """
        self.apis[self.__apiKey(
            self.__currentApiLanguage,
            self.__currentApiProjectType)] = self.__editorGetApisFromApiList()

        self.__currentApiLanguage = self.apiLanguageComboBox.currentText()
        self.__currentApiProjectType = self.projectTypeComboBox.itemData(
            self.projectTypeComboBox.currentIndex())
        self.apiList.clear()

        if not self.__currentApiLanguage:
            self.apiGroup.setEnabled(False)
            return

        self.apiGroup.setEnabled(True)
        self.deleteApiFileButton.setEnabled(False)
        self.addApiFileButton.setEnabled(False)
        self.apiFilePicker.clear()

        key = self.__apiKey(self.__currentApiLanguage,
                            self.__currentApiProjectType)
        if key not in self.apis:
            # populate on demand
            self.apis[key] = Preferences.getEditorAPI(
                self.__currentApiLanguage,
                projectType=self.__currentApiProjectType)[:]
        for api in self.apis[key]:
            if api:
                self.apiList.addItem(api)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

        from QScintilla.APIsManager import APIsManager
        self.__currentAPI = APIsManager().getAPIs(
            self.__currentApiLanguage,
            projectType=self.__currentApiProjectType)
        if self.__currentAPI is not None:
            self.__currentAPI.apiPreparationFinished.connect(
                self.__apiPreparationFinished)
            self.__currentAPI.apiPreparationCancelled.connect(
                self.__apiPreparationCancelled)
            self.__currentAPI.apiPreparationStarted.connect(
                self.__apiPreparationStarted)
            self.addInstalledApiFileButton.setEnabled(
                len(self.__currentAPI.installedAPIFiles()) > 0)
        else:
            self.addInstalledApiFileButton.setEnabled(False)

        self.addPluginApiFileButton.setEnabled(
            len(self.pluginManager.getPluginApiFiles(
                self.__currentApiLanguage)) > 0)

    def __editorGetApisFromApiList(self):
        """
        Private slot to retrieve the api filenames from the list.
        
        @return list of api filenames (list of strings)
        """
        apis = []
        for row in range(self.apiList.count()):
            apis.append(self.apiList.item(row).text())
        return apis

    @pyqtSlot()
    def on_addApiFileButton_clicked(self):
        """
        Private slot to add the api file displayed to the listbox.
        """
        file = self.apiFilePicker.text()
        if file:
            self.apiList.addItem(Utilities.toNativeSeparators(file))
            self.apiFilePicker.clear()
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_deleteApiFileButton_clicked(self):
        """
        Private slot to delete the currently selected file of the listbox.
        """
        crow = self.apiList.currentRow()
        if crow >= 0:
            itm = self.apiList.takeItem(crow)  # __IGNORE_WARNING__
            del itm
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_addInstalledApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of installed API files
        for the selected lexer language.
        """
        installedAPIFiles = self.__currentAPI.installedAPIFiles()
        if installedAPIFiles:
            installedAPIFilesPath = QFileInfo(installedAPIFiles[0]).path()
            installedAPIFilesShort = []
            for installedAPIFile in installedAPIFiles:
                installedAPIFilesShort.append(
                    QFileInfo(installedAPIFile).fileName())
            file, ok = QInputDialog.getItem(
                self, self.tr("Add from installed APIs"),
                self.tr("Select from the list of installed API files"),
                installedAPIFilesShort, 0, False)
            if ok:
                self.apiList.addItem(
                    Utilities.toNativeSeparators(
                        QFileInfo(QDir(installedAPIFilesPath),
                                  file).absoluteFilePath()))
        else:
            E5MessageBox.warning(
                self, self.tr("Add from installed APIs"),
                self.tr("""There are no APIs installed yet."""
                        """ Selection is not available."""))
            self.addInstalledApiFileButton.setEnabled(False)
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_addPluginApiFileButton_clicked(self):
        """
        Private slot to add an API file from the list of API files installed
        by plugins for the selected lexer language.
        """
        pluginAPIFiles = self.pluginManager.getPluginApiFiles(
            self.__currentApiLanguage)
        pluginAPIFilesDict = {}
        for apiFile in pluginAPIFiles:
            pluginAPIFilesDict[QFileInfo(apiFile).fileName()] = apiFile
        file, ok = QInputDialog.getItem(
            self, self.tr("Add from Plugin APIs"),
            self.tr("Select from the list of API files installed by plugins"),
            sorted(pluginAPIFilesDict.keys()), 0, False)
        if ok:
            self.apiList.addItem(
                Utilities.toNativeSeparators(pluginAPIFilesDict[file]))
        self.prepareApiButton.setEnabled(self.apiList.count() > 0)

    @pyqtSlot()
    def on_prepareApiButton_clicked(self):
        """
        Private slot to prepare the API file for the currently selected
            language.
        """
        if self.__inPreparation:
            self.__currentAPI and self.__currentAPI.cancelPreparation()
        else:
            if self.__currentAPI is not None:
                self.__currentAPI.prepareAPIs(
                    ondemand=True, rawList=self.__editorGetApisFromApiList())

    def __apiPreparationFinished(self):
        """
        Private method called after the API preparation has finished.
        """
        self.prepareApiProgressBar.reset()
        self.prepareApiProgressBar.setRange(0, 100)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.tr("Compile APIs"))
        self.__inPreparation = False

    def __apiPreparationCancelled(self):
        """
        Private slot called after the API preparation has been cancelled.
        """
        self.__apiPreparationFinished()

    def __apiPreparationStarted(self):
        """
        Private method called after the API preparation has started.
        """
        self.prepareApiProgressBar.setRange(0, 0)
        self.prepareApiProgressBar.setValue(0)
        self.prepareApiButton.setText(self.tr("Cancel compilation"))
        self.__inPreparation = True

    def saveState(self):
        """
        Public method to save the current state of the widget.
        
        @return tuple containing the index of the selected lexer language
            and the index of the selected project type
        @rtype tuple of int and int
        """
        return (self.apiLanguageComboBox.currentIndex(),
                self.projectTypeComboBox.currentIndex())

    def setState(self, state):
        """
        Public method to set the state of the widget.
        
        @param state state data generated by saveState
        """
        self.apiLanguageComboBox.setCurrentIndex(state[0])
        self.on_apiLanguageComboBox_activated(
            self.apiLanguageComboBox.currentText())

        self.projectTypeComboBox.setCurrentIndex(state[1])
        self.on_projectTypeComboBox_activated(state[1])

    @pyqtSlot()
    def on_apiList_itemSelectionChanged(self):
        """
        Private slot to react on changes of API selections.
        """
        self.deleteApiFileButton.setEnabled(
            len(self.apiList.selectedItems()) > 0)

    @pyqtSlot(str)
    def on_apiFilePicker_textChanged(self, txt):
        """
        Private slot to handle the entering of an API file name.
        
        @param txt text of the line edit (string)
        """
        enable = txt != ""

        if enable:
            # check for already added file
            for row in range(self.apiList.count()):
                if txt == self.apiList.item(row).text():
                    enable = False
                    break

        self.addApiFileButton.setEnabled(enable)