[Qgis-developer] [New Feature] - AutoCompletion for QGIS Python Console based on QScintilla2
Salvatore Larosa
lrssvtml at gmail.com
Fri Sep 7 10:08:58 PDT 2012
Hi all,
after the precious Larry's advice, I made some changes to the
console for highlighting styles and traceback one, few things [1] !
Currently lacks only the insertion of text from "mimeData". [2]
Rigth now I'm very busy and I cannot seem to implement additional
features suggested by Larry, I hope in the future I will!
After introducing mimeData stuff, I'll clean the code and then share it!!
Greetings!
[1] - http://lrssvt.ns0.it/newPythonConsole.ogv
[2] - https://github.com/qgis/Quantum-GIS/blob/master/python/console.py#L269
> 2012/9/4 Larry Shaffer <larrys at dakotacarto.com>:
>> Hi Salvatore,
>>
>> On Tue, Sep 4, 2012 at 9:13 AM, Salvatore Larosa <lrssvtml at gmail.com> wrote:
>>> Hello everyone, I am working to implement the auto complete in QGIS
>>> python console.
>>> At the time, I came to this result: [1]
>>
>> That looks great already! Very welcome addition.
>>
>>> Still a few things missing:
>>> 1) run command with multi-line text
>>> 2) styled text for errors, traceback, message etc.
>>
>> If you're thinking of tinkering with the traceback output dialog,
>> please consider some of the suggestions put forth here [0], which
>> include more complete frame info, like variables, etc. There is
>> already good sample code for this in the Django project debug output
>> (as mentioned by Martin)[1].
>>
>> For styling purposes, it may be possible to output the traceback in
>> HTML, like with Django, then style it with CSS in a QWebView (see
>> Martin's initial response to my post).
>>
>> [0] http://osgeo-org.1560.n6.nabble.com/Changes-to-python-utils-py-td4977090.html
>> [1] https://github.com/django/django/blob/master/django/views/debug.py
>>
>>> 3) fix up events when keys are pressed (keyPressEvent)
>>> 4) other minor errors.
>>>
>>> Basically I changed the class QTextEdit with QsciScintilla using
>>> pieces of code from [2]
>>> and, for API syntax, the files provided by Larry Shaffer (thanks).
>>>
>>> I'm having some difficulties as disable the undo/redo and I can not
>>> use styles to the text (font, color, etc) if the Lexer is enabled!
>>
>> Concerning undo, it looks like you can't turn it off, but maybe you
>> can just make sure its buffer is always emptied if it contains
>> anything instead? (not tested)
>>
>> Qsci-object.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER)
>>
>>
>> Concerning styles, some are set for the Qsci object and some are set
>> for its currently bound lexer (I assume you are using
>> QsciLexerPython). I believe styles can be adjusted either before the
>> lexer is applied or after (though you may have to clear them first, if
>> after).
>>
>> For examples of doing this see Eric4 source here [0], specifically
>> __setTextDisplay() method for styling Qsci object at line #2156 and
>> here[1] for info on setting lexer style blocks. For the lexer styles,
>> you instantiate the lexer then override the styles you want using
>> their lexer-specific enum value as a reference (e.g. keyword, number,
>> operator, etc.) [2], then apply the lexer to the Qsci object:
>>
>> lexer-object.setColor(QColor, 1) # for setting color of operators
>>
>> If you change the coloring styles, I believe you lastly need to call
>> Qsci-object.recolor().
>>
>> [0] http://die-offenbachs.homelinux.org:48888/viewvc/eric4%20IDE/eric4/trunk/QScintilla/MiniEditor.py?view=markup
>> [1] http://die-offenbachs.homelinux.org:48888/viewvc/eric4%20IDE/eric4/trunk/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py?view=markup
>> [2] http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciLexer.html
>> , http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/classQsciLexerPython.html
>>
>>
>>> Any feedback and help are welcome!
>>
>> I did some research on QScintilla2 APIs and QGIS supported platforms
>> and their distros. I came to the conclusion that, at this time, the
>> QScintilla2 API to use is 2.4.5 (no higher). This supports as far back
>> as Natty on Ubuntu desktop, but is possibly even a bit too new for
>> some distros like CentOS. You can download the docs as part of the
>> source here [0].
>>
>> [0] http://packages.ubuntu.com/source/natty/qscintilla2
>>
>>
>> Also, concerning the compiled .api files, it would be very
>> advantageous to have the Python 2.7 .api mixed in there as well (if
>> it's not). That api file should be included in the current source of
>> QScintilla2 ( <src-dir>/qsci/api/python or
>> /usr/local/Qt4.?/qsci/api/python/ ). Not sure if you included a PyQt4
>> api as well, but that should probably be based off of Qt 4.6 or 4.7,
>> depending upon current unfinished(?) decision on QGIS base Qt version
>> to support with next release.
>>
>> I have most of these api files archived, if you need any. I have
>> tested the Qsci editor in QGIS with over 54,000 compiled api lines
>> with no appreciable slow down, though the list of possible completions
>> gets too long.
>>
>> In my Plugin Editor plugin, I currently store a user-generated
>> compiled api file in ~/.config/QGIS_PluginEditor/python.pap [0].
>> However, if it were QGIS-generic, say, ~/.config/qgis_apis/python.pap
>> instead, anyone who uses my plugin or Eric4 can compile a custom
>> python.pap and place it in ~/.config/qgis_apis/python.pap to
>> user-override the console's auto-completion and call tips (very
>> handy!). Most Python packages (osgeo, for example) can be loaded into
>> Eric4 and have a Qsci-compatible api file generated.
>>
>> [0] http://dl.dropbox.com/u/4058089/qgis/editor_apis.png
>>
>> Regards,
>>
>> Larry
>>
>>
>>> Regards,
>>>
>>> -SL
>>>
>>> [1] - http://lrssvt.ns0.it/autocompletion.ogv
>>> [2] - https://code.google.com/p/pydee/
>>>
>>> --
>>> Salvatore Larosa
>>> linkedIn: http://linkedin.com/in/larosasalvatore
>>> twitter: @lrssvt
>>> skype: s.larosa
>>> IRC: lrssvt on freenode
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
>
> --
> Salvatore Larosa
> linkedIn: http://linkedin.com/in/larosasalvatore
> twitter: @lrssvt
> skype: s.larosa
> IRC: lrssvt on freenode
--
Salvatore Larosa
linkedIn: http://linkedin.com/in/larosasalvatore
twitter: @lrssvt
skype: s.larosa
IRC: lrssvt on freenode
More information about the Qgis-developer
mailing list