An often-requested feature that we've added to Wing IDE version 5.0.9 is the ability to mark a range of code in the editor as "active" so it is easily reevaluated in the Python Shell or Debug Probe. This makes it easier to work interactively with Python without having to copy and paste code between the Python Shell or Debug Probe and the editor.
To use this feature, select a range of code in the editor and press the Set Active Range icon in the top right of the Python Shell or Debug Probe. This marks the range in the editor and adds an Evaluate Active Range icon for evaluating the range and a Visit Active Range icon for visiting the active range in the editor to the top right of the shell tool. The Remove Active Range icon can be used to remove the active range.
Here is an example of this feature in action, in the integrated Python Shell:
The same capability exists in the Debug Probe, which is a Python Shell that acts in the context of the currently active debug stack frame.
Setting up Key Bindings
There are no default key bindings for these actions, but keys can be bound to them using the User Interface > Keyboard > Custom Key Bindings preference. The commands defined are:
python-shell-toggle-active-range sets or clears the active range in the Python Shell, using the current selection or current line in the editor when setting the range.
python-shell-evaluate-active-range evaluates the current active range in the Python Shell.
python-shell-show-active-range shows the Python Shell's active range in the editor.
Similar commands are defined for the Debug Probe: debug-probe-toggle-active-range, debug-probe-evaluate-active-range, and debug-probe-show-active-range.
Check out our new screencast, which shows some of the features of Wing IDE Professional version 5 in action:
Share this article:
In the previous blog post we talked about how auto-editing in Wing IDE Pro can be used to speed up writing and editing Python code. Now let's look at how the auto-completer works with other parts of the IDE to make coding easier.
By default, Wing's auto-completer uses the Tab key for completion, but this can be changed with the Editor > Auto-Completion > Completion Keys preference. The same preferences group lets you specify whether to show the completer immediately or only after a certain number of characters or time, how to place the completion, and various other options.
Here is what the completer looks like in action:
Configuring the Python Path
Auto-completion and many of Wing's other features rely on the IDE's analysis of your source code and the code that you import. If Wing cannot find some of the imported modules, it cannot offer editing assistance for them. Often this just works, but in some cases you may need add to the Python Path in Wing's Project Properties, accessed from the Project menu.
Notice that the auto-completer contains two columns of icons like and that indicate the origin and type of the symbol. These are described in detail in the Auto-Completer documentation.
The completer also offers code snippets appropriate for the current context. These are indicated with the icon. The default set of snippets that come with Wing IDE may be viewed and altered in the Snippets tool in the Tools menu.
Here is an example of entering snippets with the auto-completer, showing how the same snippet may enter different code, according to context:
Editing with the Debugger
Normally, Wing's auto-completer shows type information obtained through static analysis of your code and the libraries that you import. This works well in most cases, but may fail in dynamic code that resists static analysis.
A quick and easy way to get around this is to set a breakpoint in the code you are working on and start the debugger to reach that breakpoint. Once this is done, the auto-completer uses both static analysis and runtime type analysis in any code that is active on the debug process stack. The source of a symbol in the completer is indicated with the icon.
Starting the debugger is usually just a question of selecting Start/Continue in the Debug menu or using the toolbar icon. In some cases you may first need to set up and configure a project.
Here is an example of this:
Working while the debugger is active also lets you try out new code right away. We'll talk more about that in the next blog post.
Turbo Completion Mode
Wing's auto-completer offers another completion mode for Python that can be incredibly productive, particularly when working with the live runtime state, as described above. It turns all non-symbol keys into completion keys in a context-appropriate way, according to where you are typing, what you are typing, and what key you have just pressed.
So, for example, pressing the = key after an argument completes the argument but pressing the = key after for x does not because you are defining a new symbol x.
Turbo-completion is illustrated in the following:
This mode is off by default because it requires some getting used to. But it is well worth learning and can be enabled with the Edit > Auto-completion > Python Turbo Mode preference.
Using the Source Assistant
The Source Assistant is where Wing shows more details about the type of a symbol, including documentation, call signature, and information about object inheritance and overridden methods. For builtin types and the standard library, this includes also links into Python documentation.
The Source Assistant is integrated with every part of Wing IDE, so it shows information for the current selection in the editor, auto-completer, Python Shell, Source Browser, Project manager, and Debug Probe (a shell for interacting with the debug process that we'll talk about next time).
Here are some examples of the Source Assistant in action:
That's it for now. Next time we'll take a detailed look at Wing's debugger.
We're continuously improving Wing's auto-completer and Source Assistant. If you have features you would like to see, or have any questions about the existing features, please email us at email@example.com.
One way in which an IDE speeds up software development is through auto-editing operations. A common example found in almost every text editor is auto-entering ')' after the caret when '(' is pressed.
Wing IDE Professional takes this quite a bit further with a suite of operations that speed up the process of editing Python code. Some of these are disabled by default because they can be disconcerting to new users, but they are well worth exploring. This article explains how to use some of the more advanced auto-editing operations that Wing IDE Pro provides for Python.
If you want to try out each auto-editing operation while reading this, install Wing IDE Pro and Python and go into the Edit > Keyboard Personality menu and Configure Auto-Editing to turn on all the auto-editing operations.
Auto-Enter Invocation Args
This operation causes Wing to automatically insert function or method arguments when an invocation is started, so that you can more easily enter your invocation. For example, when you type getattr( Wing looks up the type of getattr and automatically places the arguments for it. You would end up with getattr(object, name, default=None) in the editor, with the arguments selected.
At this point you can either over-type the selected arguments or tab through them to enter each one. For keyword arguments, tab order visits first the whole argument and then just the value. When you exit the invocation, Wing automatically removes any unaltered default values.
This operation also works if you are entering a def for a method that overrides an inherited method, so that the same arguments that exist in the inherited method are placed automatically.
If you tend to use uniform local variable and function/method argument names then the auto-entered arguments are often all you need. For example, typing self.MyMethod( might get you an invocation like self.MyMethod(path, filename, extend) that works as-is if the locals path, filename, and extend are defined. This can save a lot on typing and reduces opportunities for mistakes.
Here is an example of this feature in action:
Configuring the Python PathAuto-invocation and many of Wing's other features rely on the IDE's analysis of your source code and the code that you import. If Wing cannot find some of the imported modules, it cannot offer editing assistance for them. In most cases, modules are installed into standard locations or Wing is able to read modifications to sys.path from your code, so this is not an issue. However, in some cases you may need add to the Python Path in Wing's Project Properties, accessed from the Project menu.
Manage Blocks with Repeated Colon Presses
A Few Words on IndentationWhile I'm on this topic, let me say a few things about indentation. Wing's default behavior for the Tab key is context-dependent. It does different things at the beginning, middle, and end of a line, when there is a non-empty selection, when the auto-completer is active, and if you're entering a snippet or auto-invocation. This lets you do things like selecting a block of code and toggling its indentation between syntactically valid levels by pressing Tab repeatedly. The behavior of the tab key can be changed with the User Interface > Keyboard > Tab Key Action preference.
Wing also adjusts the indentation of pasted lines. If it gets it wrong, just Undo once to remove the indentation change.
You can convert indentation style in files with the Indentation tool in the Tools menu, there are other indentation operations in the Source > Indentation menu, and there are preferences for adjusting how Wing approaches indentation in the Editor > Indentation preferences group.
When this operation is enabled, placing the caret above a block of existing code and typing if x: causes Wing to automatically place a newline and indent to prepare for input of a new line of code.
Pressing ':' a second time in this context, reformats the code so that the first line of code following the new block is placed under the conditional.
Pressing ':' a third time instead places the whole following block of contiguous lines under the conditional. Reformatting stops at any blank line or indentation decrease.
Here is an example of this in action:
This auto-editing operation also works with for, try, except, else, while, with, and so forth -- anything that starts a new block.
Applying Keys to Selections
Another way to create new blocks of code is to select a range of lines and press the ':' key. This indents the existing lines and starts a new block. Now you can type if, for, or whatever other block type you want to create. Wing auto-inserts except when try is typed and selects except so it can be edited easily. You can press Tab to move into the except (or finally) block.
You can also apply other keys to selections, such as '(', '[', or '[' to surround text with '()', '', or '', press quotes to create strings, or '#' to toggle whether something is commented out. These can be enable or disabled independently from the Editor > Auto-Editing preferences group.
Here this an example of this:
This auto-editing operation is also off by default since it can take some getting used to. When enabled with the Editor > Auto-Editing > Auto-Enter Spaces preference, Wing automatically inserts spacing in a way that conforms to PEP8 style spacing. For example, if you type x=1, Wing will enter x = 1.
With the Enforce PEP8 Style Spacing sub-option enabled, Wing protects against adding extra spaces when you press the space bar.
The Spaces in Argument Lists sub-option lets you override whether to use PEP8 style spaces for arguments. That's probably the most contentious part of PEP8, so we provided an separate option for it.
Notice that the auto-completer also places spacing when this auto-editing operation is enabled. Together with Wing's auto-indent feature and the fact that Wing matches indentation style in existing files, the user is freed most of the time from having to worry about spacing.
Here is an example of this feature in action:
Correct Out-of-Order Typing
When this auto-editing operation is enabled, Wing recognizes some types of out-of-order typing and adjusts them automatically. For example, typing def x(a,b:) enters def x(a, b): plus a new line and indentation. Similarly x(,) is converted to x(),
Here is an example of these operations:
That's it for now. Next time we'll take a detailed look at Wing's autocompleter and Source Assistant.
We're continuously adding to Wing's auto-editing capabilities. If you have auto-editing features you would like to see, or have any questions about the existing features, please email us at firstname.lastname@example.org.
Share this article:
Older blog posts are available at wingware.blogspot.com.