Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #619 from slarosa/generate_pap
[FEATURE] Module to generate prepared APIs file for call tips and auto-completion in Python Console
- Loading branch information
Showing
7 changed files
with
376 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# -*- coding:utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
Module to generate prepared APIs for calltips and auto-completion. | ||
------------------- | ||
begin : 2012-09-10 | ||
copyright : (C) 2012 Larry Shaffer | ||
email : larrys (at) dakotacarto (dot) com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
Portions of this file contain code from Eric4 APIsManager module. | ||
""" | ||
|
||
import sys | ||
import os | ||
import shutil | ||
import fnmatch | ||
import glob | ||
|
||
from PyQt4.Qsci import * | ||
from PyQt4.QtGui import * | ||
from PyQt4.QtCore import * | ||
|
||
from ui_console_compile_apis import Ui_APIsDialogPythonConsole | ||
|
||
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(unicode(self._pap_file)) | ||
rslt = self.trUtf8("Error") | ||
if prepd: | ||
rslt = QCoreApplication.translate("PythonConsole","Saved") | ||
self.ui.label.setText('{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 '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(unicode(api_file)) | ||
try: | ||
self._api.prepare() | ||
except Exception, 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>APIsDialogPythonConsole</class> | ||
<widget class="QDialog" name="APIsDialogPythonConsole"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>320</width> | ||
<height>280</height> | ||
</rect> | ||
</property> | ||
<property name="minimumSize"> | ||
<size> | ||
<width>320</width> | ||
<height>0</height> | ||
</size> | ||
</property> | ||
<property name="windowTitle"> | ||
<string/> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label"> | ||
<property name="minimumSize"> | ||
<size> | ||
<width>320</width> | ||
<height>0</height> | ||
</size> | ||
</property> | ||
<property name="text"> | ||
<string>Generating prepared API file (please wait)...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QProgressBar" name="progressBar"> | ||
<property name="enabled"> | ||
<bool>true</bool> | ||
</property> | ||
<property name="maximum"> | ||
<number>0</number> | ||
</property> | ||
<property name="value"> | ||
<number>-1</number> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPlainTextEdit" name="plainTextEdit"> | ||
<property name="font"> | ||
<font> | ||
<pointsize>12</pointsize> | ||
</font> | ||
</property> | ||
<property name="readOnly"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QsciScintilla" name="textEdit_Qsci"> | ||
<property name="toolTip"> | ||
<string/> | ||
</property> | ||
<property name="whatsThis"> | ||
<string/> | ||
</property> | ||
<property name="verticalScrollBarPolicy"> | ||
<enum>Qt::ScrollBarAlwaysOff</enum> | ||
</property> | ||
<property name="horizontalScrollBarPolicy"> | ||
<enum>Qt::ScrollBarAlwaysOff</enum> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<customwidgets> | ||
<customwidget> | ||
<class>QsciScintilla</class> | ||
<extends>QFrame</extends> | ||
<header>Qsci/qsciscintilla.h</header> | ||
</customwidget> | ||
</customwidgets> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.