Example #1
0
    def editComplete(self):
        text = self.text()
        if QString.compare(text, QString("")) != 0:

            is_contains = self.word_list.contains(text, Qt.CaseInsensitive)
            if not is_contains:
                self.word_list << text
                self.string_list_model.setStringList(self.word_list)
Example #2
0
    def match(self, context):
        if not context.isValid():
            return

        query = context.query()

        # Don't use query.startsWith('vim ') because we want the
        # list of all sessions to show up once inserted 'vim'.
        # The space between plugin keywork and text query must be
        # handled manually.
        if not query.startsWith('vim', Qt.CaseInsensitive):
            return
        try:
            if query[3] != ' ':
                return
        except IndexError:
            pass

        query = query[4:]
        query = query.trimmed()

        for _, _, sessions in os.walk(DEFAULT_SESSION_DIRECTORY):
            for session in sessions:

                match = Plasma.QueryMatch(self.runner)

                # Skip lock files.
                if session.endswith('.lock'):
                    continue

                # Trim .vim extension.
                session = QString(session[:-4])

                # Search is case insensitive.
                if session.contains(query, Qt.CaseInsensitive):
                    match.setText(session)
                    match.setSubtext('Open Vim session')
                    match.setType(Plasma.QueryMatch.ExactMatch)
                    match.setIcon(KIcon('vim'))
                    match.setData(session)
                    if session.compare(query, Qt.CaseInsensitive) == 0:
                        match.setRelevance(1.0)
                    else:
                        match.setRelevance(0.8)

                    context.addMatch(session, match)
Example #3
0
 def similarWords(self):
     qch = QChar(u'-')
     qcp = QChar(u"'")
     wordOriginal = self.model().data(self.contextIndex, Qt.DisplayRole).toString()
     word = QString(wordOriginal)
     word.remove(qch)
     word.remove(qcp)
     h1list = []
     for i in range(IMC.wordCensus.size()):
         word1 = IMC.wordCensus.getWord(i)
         word2 = QString(word1) # force a copy!
         word2.remove(qch) # otherwise this would affect the word
         word2.remove(qcp) # in the census list
         if 0 == word.compare(word2,Qt.CaseInsensitive):
             h1list.append(unicode(word1)) # one hit on word itself
     if 1 < len(h1list): # got at least 1 other
         self.panelRef.tableModel.beginResetModel()
         self.panelRef.listFilter = h1list
         self.panelRef.tableModel.endResetModel()
         self.panelRef.rowCountLabel.setNum(self.panelRef.proxy.rowCount())
     else:
         pqMsgs.infoMsg("There are no words similar to {0}".format(unicode(wordOriginal)))
Example #4
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())
Example #5
0
    def convert2(self):
        if not QString.compare(self.input, ''):
            os.system('echo "Error: missing input"')  # bash in linux
        else:
            self.command = QString('')  # clear command
            self.command.append('ffmpeg ')  # call the program
            self.command.append('-i "%s" ' % self.input)  # input file
            self.command.append('-c:a %s ' % self.acodec)  # audio codec
            self.command.append('-c:v %s ' % self.vcodec)  # video codec

            if not QString.compare(self.crf, ''):
                # if text is empty, default video quality. CRF = 23
                self.command.append('-crf 23 ')
            else:
                self.command.append('-crf %s ' % self.crf)  # video quality

            if self.check_res.isChecked():
                if not QString.compare(self.vcodec, 'copy'):
                    os.system(
                        'echo "Error: cannot resize without encoding video. \
Please select a video codec."')
                    #sys.exit(app.exec_())
                    return  # this way it just exits from the function instead of terminating the app
                self.command.append('-vf scale=')  # resize filter
                if not QString.compare(self.width, '') and not QString.compare(
                        self.height, ''):
                    self.command.append('iw:ih ')  # do not resize
                elif not QString.compare(self.width, '') and QString.compare(
                        self.height, ''):
                    self.command.append(
                        '-2:%s ' %
                        self.height)  # change height with constant ratio
                elif QString.compare(self.width, '') and not QString.compare(
                        self.height, ''):
                    self.command.append(
                        '%s:-2 ' %
                        self.width)  # change width with constant ratio
                elif QString.compare(self.width, '') and QString.compare(
                        self.height, ''):
                    self.command.append(
                        '%s:%s ' %
                        (self.width,
                         self.height))  # change height with constant ratio

            if not QString.compare(self.output, ''):
                self.command.append('output.mp4')  # default output
            else:
                self.command.append('"%s"' % self.output)  # output file

            os.system(str(self.command.toUtf8()))