本文整理汇总了Python中qgis.PyQt.Qsci.QsciAPIs.prepare方法的典型用法代码示例。如果您正苦于以下问题:Python QsciAPIs.prepare方法的具体用法?Python QsciAPIs.prepare怎么用?Python QsciAPIs.prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.Qsci.QsciAPIs
的用法示例。
在下文中一共展示了QsciAPIs.prepare方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initCompleter
# 需要导入模块: from qgis.PyQt.Qsci import QsciAPIs [as 别名]
# 或者: from qgis.PyQt.Qsci.QsciAPIs import prepare [as 别名]
def initCompleter(self):
dictionary = None
if self.db:
dictionary = self.db.connector.getSqlDictionary()
if not dictionary:
# use the generic sql dictionary
from .sql_dictionary import getSqlDictionary
dictionary = getSqlDictionary()
wordlist = []
for name, value in list(dictionary.items()):
wordlist += value # concat lists
wordlist = list(set(wordlist)) # remove duplicates
api = QsciAPIs(self.editSql.lexer())
for word in wordlist:
api.add(word)
api.prepare()
self.editSql.lexer().setAPIs(api)
示例2: PrepareAPIs
# 需要导入模块: from qgis.PyQt.Qsci import QsciAPIs [as 别名]
# 或者: from qgis.PyQt.Qsci.QsciAPIs import prepare [as 别名]
class PrepareAPIs(QObject):
def __init__(self, api_lexer, api_files, pap_file):
QObject.__init__(self)
self._api = None
self._api_files = api_files
self._api_lexer = api_lexer
self._pap_file = pap_file
def _clearLexer(self):
self.qlexer = None
def _stopPreparation(self):
if self._api is not None:
self._api.cancelPreparation()
self._api = None
sys.exit(1)
def _preparationFinished(self):
self._clearLexer()
try:
if os.path.exists(self._pap_file):
os.remove(self._pap_file)
prepd = self._api.savePrepared(unicode(self._pap_file))
self._api = None
sys.exit(0 if prepd else 1)
except Exception as err:
self._api = None
sys.exit(1)
def prepareAPI(self):
try:
self._api = QsciAPIs(self._api_lexer)
self._api.apiPreparationFinished.connect(self._preparationFinished)
for api_file in self._api_files:
self._api.load(unicode(api_file))
self._api.prepare()
except Exception as err:
self._api = None
sys.exit(1)
示例3: ScriptEdit
# 需要导入模块: from qgis.PyQt.Qsci import QsciAPIs [as 别名]
# 或者: from qgis.PyQt.Qsci.QsciAPIs import prepare [as 别名]
#.........这里部分代码省略.........
self.setFonts(10)
self.initLexer()
def setFonts(self, size):
# Load font from Python console settings
settings = QgsSettings()
fontName = settings.value('pythonConsole/fontfamilytext', 'Monospace')
fontSize = int(settings.value('pythonConsole/fontsize', size))
self.defaultFont = QFont(fontName)
self.defaultFont.setFixedPitch(True)
self.defaultFont.setPointSize(fontSize)
self.defaultFont.setStyleHint(QFont.TypeWriter)
self.defaultFont.setBold(False)
self.boldFont = QFont(self.defaultFont)
self.boldFont.setBold(True)
self.italicFont = QFont(self.defaultFont)
self.italicFont.setItalic(True)
self.setFont(self.defaultFont)
self.setMarginsFont(self.defaultFont)
def initShortcuts(self):
(ctrl, shift) = (self.SCMOD_CTRL << 16, self.SCMOD_SHIFT << 16)
# Disable some shortcuts
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('D') + ctrl)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('L') + ctrl)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('L') + ctrl +
shift)
self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('T') + ctrl)
# self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord("Z") + ctrl)
# self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord("Y") + ctrl)
# Use Ctrl+Space for autocompletion
self.shortcutAutocomplete = QShortcut(QKeySequence(Qt.CTRL +
Qt.Key_Space), self)
self.shortcutAutocomplete.setContext(Qt.WidgetShortcut)
self.shortcutAutocomplete.activated.connect(self.autoComplete)
def autoComplete(self):
self.autoCompleteFromAll()
def initLexer(self):
settings = QgsSettings()
self.lexer = QsciLexerPython()
font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
loadFont = settings.value("pythonConsole/fontfamilytextEditor")
if loadFont:
font.setFamily(loadFont)
fontSize = settings.value("pythonConsole/fontsizeEditor", type=int)
if fontSize:
font.setPointSize(fontSize)
self.lexer.setDefaultFont(font)
self.lexer.setDefaultColor(QColor(settings.value("pythonConsole/defaultFontColorEditor", QColor(self.DEFAULT_COLOR))))
self.lexer.setColor(QColor(settings.value("pythonConsole/commentFontColorEditor", QColor(self.COMMENT_COLOR))), 1)
self.lexer.setColor(QColor(settings.value("pythonConsole/numberFontColorEditor", QColor(self.NUMBER_COLOR))), 2)
self.lexer.setColor(QColor(settings.value("pythonConsole/keywordFontColorEditor", QColor(self.KEYWORD_COLOR))), 5)
self.lexer.setColor(QColor(settings.value("pythonConsole/classFontColorEditor", QColor(self.CLASS_COLOR))), 8)
self.lexer.setColor(QColor(settings.value("pythonConsole/methodFontColorEditor", QColor(self.METHOD_COLOR))), 9)
self.lexer.setColor(QColor(settings.value("pythonConsole/decorFontColorEditor", QColor(self.DECORATION_COLOR))), 15)
self.lexer.setColor(QColor(settings.value("pythonConsole/commentBlockFontColorEditor", QColor(self.COMMENT_BLOCK_COLOR))), 12)
self.lexer.setColor(QColor(settings.value("pythonConsole/singleQuoteFontColorEditor", QColor(self.SINGLE_QUOTE_COLOR))), 4)
self.lexer.setColor(QColor(settings.value("pythonConsole/doubleQuoteFontColorEditor", QColor(self.DOUBLE_QUOTE_COLOR))), 3)
self.lexer.setColor(QColor(settings.value("pythonConsole/tripleSingleQuoteFontColorEditor", QColor(self.TRIPLE_SINGLE_QUOTE_COLOR))), 6)
self.lexer.setColor(QColor(settings.value("pythonConsole/tripleDoubleQuoteFontColorEditor", QColor(self.TRIPLE_DOUBLE_QUOTE_COLOR))), 7)
self.lexer.setColor(QColor(settings.value("pythonConsole/defaultFontColorEditor", QColor(self.DEFAULT_COLOR))), 13)
self.lexer.setFont(font, 1)
self.lexer.setFont(font, 3)
self.lexer.setFont(font, 4)
self.lexer.setFont(font, QsciLexerPython.UnclosedString)
for style in range(0, 33):
paperColor = QColor(settings.value("pythonConsole/paperBackgroundColorEditor", QColor(self.BACKGROUND_COLOR)))
self.lexer.setPaper(paperColor, style)
self.api = QsciAPIs(self.lexer)
useDefaultAPI = bool(settings.value('pythonConsole/preloadAPI',
True))
if useDefaultAPI:
# Load QGIS API shipped with Python console
self.api.loadPrepared(
os.path.join(QgsApplication.pkgDataPath(),
'python', 'qsci_apis', 'pyqgis.pap'))
else:
# Load user-defined API files
apiPaths = settings.value('pythonConsole/userAPI', [])
for path in apiPaths:
self.api.load(path)
self.api.prepare()
self.lexer.setAPIs(self.api)
self.setLexer(self.lexer)
示例4: ShellScintilla
# 需要导入模块: from qgis.PyQt.Qsci import QsciAPIs [as 别名]
# 或者: from qgis.PyQt.Qsci.QsciAPIs import prepare [as 别名]
#.........这里部分代码省略.........
font.setPointSize(fontSize)
font.setStyleHint(QFont.TypeWriter)
font.setStretch(QFont.SemiCondensed)
font.setLetterSpacing(QFont.PercentageSpacing, 87.0)
font.setBold(False)
self.lexer.setDefaultFont(font)
self.lexer.setDefaultColor(QColor(self.settings.value("pythonConsole/defaultFontColor", QColor(Qt.black))))
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentFontColor", QColor(Qt.gray))), 1)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/keywordFontColor", QColor(Qt.darkGreen))), 5)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/classFontColor", QColor(Qt.blue))), 8)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/methodFontColor", QColor(Qt.darkGray))), 9)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/decorFontColor", QColor(Qt.darkBlue))), 15)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentBlockFontColor", QColor(Qt.gray))), 12)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/singleQuoteFontColor", QColor(Qt.blue))), 4)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/doubleQuoteFontColor", QColor(Qt.blue))), 3)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/tripleSingleQuoteFontColor", QColor(Qt.blue))), 6)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/tripleDoubleQuoteFontColor", QColor(Qt.blue))), 7)
self.lexer.setFont(font, 1)
self.lexer.setFont(font, 3)
self.lexer.setFont(font, 4)
for style in range(0, 33):
paperColor = QColor(self.settings.value("pythonConsole/paperBackgroundColor", QColor(Qt.white)))
self.lexer.setPaper(paperColor, style)
self.api = QsciAPIs(self.lexer)
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True, type=bool)
chekBoxPreparedAPI = self.settings.value("pythonConsole/usePreparedAPIFile", False, type=bool)
if chekBoxAPI:
pap = os.path.join(QgsApplication.pkgDataPath(), "python", "qsci_apis", "pyqgis.pap")
self.api.loadPrepared(pap)
elif chekBoxPreparedAPI:
self.api.loadPrepared(self.settings.value("pythonConsole/preparedAPIFile"))
else:
apiPath = self.settings.value("pythonConsole/userAPI", [])
for i in range(0, len(apiPath)):
self.api.load(apiPath[i])
self.api.prepare()
self.lexer.setAPIs(self.api)
self.setLexer(self.lexer)
## TODO: show completion list for file and directory
def getText(self):
""" Get the text as a unicode string. """
value = self.getBytes().decode('utf-8')
# print (value) printing can give an error because the console font
# may not have all unicode characters
return value
def getBytes(self):
""" Get the text as bytes (utf-8 encoded). This is how
the data is stored internally. """
len = self.SendScintilla(self.SCI_GETLENGTH) + 1
bb = QByteArray(len, '0')
self.SendScintilla(self.SCI_GETTEXT, len, bb)
return bytes(bb)[:-1]
def getTextLength(self):
return self.SendScintilla(QsciScintilla.SCI_GETLENGTH)
def get_end_pos(self):
"""Return (line, index) position of the last character"""
line = self.lines() - 1
示例5: PrepareAPIDialog
# 需要导入模块: from qgis.PyQt.Qsci import QsciAPIs [as 别名]
# 或者: from qgis.PyQt.Qsci.QsciAPIs import prepare [as 别名]
class PrepareAPIDialog(QDialog):
def __init__(self, api_lexer, api_files, pap_file, parent=None):
QDialog.__init__(self, parent)
self.ui = Ui_APIsDialogPythonConsole()
self.ui.setupUi(self)
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Compile APIs"))
self.ui.plainTextEdit.setVisible(False)
self.ui.textEdit_Qsci.setVisible(False)
self.adjustSize()
self._api = None
self.ui.buttonBox.rejected.connect(self._stopPreparation)
self._api_files = api_files
self._api_lexer = api_lexer
self._pap_file = pap_file
def _clearLexer(self):
# self.ui.textEdit_Qsci.setLexer(0)
self.qlexer = None
def _stopPreparation(self):
if self._api is not None:
self._api.cancelPreparation()
self._api = None
self._clearLexer()
self.close()
def _preparationFinished(self):
self._clearLexer()
if os.path.exists(self._pap_file):
os.remove(self._pap_file)
self.ui.label.setText(QCoreApplication.translate("PythonConsole", "Saving prepared file..."))
prepd = self._api.savePrepared(self._pap_file)
rslt = self.trUtf8("Error")
if prepd:
rslt = QCoreApplication.translate("PythonConsole", "Saved")
self.ui.label.setText(u'{0} {1}'.format(self.ui.label.text(), rslt))
self._api = None
self.ui.progressBar.setVisible(False)
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setText(
QCoreApplication.translate("PythonConsole", "Done"))
self.adjustSize()
def prepareAPI(self):
# self.ui.textEdit_Qsci.setLexer(0)
exec(u'self.qlexer = {0}(self.ui.textEdit_Qsci)'.format(self._api_lexer))
# self.ui.textEdit_Qsci.setLexer(self.qlexer)
self._api = QsciAPIs(self.qlexer)
self._api.apiPreparationFinished.connect(self._preparationFinished)
for api_file in self._api_files:
self._api.load(api_file)
try:
self._api.prepare()
except Exception as err:
self._api = None
self._clearLexer()
self.ui.label.setText(QCoreApplication.translate("PythonConsole", "Error preparing file..."))
self.ui.progressBar.setVisible(False)
self.ui.plainTextEdit.setVisible(True)
self.ui.plainTextEdit.insertPlainText(err)
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setText(
self.trUtf8("Done"))
self.adjustSize()