Opened 13 years ago

Last modified 13 years ago

#3408 new patch

Enhancement - Patch to add extra edit area and syntax highlighting to python console

Reported by: NathanW Owned by: wonder
Priority: minor: annoyance Milestone: Version 1.7.0
Component: Python plugins and bindings Version: Trunk
Keywords: Cc:
Must Fix for Release: No Platform: All
Platform Version: Awaiting user input: no

Description

This patch adds a second non-interactive python coding area to the python console. This lets the users write and rearrange python code before running it in the interactive console. Code from the edit area can be run in the interactive area using ctrl+return.

Syntax highlighting has also been implemented, for both the interactive console and the new edit area.

I also run reindent.py which is why the patch has more then what was just added by me.

Attachments (1)

ConsoleEditArea.patch (20.5 KB ) - added by NathanW 13 years ago.

Download all attachments as: .zip

Change History (4)

by NathanW, 13 years ago

Attachment: ConsoleEditArea.patch added

comment:1 by lutra, 13 years ago

Type: enhancementpatch

comment:2 by wonder, 13 years ago

Finally I've got time to take a look at your patch. The proposed improvements are welcome, though I have some comments on the functionality:

  • I don't really like the vertical split between the console text edit box and "source" text edit box - it takes away a lot of space of console. So now I see just very few lines of the console. I would suggest to rework this for better usability. For example, there could be a small tool button which would show/hide the additional edit box - that one would be hidden by default. Also I would suggest to make the split horizontal rather than vertical (the lines are typically not that long). Or even instead of a split it could open a new window for source editing (optionally with the possibility to load/save the code).
  • the syntax highlighter tries to handle everything as python code. This is a bit unfortunate in the console since the output isn't typically python code. As you've noted, that's also why error messages are not highlighted correctly. If you'd like to dig a bit more into syntax highlighting, there's a nice python module "tokenize" which is able to split the text to python tokens: that could be used for parsing python instead of using those nasty regexps.

It would be good to address the issues mentioned above in order to get this into trunk.

Btw. maybe you are aware of Mark Summerfield's nice example of an interactive python console with GUI. It can also do completion and shows tooltips with help on method arguments. It can serve as a source of inspiration for further improvements of the python console in qgis: http://www.qtrac.eu/sandbox.pyw

Martin

comment:3 by NathanW, 13 years ago

No worries. I agree with both points, and both were a concern of mine when I first wrote it. Now that other people are thinking the same I will see how I can improve the usability.

I didn't know about Mark Summerfield's example. That will help a lot.

  • Nathan
Note: See TracTickets for help on using tickets.