Wing Tipshttps://wingware.com/Tips, tricks, and helpful hints for Wingware's Python IDEsSun, 24 May 2020 18:26:27 GMTPyRSS2Gen-1.0.0http://www.dalkescientific.com/Python/PyRSS2Gen.htmlConditional Breakpoints Wing's Python Debuggerhttps://wingware.com/blog/conditional-breakpoints<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use conditional breakpoints in Wing Pro to stop in Python code only when certain conditions are true. This is useful for isolating a single case out of many that may be processed by the same code in a particular run, in order to investigate how that case is being handled.</p> <p>Conditional breakpoints are also a great way to select the runtime state for which you want to write new Python code, with the ability to immediately try out what you write.</p> <div class="section"> <h3 class="title-3">Use Conditional Breakpoints in Debugging</h3> <p>To set a conditional breakpoint, right-click on the breakpoint margin in the editor and select <tt class="literal"><span class="pre">Set</span> <span class="pre">Conditional</span> <span class="pre">Breakpoint</span></tt>:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/set-conditional.gif" alt="Set Conditional Breakpoint" backrefs="" caption="Shown above: Right-click on the breakpoint margin to set a conditional breakpoint." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Right-click on the breakpoint margin to set a conditional breakpoint.</i></p><p>Then start debug with <tt class="literal"><span class="pre">Start/Continue</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu, from the toolbar, or as shown here with <tt class="literal"><span class="pre">Debug</span> <span class="pre">Tests</span></tt> in the <tt class="literal"><span class="pre">Testing</span></tt> tool:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/debug-to-bp.gif" alt="Debug Unit Tests with a Conditional Breakpoint" backrefs="" caption="Shown above: Select a set of unit tests and debug them to reach the conditional breakpoint, then run to the next hit, step over a few lines, and press Shift-Space to view the value of all visible variables." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Select a set of unit tests and debug them to reach the conditional breakpoint, then run to the next hit, step over a few lines, and press Shift-Space to view the value of all visible variables.</i></p></div> <div class="section"> <h3 class="title-3">Use Conditional Breakpoints to Write New Code</h3> <p>Since Wing lets you stop at breakpoints to work on new Python code interactively in the live runtime state of the debug process, conditional breakpoints are also a great way to select the specific runtime case for which you want to write new code. You'll have access to auto-completion that works off the actual runtime state, and can try your code right away in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/interactive.gif" alt="Interactive Development at a Conditional Breakpoint" backrefs="" caption="Shown above: Enter code with auto-completion and auto-editing features that inspect the live runtime state of the debug process, then try out an invocation in the Debug Console." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Enter code with auto-completion and auto-editing features that inspect the live runtime state of the debug process, then try out an invocation in the Debug Console.</i></p><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/conditional-breakpointsWed, 20 May 2020 01:00:00 GMTMoving the Program Counter in Wing's Python Debuggerhttps://wingware.com/blog/move-program-counter2<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to move the program counter while debugging Python code in Wing Personal and Wing Pro. This is a good way to go back and re-execute previously visited Python code, in order to trace through to the cause of a bug without having to restart the debug process.</p> <p>To move the program counter, the debugger must be running and paused or stopped at a breakpoint. Then right-click on the target line in the editor and select <tt class="literal"><span class="pre">Move</span> <span class="pre">Program</span> <span class="pre">Counter</span> <span class="pre">Here</span></tt>:</p> <img src="https://wingware.com/images/blog/move-program-counter2/move-program-counter.gif" alt="Move Program Counter" backrefs="" caption="Shown above: Right-click to select Move Program Counter Here, then continue stepping with Step Over and Step Into in the toolbar." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Right-click to select Move Program Counter Here, then continue stepping with Step Over and Step Into in the toolbar.</i></p><p><strong>Limitations:</strong> Due to the way Python is implemented, the program counter can only be moved within the current inner-most stack frame and it may not be moved within an exception handler, after an exception has been raised but not yet handled.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> https://wingware.com/blog/move-program-counter2Tue, 12 May 2020 01:00:00 GMTQuick Navigation to Project Files in Wing Python IDEhttps://wingware.com/blog/open-from-project<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> highlights a simple but useful feature in Wing Personal and Wing Pro that you might have missed up until now: <tt class="literal"><span class="pre">Open</span> <span class="pre">from</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">File</span></tt> menu.</p> <p>This is usually accessed with its key binding, <tt class="literal"><span class="pre">Ctrl-Shift-O</span></tt>, or <tt class="literal"><span class="pre">Command-Shift-O</span></tt> on macOS. If you've selected a non-default <tt class="literal"><span class="pre">Keyboard</span> <span class="pre">Personality</span></tt> in the <tt class="literal"><span class="pre">Edit</span></tt> menu, a different key binding may be used. Or, if none is defined for that keyboard setting, you can add a binding for command <tt class="literal"><span class="pre">open-from-project</span></tt> with the <tt class="literal"><span class="pre">User</span> <span class="pre">Interface</span> <span class="pre">&gt;</span> <span class="pre">Keyboard</span> <span class="pre">&gt;</span> <span class="pre">Custom</span> <span class="pre">Key</span> <span class="pre">Bindings</span></tt> preference.</p> <p>Executing the command displays a dialog. Entering a fragment narrows the list to include only matching project files:</p> <img src="https://wingware.com/images/blog/open-from-project/open-from-project.gif" alt="/images/blog/open-from-project/open-from-project.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Matching is on the file name only. However, if the fragment includes the path separator, then the match is applied to the full path of the file, including also enclosing directory names:</p> <img src="https://wingware.com/images/blog/open-from-project/match-full-path.gif" alt="/images/blog/open-from-project/match-full-path.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>The first few items in the dialog are the most recently opened files, so these can be selected quickly with the down arrow and by pressing <tt class="literal"><span class="pre">Enter</span></tt>. Even if a file is already open, using <tt class="literal"><span class="pre">Open</span> <span class="pre">From</span> <span class="pre">Project</span></tt> is often the fastest way to move between different source files.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> https://wingware.com/blog/open-from-projectWed, 22 Apr 2020 01:00:00 GMTDebug Python Services Running on AWS with Wing Prohttps://wingware.com/blog/aws-2<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we're continuing our look at how to use Wing Pro to remotely develop Python code running on an AWS instance. This time we'll set up remote debugging of code that is launched from outside of the IDE. This can be useful in debugging web apps and other services.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>Before getting started, you will need an AWS instance that you can SSH into, and you'll want to set up a Wing project for that AWS instance. If you don't already have this working, take a look at last's weeks Wing Tip: <a class="reference" href="/hints/aws-1">Remote Python Development on AWS with Wing Pro</a>.</p> <p>The small debugging example given in the above link launched the remote code being debugged from the IDE. The code actually runs on the AWS instance, but Wing launches it with the help of its remote agent. Now we're instead going to set up debugging remote code that is launched outside of control of the IDE.</p> <p>This is done by (1) using Wing Pro's remote development support to set up a reverse SSH tunnel to the remote AWS instance, so that the debugger can connect back to the IDE, and then (2) inserting an import into code that starts debug and makes the connection to the IDE.</p> </div> <div class="section"> <h3 class="title-3">Setting up Remote Listening</h3> <p>In the project you have set up for your remote AWS instance, click on the bug icon in the lower left of Wing's window to check on <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>:</p> <img src="https://wingware.com/images/blog/aws-2/debug-menu.png" alt="/images/blog/aws-2/debug-menu.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="383px" /><p>Now if you hover the mouse over the bug icon, you will see that Wing reports that it is listening for debug connections on the remote host on port <tt class="literal"><span class="pre">50050</span></tt>, as well as listening on the local host:</p> <img src="https://wingware.com/images/blog/aws-2/debug-status.png" alt="/images/blog/aws-2/debug-status.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="781px" /></div> <div class="section"> <h3 class="title-3">Starting Debug</h3> <p>To keep things simple, rather than setting up a web development framework or other service, we'll test with a simple <tt class="literal"><span class="pre">helloworld.py</span></tt> example that we launch manually from the command line outside of Wing.</p> <p>You can create this file on the AWS instance by right-clicking on a directory you previously added to Wing's <tt class="literal"><span class="pre">Project</span></tt> tool and selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">File</span></tt>. This collects the new file name in a dialog or, in some keyboard configurations, in the status area at the bottom of Wing's window, and then opens the file in the editor.</p> <p>Then paste in the following code and save the file:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">wingdbstub</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">print</span><span class="p">(</span><span class="s">&quot;Hello&quot;</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span> <span class="n">x</span> <span class="o">+=</span><span class="mi">1</span> <span class="k">print</span><span class="p">(</span><span class="s">&quot;Goodbye&quot;</span><span class="p">,</span><span class="n">x</span><span class="p">)</span> </pre></div> <p>Notice that the first line <tt class="literal"><span class="pre">import</span> <span class="pre">wingdbstub</span></tt> starts debug and connects to the IDE through the reverse SSH tunnel you set up in the previous section.</p> <p>In order for this to work, you need to copy the automatically preconfigured file <tt class="literal"><span class="pre">~/.wingpro7/remote-#.#.#.#/wingdbstub.py</span></tt> on the remote host (where #.#.#.# is the version of Wing you running) into the same directory as <tt class="literal"><span class="pre">helloworld.py</span></tt>. This can be done by opening the file in Wing and using <tt class="literal"><span class="pre">Save</span> <span class="pre">As</span></tt>. Or just connect to your AWS instance, <tt class="literal"><span class="pre">cd</span></tt> into your target directory, and copy it into place:</p> <pre class="literal-block"> cp ~/.wingpro7/remote-#.#.#.#/wingdbstub.py . </pre> <p>If you are using Lightsail, a convenient way to connect to your instance is <tt class="literal"><span class="pre">Connect</span> <span class="pre">Using</span> <span class="pre">SSH</span></tt> under the <tt class="literal"><span class="pre">Connect</span></tt> tab in the Amazon Lightsail management interface.</p> <p>Finally, set a breakpoint on line 3 of the test code so it will not just run to completion, but instead will stop in Wing's debugger. This is done by clicking on the leftmost margin in the editor:</p> <img src="https://wingware.com/images/blog/aws-2/breakpoint.png" alt="/images/blog/aws-2/breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="309px" /><p>Now you can start debug just by launching the test code outside of Wing:</p> <pre class="literal-block"> python3 helloworld.py </pre> <p>The first time you do this, Wing may refuse the connection and ask whether you want to accept the security token for this host. This happens if you installed the remote agent earlier from a different Wing installation:</p> <img src="https://wingware.com/images/blog/aws-2/security-token.png" alt="/images/blog/aws-2/security-token.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="722px" /><p>If this dialog appears, click <tt class="literal"><span class="pre">Accept</span></tt> and then start the test code a second time:</p> <pre class="literal-block"> python3 helloworld.py </pre> <p>This time Wing will accept the connection and should stop on your breakpoint:</p> <img src="https://wingware.com/images/blog/aws-2/stopped.png" alt="/images/blog/aws-2/stopped.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="351px" /><p>From here, you can inspect your debug process in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> or <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt>, set other breakpoints or conditional breakpoints, step through code, and so forth. For more information on the capabilities of Wing's debugger, see the <a class="reference" href="/doc/debug/quick-start">Debugger Quick Start</a> or the tutorial in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Notes</h3> <p>To actually set up Wing to work with a web development framework on your AWS instance, see our How-Tos for <a class="reference" href="/doc/howtos/flask">Flask</a>, <a class="reference" href="/doc/howtos/django">Django</a>, or <a class="reference" href="/doc/howtos/web">other web development frameworks</a>. These explain additional configuration that may be needed in each case.</p> <p>Wing's debugger also provides a simple <a class="reference" href="/doc/debug/debugger-api">debugger API</a> that may be useful, for example in developing a way to turn the debugger on and off on demand or controlling which threads are debugged.</p> <p>For detailed documentation see the <a class="reference" href="/doc/debug/index">Debugger</a> and <a class="reference" href="/doc/debug/advanced">Advanced Debugging Topics</a> chapters in Wing Pro's user manual.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/aws-2Tue, 07 Apr 2020 01:00:00 GMTRemote Python Development on AWS with Wing Prohttps://wingware.com/blog/aws-1<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll start looking at how to use Wing Pro to remotely develop Python code running on an AWS instance. With minimal configuration, Wing Pro can edit, debug, test, inspect, and navigate Python code residing on an AWS instance, as if it were on the local host.</p> <div class="section"> <h3 class="title-3">Minimum Requirements</h3> <p>You will need an AWS instance that has Python installed on it, is running 32-bit or 64-bit Intel Linux, and that you can connect to using OpenSSH or PuTTY. PuTTY is recommended on Windows because it tends to be prone to fewer problems. You will need the following in order to configure Wing Pro to use your AWS instance:</p> <p><strong>(1)</strong> The user name and static IP address or DNS name used to connect to the AWS instance. Amazon Lightsail typically uses an IP address while EC2 and other variants of AWS may provide a DNS name as well. The static IP address will work in any case.</p> <p><strong>(2)</strong> The SSH key pair in a <tt class="literal"><span class="pre">*.pem</span></tt> file, as downloaded from AWS.</p> <p>If you do not already have Wing Pro installed, <a class="reference" href="https://wingware.com/downloads/wingpro">download it now</a>.</p> </div> <div class="section"> <h3 class="title-3">Setting up AWS</h3> <p><em>If you already have an AWS instance to work with, you can skip this section.</em></p> <p><a class="reference" href="https://aws.amazon.com/lightsail/">Amazon Lightsail</a> is the easiest way to get an AWS instance, in about 5 minutes. You will need to set up an account. Then create a <tt class="literal"><span class="pre">Linux/Unix</span></tt> instance, selecting the <tt class="literal"><span class="pre">OS</span> <span class="pre">Only</span></tt> option and the most recent <tt class="literal"><span class="pre">Ubuntu</span></tt> or any other Intel Linux with Python 2 or 3 on it.</p> <p>While setting up your instance, you can download your SSH key pair under the AWS <tt class="literal"><span class="pre">SSH</span> <span class="pre">key</span> <span class="pre">pair</span> <span class="pre">manager</span></tt>. You'll need this on your local machine, where Wing is running, in order to be able to connect to the instance.</p> <p>After the instance is created, it will remain in <tt class="literal"><span class="pre">pending</span></tt> state for a minute or so. Once it is up and running, create a static IP address under the <tt class="literal"><span class="pre">Network</span></tt> tab in the AWS Lightsail management area and attach it to your instance.</p> <p>At this point you have all that is needed to start using Wing Pro with AWS: (1) The SSH key pair that you downloaded, and (2) the user name and IP address, which are shown on the Lightsail instance management page.</p> </div> <div class="section"> <h3 class="title-3">Testing the SSH Connection</h3> <p>Before trying to use your new instance from Wing Pro, you should first try to connect using <tt class="literal"><span class="pre">ssh</span></tt> or PuTTY's <tt class="literal"><span class="pre">plink.exe</span></tt> on the command line, to make sure those are working. This is important because Wing invokes those command lines to connect to the instance.</p> <p><strong>OpenSSH</strong></p> <p>On Linux or macOS using <tt class="literal"><span class="pre">ssh</span></tt>, you need to make your <tt class="literal"><span class="pre">*.pem</span></tt> SSH key pair file readable only by the user running Wing, for example with:</p> <pre class="literal-block"> chmod 600 aws.pem </pre> <p>Otherwise, <tt class="literal"><span class="pre">ssh</span></tt> will reject it as potentially compromised.</p> <p>Once that is done, try connecting as follows, substituting the actual path to your downloaded SSH key pair and your instance's username and IP address or DNS name:</p> <pre class="literal-block"> ssh -i /path/to/mykey.pem ubuntu&#64;11.22.33.44 </pre> <p>You will be asked to add the instance's identity to your known hosts file, which you should do by typing <tt class="literal"><span class="pre">yes</span></tt>. If this is not done, <tt class="literal"><span class="pre">ssh</span></tt> will fail to connect and Wing will also not be able to connect to the instance.</p> <p><strong>PuTTY</strong></p> <p>With PuTTY on Windows, you will need to first convert the SSH key to a format that PuTTY can use. This is done by launching <tt class="literal"><span class="pre">puttygen</span></tt>, pressing the <tt class="literal"><span class="pre">Load</span></tt> button to read the <tt class="literal"><span class="pre">*.pem</span></tt> SSH key file you downloaded from the AWS management site, and then using <tt class="literal"><span class="pre">Save</span> <span class="pre">Private</span> <span class="pre">Key</span></tt> to write a <tt class="literal"><span class="pre">*.ppk</span></tt> file.</p> <p>Then you invoke <tt class="literal"><span class="pre">plink.exe</span></tt> to connect to the AWS instance as follows, substituting in the actual path to your downloaded SSH key pair and the correct username and IP address or DNS name for the AWS instance:</p> <pre class="literal-block"> plink.exe -i C:\path\to\mykey.ppk ubuntu&#64;11.22.33.44 </pre> <p>You will be asked to accept the AWS instance's identity the first time you connect, and this must be done before Wing's remote development support will work with the AWS instance.</p> </div> <div class="section"> <h3 class="title-3">Creating a Wing Project</h3> <p>Now you're ready to create a project in Wing Pro. This is done with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu. Select <tt class="literal"><span class="pre">Connect</span> <span class="pre">to</span> <span class="pre">Remote</span> <span class="pre">Host</span> <span class="pre">via</span> <span class="pre">SSH</span></tt> as your project type. Then enter an identifier for the remote host (any short string to identify it in Wing's UI), and the user name and IP address or DNS name used to connect to the host:</p> <img src="https://wingware.com/images/blog/aws-1/new-project.png" alt="/images/blog/aws-1/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="716px" /><p>As in the above example, <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> will usually be <tt class="literal"><span class="pre">Use</span> <span class="pre">default</span></tt>, which first tries <tt class="literal"><span class="pre">python3</span></tt> and then <tt class="literal"><span class="pre">python</span></tt>. If Python is not on the <tt class="literal"><span class="pre">PATH</span></tt> on your AWS instance or you want to specify a particular Python executable or activate a virtual environment, you can do this here.</p> <p>You will also need to point Wing at the SSH key pair file you downloaded from AWS earlier. This is done under the <tt class="literal"><span class="pre">Options</span></tt> tab using the <tt class="literal"><span class="pre">Private</span> <span class="pre">Key</span></tt> field as follows:</p> <img src="https://wingware.com/images/blog/aws-1/private-key-file.png" alt="/images/blog/aws-1/private-key-file.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="716px" /><p>Pressing <tt class="literal"><span class="pre">OK</span></tt> in the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog will create and configure the project, connect to the remote instance, install Wing's remote agent, and then offer to add source directories to the project or save the new project file:</p> <img src="https://wingware.com/images/blog/aws-1/new-project-confirm.png" alt="/images/blog/aws-1/new-project-confirm.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="612px" /><p>If you already have source code on the AWS instance, press <tt class="literal"><span class="pre">Add</span> <span class="pre">Directory</span></tt> one or more times to add directories to the project. Typically, you want to add the directories that contain code you plan to work on, and leave out directories that contain Python, the standard libraries, and other modules and packages that you may use. Wing can find those as needed, through the Python Path.</p> <p>If you are working with a blank new AWS instance, add the home directory to your project to get started. This can be changed later as needed.</p> <p>Finally, save the project to local disk. The project is now ready to use.</p> </div> <div class="section"> <h3 class="title-3">Testing a Hello World</h3> <p>To try out a simple example of editing and debugging code on the remote AWS instance, create a file <tt class="literal"><span class="pre">helloworld.py</span></tt> temporarily on the instance. This is done by right-clicking on one of the files in the <tt class="literal"><span class="pre">Project</span></tt> tool in Wing Pro and selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">File</span></tt>. Enter the file name (in some key bindings this is in the data entry area at the bottom of Wing's window) and type or paste the following into the new file:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">time</span> <span class="k">print</span><span class="p">(</span><span class="s">&quot;Hello World! {}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()))</span> </pre></div> <p>After saving the file, set a breakpoint on the second line by clicking on the leftmost margin in the editor:</p> <img src="https://wingware.com/images/blog/aws-1/breakpoint.png" alt="/images/blog/aws-1/breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="382px" /><p>Then select <tt class="literal"><span class="pre">Starting/Continue</span></tt> from the <tt class="literal"><span class="pre">Debug</span></tt> menu to start debug, or use the green play icon <img src="https://wingware.com/images/doc/en/icons/wingide-debug-continue.png" alt="play" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> in the toolbar.</p> <p>There is a slight delay to get the process started, depending on your network distance from the AWS instance, but then you should see Wing stop on the breakpoint:</p> <img src="https://wingware.com/images/blog/aws-1/breakpoint-stop.png" alt="/images/blog/aws-1/breakpoint-stop.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="382px" /><p>There's not much to see here, but you can poke around a little in the live runtime state of the paused debug process, using Wing Pro's <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, from the <tt class="literal"><span class="pre">Tools</span></tt> menu:</p> <img src="https://wingware.com/images/blog/aws-1/debug-console.png" alt="/images/blog/aws-1/debug-console.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="526px" /><p>Once you continue debugging, the process will exit and print to the <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool:</p> <img src="https://wingware.com/images/blog/aws-1/debug-io.png" alt="/images/blog/aws-1/debug-io.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="581px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/aws-1Tue, 24 Mar 2020 01:00:00 GMTGoto-Definition From the Interactive Shells in Wing Prohttps://wingware.com/blog/goto-definition-in-shells<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll take a quick look at a lesser-known but often useful feature in Wing Pro: Jumping from symbols in the integrated shells to their point of definition in source code. This makes it a snap to bridge from runtime symbols to the source code where they are actually defined and used.</p> <div class="section"> <h3 class="title-3">Debug Console Example</h3> <p>In this example, the debugger is stopped and I'm working in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, which is an interactive shell that runs in the context of the currently selected debug stack frame. While trying to determine why <tt class="literal"><span class="pre">handler.exit_status</span></tt> is <tt class="literal"><span class="pre">None</span></tt>, I jump to its point of definition from the right-click context menu:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/debug-console.gif" alt="/images/blog/goto-definition-in-shells/debug-console.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>From here, I could set a breakpoint and restart debug, or right-click on the editor to select <tt class="literal"><span class="pre">Find</span> <span class="pre">Points</span> <span class="pre">of</span> <span class="pre">Use</span></tt> to see all the points of use of <tt class="literal"><span class="pre">exit_status</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Python Shell Example</h3> <p>Similarly, I can import a module in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and jump to the point of definition of symbols in the module. Here I'm using this technique to bring up the source code for numpy's <tt class="literal"><span class="pre">ndarray</span></tt>:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/python-shell.gif" alt="/images/blog/goto-definition-in-shells/python-shell.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>In this case, I'm pressing <tt class="literal"><span class="pre">F4</span></tt> to go to the definition, rather than using the right-click context menu.</p> </div> <div class="section"> <h3 class="title-3">Traversing Visit History</h3> <p>To get back from the point of definition to the previously displayed code in the editor, use the browser-like forward/back arrow buttons in the top left of the editor:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/back-arrows.png" alt="/images/blog/goto-definition-in-shells/back-arrows.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="321px" /><p>Pressing <tt class="literal"><span class="pre">Alt-Left</span></tt> or using any other key binding for the command <tt class="literal"><span class="pre">visit-history-previous</span></tt> also goes back in the editor's visit history.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/goto-definition-in-shellsWed, 11 Mar 2020 01:00:00 GMTUsing Anaconda Environments with Wing Python IDEhttps://wingware.com/blog/anaconda-envs<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, and we've been looking at the new features in this version. So far we've covered <a class="reference" href="https://wingware.com/hints/reformatting">reformatting with Black and YAPF</a>, Wing 7.2's <a class="reference" href="https://wingware.com/hints/virtualenv">expanded support for virtualenv</a>, and <a class="reference" href="https://wingware.com/hints/python-m">using python -m with Wing</a>.</p> <p>This time we'll take a look at what Wing 7.2 provides for people that are using Anaconda environments created with <tt class="literal"><span class="pre">conda</span> <span class="pre">create</span></tt> as an alternative to virtualenv.</p> <div class="section"> <h3 class="title-3">What Wing 7.2 Adds</h3> <p>Wing 7.2 supports creating new Wing projects that use an existing Anaconda environment, so that the environment is automatically activated whenever the project is open. Debug processes, unit tests, the integrated Python Shell, and OS Commands all run in the activated environment.</p> <p>Wing 7.2 also added the ability to create and configure a new Anaconda environment while creating a new Wing project.</p> </div> <div class="section"> <h3 class="title-3">Using an Existing Anaconda Environment</h3> <p>Wing tries to discover existing Anaconda environments and lists them in the drop down menu next to the <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> option under <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> and the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog, which are both in the <tt class="literal"><span class="pre">Project</span></tt> menu:</p> <img src="https://wingware.com/images/blog/anaconda-envs/discovered-envs.png" alt="/images/blog/anaconda-envs/discovered-envs.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="606px" /><p>Selecting one of the listed Anaconda environments configures the project to automatically activate that environment whenever the project is open:</p> <img src="https://wingware.com/images/blog/anaconda-envs/selected-env.png" alt="/images/blog/anaconda-envs/selected-env.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="606px" /><p>If Wing cannot find your Anaconda environment automatically, you can instead manually enter the command that activates it.</p> </div> <div class="section"> <h3 class="title-3">Creating New Projects</h3> <p>Wing can also create a new Anaconda environment at the same time that a new Wing project is created. This is done by selected <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu and choosing <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Anaconda</span> <span class="pre">Environment</span></tt> as the project type:</p> <img src="https://wingware.com/images/blog/anaconda-envs/new-project.png" alt="/images/blog/anaconda-envs/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="600px" /><p>Wing will create the new environment, install packages, and then configure and save a project file. You can immediately start working in your new environment, which Wing automatically activates for you whenever you have the project open.</p> <p>That's all there is to it!</p> <p>For some additional details, see <a class="reference" href="https://wingware.com/doc/howtos/anaconda">Using Wing with Anaconda</a>.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/anaconda-envsWed, 26 Feb 2020 01:00:00 GMTUsing "python -m" in Wing 7.2https://wingware.com/blog/python-m<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, and the next couple <a class="reference" href="https://wingware.com/hints">Wing Tips</a> look at some of its new features. We've already looked at <a class="reference" href="https://wingware.com/hints/reformatting">reformatting with Black and YAPF</a> and Wing 7.2's <a class="reference" href="https://wingware.com/hints/virtualenv">expanded support for virtualenv</a>.</p> <p>Now let's look at how to set up debugging modules that need to be launched with <tt class="literal"><span class="pre">python</span> <span class="pre">-m</span></tt>. This command line option for Python allows searching the Python Path for the name of a module or package, and then loading and executing it. This capability was introduced way back in Python 2.4, and then extended in Python 2.5 through <a class="reference" href="https://www.python.org/dev/peps/pep-0338/">PEP 338</a> . However, it only came into widespread use relatively recently, for example to launch <tt class="literal"><span class="pre">venv</span></tt>, <tt class="literal"><span class="pre">black</span></tt>, or other command line tools that are shipped as Python packages.</p> <div class="section"> <h3 class="title-3">Launching Modules</h3> <p>To configure Wing to launch a module by name with <tt class="literal"><span class="pre">python</span> <span class="pre">-m</span></tt>, create a <tt class="literal"><span class="pre">Named</span> <span class="pre">Entry</span> <span class="pre">Point</span></tt> from the <tt class="literal"><span class="pre">Debug</span></tt> menu, select <tt class="literal"><span class="pre">Named</span> <span class="pre">Module</span></tt>, and enter the module or package name and any run arguments:</p> <img src="https://wingware.com/images/blog/python-m/named-entry-point-module.png" alt="/images/blog/python-m/named-entry-point-module.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="472px" /><p>The above is equivalent to this command line:</p> <pre class="literal-block"> python -m mymodule one two </pre> <p>The named entry point can be set as the main entry point for your project under the <tt class="literal"><span class="pre">Debug/Execute</span></tt> tab of <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>, from the <tt class="literal"><span class="pre">Project</span></tt> menu:</p> <img src="https://wingware.com/images/blog/python-m/main-entry-point.png" alt="/images/blog/python-m/main-entry-point.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="585px" /><p>Or it can be launched from the <tt class="literal"><span class="pre">Debug</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Named</span> <span class="pre">Entry</span> <span class="pre">Point</span></tt> menu or by assigning a key binding to it in the named entry point manager dialog.</p> </div> <div class="section"> <h3 class="title-3">Launching Packages</h3> <p>Packages can also be launched in this way, if they include a file named <tt class="literal"><span class="pre">__main__.py</span></tt> to define the package's main entry point:</p> <img src="https://wingware.com/images/blog/python-m/named-entry-point.png" alt="/images/blog/python-m/named-entry-point.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="472px" /></div> <div class="section"> <h3 class="title-3">Setting Python Path</h3> <p>Whether launching a module or package, the name has to be found on the <tt class="literal"><span class="pre">Python</span> <span class="pre">Path</span></tt> that you've configured for your project. If Wing fails to find the module, add its parent directory to <tt class="literal"><span class="pre">Python</span> <span class="pre">Path</span></tt> under the <tt class="literal"><span class="pre">Environment</span></tt> tab in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>:</p> <img src="https://wingware.com/images/blog/python-m/python-path.png" alt="/images/blog/python-m/python-path.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="578px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/python-mTue, 18 Feb 2020 01:00:00 GMTUsing virtualenv with Wing Python IDEhttps://wingware.com/blog/virtualenv<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, and the next couple <a class="reference" href="https://wingware.com/hints">Wing Tips</a> look at some of its new features. <a class="reference" href="https://wingware.com/hints/reformatting">Last time</a> at code reformatting with Black and YAPF. Now let's investigate Wing 7.2's expanded support for virtualenv.</p> <div class="section"> <h3 class="title-3">What Wing 7.2 Adds</h3> <p>Wing 7.2 improves support for virtualenv by allowing the command that activates the environment to be entered in the Python Executable in Project Properties, Launch Configurations, and when creating new projects. This is an easier and more natural way to configure virtualenvs than the old approach of finding and using the virtualenv's Python executable.</p> <p>The New Project dialog now also includes the option to create a new virtualenv along with a new project, optionally specifying packages to install. This makes it much easier to get started on a new code base that uses virtualenv.</p> </div> <div class="section"> <h3 class="title-3">Using an Activated Env</h3> <p>Wing has always supported virtualenv by allowing the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> to be set to the virtualenv's Python, which both activates the env and runs Python. In Wing 7.2 it is possible to instead set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to the command that activates the virtualenv. When this is done, Wing activates the environment and runs <tt class="literal"><span class="pre">python</span></tt> in it.</p> <p>To use this approach, select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> for the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> and enter the activation command:</p> <img src="https://wingware.com/images/blog/virtualenv/properties.png" alt="/images/blog/virtualenv/properties.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="758px" /><p>The drop down menu next to the entry area lists discovered environments and those which have been used recently:</p> <img src="https://wingware.com/images/blog/virtualenv/recent-envs.png" alt="/images/blog/virtualenv/recent-envs.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="446px" /><p>Activated virtualenvs can be used in the same way in other settings where a <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> can be specified, for example for Launch Configurations and in a Remote Host configuration.</p> </div> <div class="section"> <h3 class="title-3">Creating New Projects</h3> <p>There are two options available for virtualenv, when creating a new project from the <tt class="literal"><span class="pre">Project</span></tt> menu: (1) Creating a new virtualenv and new Wing project at the same time, or (2) Creating a new Wing project that uses an existing virtualenv.</p> <div class="section"> <h4 class="title-4">Creating a New virtualenv</h4> <p>To create a new virtualenv along with your project, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu and set the project type to <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Virtualenv</span></tt>. You will then need to enter the name for the virtualenv, select a parent directory where the virtualenv's directory will be written, and optionally specify packages to install and/or the base <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to use. For example:</p> <img src="https://wingware.com/images/blog/virtualenv/new-project-new.png" alt="/images/blog/virtualenv/new-project-new.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="579px" /><p>Wing will create the virtualenv, install packages, and then configure and save a project file. You can immediately start working in your new virtualenv, which Wing automatically activates for you whenever you have the project open.</p> </div> <div class="section"> <h4 class="title-4">Using an Existing virtualenv</h4> <p>To use an existing virtualenv, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu, set the project type to <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Virtualenv</span></tt>, and then enter the activation command:</p> <img src="https://wingware.com/images/blog/virtualenv/new-project-existing.png" alt="/images/blog/virtualenv/new-project-existing.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="573px" /><p>After the new project is created, use <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu to add your source code directories to the project, and then save the project to disk.</p> <p>For some additional details, see <a class="reference" href="https://wingware.com/doc/howtos/virtualenv">Using Wing with virtual</a>.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> </div> https://wingware.com/blog/virtualenvWed, 05 Feb 2020 01:00:00 GMTUsing Black and YAPF Code Reformatting in Wing Python IDEhttps://wingware.com/blog/reformatting<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, so in the next couple <a class="reference" href="https://wingware.com/hints">Wing Tips</a> we'll take a look at some of its new features.</p> <p>Wing 7.2 expands the options for automatic code reformatting to include also <a class="reference" href="https://github.com/psf/black">Black</a> and <a class="reference" href="https://github.com/google/yapf">YAPF</a>, in addition to the previously supported <a class="reference" href="https://github.com/hhatto/autopep8">autopep8</a>. Using one of these allows you to develop nicely formatted uniform-looking code without spending time manually adjusting the layout of code.</p> <p>There are two ways to go about reformatting code in Wing with any of these: (1) You can reformat whole files or the current selection on request at any time, or (2) you can reformat automatically as you edit lines of code or save edited files to disk.</p> <p><strong>Installing Reformatters</strong></p> <p>Wing uses its own copy of autopep8 for PEP 8 style formatting. If you plan to use Black or YAPF formatting instead, then you must first install the selected formatter into the Python that you are using with your code. For example:</p> <pre class="literal-block"> pip install black pip install yapf </pre> <p>Or if you are using Anaconda:</p> <pre class="literal-block"> conda install black conda install yapf </pre> <p>After this is done, running Python on the command line with arguments <tt class="literal"><span class="pre">-m</span> <span class="pre">black</span></tt> or <tt class="literal"><span class="pre">-m</span> <span class="pre">yapf</span></tt> should invoke the reformatter.</p> <p><strong>Manual Reformatting</strong></p> <p>The <tt class="literal"><span class="pre">Source</span> <span class="pre">&gt;</span> <span class="pre">Reformatting</span></tt> menu contains items for reformatting the current file or selection for PEP 8, Black or YAPF:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-menu.png" alt="/images/blog/reformatting/reformat-menu.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="736px" /><p>The result of the above operation (reformatting the selection with Black) looks like this:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-menu-result.png" alt="/images/blog/reformatting/reformat-menu-result.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="643px" /><p>A single <tt class="literal"><span class="pre">Undo</span></tt> will undo the reformatting operation.</p> <p><strong>Automatic Reformatting</strong></p> <p>Wing can also auto-format edited lines after the caret leaves the line, or whole files as they are saved to disk. This is enabled with the <tt class="literal"><span class="pre">Auto-Reformat</span></tt> property under the <tt class="literal"><span class="pre">Options</span></tt> tab in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>, or with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-formatting</span> <span class="pre">&gt;</span> <span class="pre">Auto-Reformat</span></tt> preference:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-automatic.png" alt="/images/blog/reformatting/reformat-automatic.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="362px" /><p>When this is set to <tt class="literal"><span class="pre">Lines</span> <span class="pre">After</span> <span class="pre">Edit</span></tt>, Wing only reformats lines that you have edited, as the editor caret leaves that line or before the file is saved. For example, using yapf as the formatter:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-auto-line.gif" alt="/images/blog/reformatting/reformat-auto-line.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Notice that reformatting applies to whole logical lines which, as in this case, may span more than one physical line.</p> <p>If <tt class="literal"><span class="pre">Whole</span> <span class="pre">Files</span> <span class="pre">Before</span> <span class="pre">Save</span></tt> auto-reformatting is used instead, then the whole file is reformatted before saving it to disk. For example, using Black as the formatter:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-auto-file.gif" alt="/images/blog/reformatting/reformat-auto-file.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Note that Wing implements some timeouts for reformatting, so that very large files do not hang up saving or other operations, and there are some options available to control the details of formatting. See <a class="reference" href="/doc/edit/auto-reformatting">Auto-Reformatting</a> for more information.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> https://wingware.com/blog/reformattingWed, 22 Jan 2020 01:00:00 GMTNavigating Python Code with Wing Pro 7 (part 3 of 3)https://wingware.com/blog/code-navigation-3<p><a class="reference" href="/hints/code-navigation-2">Last week</a> and the <a class="reference" href="/hints/code-navigation-1">week before</a>, we looked at some of the code navigation features in Wing, including goto-definition, find uses, and project-wide search, code index menus, and the Source Browser.</p> <p>This week we'll finish up this mini-series by looking at how to quickly and easily find and open files or visit symbols in Python code by typing a name fragment.</p> <div class="section"> <h3 class="title-3">Project Configuration</h3> <p>The features described here assume that you have used <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu to add your source code to your project. Typically the project should contain the code you are actively working on. Packages that your code uses can be left out of the project, unless you anticipate often wanting to open or search files in them. Wing will still be able to find them through the Python Path, as needed for auto-completion, code warnings, and other purposes.</p> </div> <div class="section"> <h3 class="title-3">Open From Project</h3> <p><tt class="literal"><span class="pre">Open</span> <span class="pre">from</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">File</span></tt> menu is typically the easiest way to navigate to a file by name. This displays a dialog that lists the project files whose names match a fragment:</p> <img src="https://wingware.com/images/blog/code-navigation/open-from-project.png" alt="/images/blog/code-navigation/open-from-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="500px" /><p>Fragments can be abbreviations of the file name and may match enclosing directory names if they contain <tt class="literal"><span class="pre">/</span></tt> or <tt class="literal"><span class="pre">\</span></tt>. The arrow keys navigate the list and pressing <tt class="literal"><span class="pre">Enter</span></tt> opens the selected file.</p> </div> <div class="section"> <h3 class="title-3">Find Symbol</h3> <p>A similar interface is available to find Python code symbols by name. For the current file, this is <tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span></tt> in the <tt class="literal"><span class="pre">Source</span></tt> menu. For all project files, use <tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span> <span class="pre">in</span> <span class="pre">Project</span></tt> instead:</p> <img src="https://wingware.com/images/blog/code-navigation/find-symbol-in-project.png" alt="/images/blog/code-navigation/find-symbol-in-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="515px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/code-navigation-3Thu, 28 Nov 2019 01:00:00 GMTNavigating Python Code with Wing Pro 7 (part 2 of 3)https://wingware.com/blog/code-navigation-2<p><a class="reference" href="/hints/code-navigation-1">Last week</a> we looked at goto-definition, find uses, and project-wide search as tools for navigating Python code in Wing 7. This time, we'll take a look at the code indices that Wing provides.</p> <div class="section"> <h3 class="title-3">Code Index Menus</h3> <p>A quick way to navigate code in the current Python file is to use the source index menus shown at the top of the editor:</p> <img src="https://wingware.com/images/blog/code-navigation/index-menus.png" alt="/images/blog/code-navigation/index-menus.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="713px" /><p>Depending on the location of the caret in the editor, Wing may show multiple menus, as in the above example: One for the contents of the top level of the file, one for the contents of the current top-level scope, and additional menus for each sub-scope. Clicking on any of these provides an index and selecting an item jumps to that place in the source code.</p> </div> <div class="section"> <h3 class="title-3">Source Browser</h3> <p>In Wing Pro only, the <tt class="literal"><span class="pre">Source</span> <span class="pre">Browser</span></tt> in the <tt class="literal"><span class="pre">Tools</span></tt> menu provides another way to view an index of your source code, either for the current module, all project modules, or all classes:</p> <img src="https://wingware.com/images/blog/code-navigation/source-browser.png" alt="/images/blog/code-navigation/source-browser.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="357px" /><p>The scope being browsed and the types of symbols shown may be selected by clicking on the menus at the top of the tool. Double-clicking on items displays them in the editor.</p> <p>Browsing all project modules or classes assume that you have used <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu to add your source code to your project. Typically the project should contain the code you are actively working on. Packages that your code uses can be left out of the project, unless you anticipate often wanting to open or search files in them. Wing will still be able to find them through the Python Path configured by Python or in Wing's <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>.</p> <br> <br><p>That's it for now! We'll be back next week to conclude this <a class="reference" href="/hints">Wing Tips</a> mini-series on navigating Python code with Wing.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/code-navigation-2Thu, 21 Nov 2019 01:00:00 GMTNavigating Python Code with Wing Pro 7 (part 1 of 3)https://wingware.com/blog/code-navigation-1<p>Wing Python IDE includes a boatload of features aimed at making it easier to navigate and understand the structure of Python code. Some of these allow for quick navigation between the definition and uses of a symbol. Others provide a convenient index into source code. And still others quickly find and open files or navigate to symbols matching a name fragment.</p> <p>In the this and the next two <a class="reference" href="/hints">Wing Tips</a>, we'll take a look at each of these in turn.</p> <div class="section"> <h3 class="title-3">Goto Definition</h3> <p>To get from any use of a symbol in Python code to its definition, use <tt class="literal"><span class="pre">Goto</span> <span class="pre">Selected</span> <span class="pre">Symbol</span> <span class="pre">Defn</span></tt> in the <tt class="literal"><span class="pre">Source</span></tt> menu. This jumps to the <tt class="literal"><span class="pre">def</span></tt>, <tt class="literal"><span class="pre">class</span></tt>, or the point at which a variable or attribute was first defined.</p> <p>Another way to do this is to right-click on the symbol in the editor and select <tt class="literal"><span class="pre">Goto</span> <span class="pre">Definition</span></tt> or <tt class="literal"><span class="pre">Goto</span> <span class="pre">Definition</span> <span class="pre">in</span> <span class="pre">Other</span> <span class="pre">Split</span></tt>:</p> <img src="https://wingware.com/images/blog/code-navigation/goto-definition.gif" alt="/images/blog/code-navigation/goto-definition.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" width="702px" /><p>The menus also give the key bindings for the commands, or you can bind your own key to the command <tt class="literal"><span class="pre">goto-selected-symbol-defn</span></tt> with the <tt class="literal"><span class="pre">User</span> <span class="pre">Interface</span> <span class="pre">&gt;</span> <span class="pre">Keyboard</span> <span class="pre">&gt;</span> <span class="pre">Custom</span> <span class="pre">Key</span> <span class="pre">Bindings</span></tt> preference.</p> <p>In some cases, jumping to a definition successfully depends on resolving imported modules correctly using the Python Path configured by Python. In most cases you will not need to add to this configuration, but doing so is possible with <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> from Wing's <tt class="literal"><span class="pre">Project</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Navigation History</h3> <p>For this and all the other code navigation options, the <img src="https://wingware.com/images/doc/en/icons/wingide-back.png" alt="history-back" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> button at the top left of the editor may be used to return to the previous file or focus. Or move forward again in your navigation history with the <img src="https://wingware.com/images/doc/en/icons/wingide-forward.png" alt="history-forward" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> button.</p> </div> <div class="section"> <h3 class="title-3">Find Uses</h3> <p>In Wing Pro only, <tt class="literal"><span class="pre">Find</span> <span class="pre">Points</span> <span class="pre">of</span> <span class="pre">Use</span></tt> in the <tt class="literal"><span class="pre">Source</span></tt> menu or the editor's right-click context menu finds all points of use of a symbol in Python code:</p> <img src="https://wingware.com/images/blog/code-navigation/find-uses.png" alt="/images/blog/code-navigation/find-uses.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="702px" /><p>This search distinguishes between different but like-named symbols and will cover all project files and other files Wing finds on the configured Python Path. The tool's <tt class="literal"><span class="pre">Options</span></tt> menu provides control over which files are searched and what types of matches are shown.</p> </div> <div class="section"> <h3 class="title-3">Search in Files</h3> <p>To find all occurrences of other strings in Python files or in project files of any type, use the <tt class="literal"><span class="pre">Search</span> <span class="pre">in</span> <span class="pre">Files</span></tt> tool from the <tt class="literal"><span class="pre">Tools</span></tt> menu with <tt class="literal"><span class="pre">Look</span> <span class="pre">in</span></tt> set to <tt class="literal"><span class="pre">Project</span> <span class="pre">Files</span></tt> and <tt class="literal"><span class="pre">Filter</span></tt> set to the narrowest filter that includes the files that you wish to search:</p> <img src="https://wingware.com/images/blog/code-navigation/search-in-files.png" alt="/images/blog/code-navigation/search-in-files.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="699px" /><p>This tool supports text matching, wildcard, and regular expression searching and automatically updates the search results as files change.</p> <p>Searching on <tt class="literal"><span class="pre">Project</span> <span class="pre">Files</span></tt> assumes that you have used <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu to add your source code to your project. Typically the project should contain the code you are actively working on. Packages that your code uses can be left out of the project, unless you anticipate often wanting to search them with <tt class="literal"><span class="pre">Search</span> <span class="pre">in</span> <span class="pre">Files</span></tt>.</p> <br> <br><p>That's it for now! We'll be back next week to continue this <a class="reference" href="/hints">Wing Tips</a> mini-series on navigating Python code with Wing.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/code-navigation-1Thu, 14 Nov 2019 01:00:00 GMTEfficient Flask Web Development with Wing 7https://wingware.com/blog/flask<p>Wing can develop and debug Python code running under <a class="reference" href="https://palletsprojects.com/p/flask/">Flask</a>, a web framework that is quick to get started with and easy to extend as your web application grows.</p> <p>To create a new project, use <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in Wing's <tt class="literal"><span class="pre">Project</span></tt> menu and select the project type <tt class="literal"><span class="pre">Flask</span></tt>. If Flask is not installed into your default Python, you may also need to set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to the full path of the <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt> you want to use. This is the value of <tt class="literal"><span class="pre">sys.executable</span></tt> (after <tt class="literal"><span class="pre">import</span> <span class="pre">sys</span></tt>) in the desired Python installation or virtualenv.</p> <p>Next, add your files to the project with <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu.</p> <div class="section"> <h3 class="title-3">Debugging Flask in Wing</h3> <p>To debug Flask in Wing you need to turn off Flask's built-in debugger, so that Wing's debugger can take over reporting exceptions. This is done by setting the <tt class="literal"><span class="pre">debug</span></tt> attribute on the Flask application to <tt class="literal"><span class="pre">False</span></tt>:</p> <div class="python-highlight"><pre><span class="n">app</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="bp">False</span> </pre></div> <p>Then use <tt class="literal"><span class="pre">Set</span> <span class="pre">Current</span> <span class="pre">as</span> <span class="pre">Main</span> <span class="pre">Entry</span> <span class="pre">Point</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu to set your main entry point, so you can start debugging from the IDE even if the main entry point file is not visible in the editor.</p> <p>Once debug is started, you can load pages from a browser to reach breakpoints or exceptions in your code. Output from the Flask process is shown in Wing's <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool.</p> </div> <div class="section"> <h3 class="title-3">Example</h3> <p>Here's an example of a complete &quot;Hello World&quot; Flask application that can be debugged with Wing:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">os</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span> <span class="nd">@app.route</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">hello</span><span class="p">():</span> <span class="k">return</span> <span class="s">&quot;&lt;h3&gt;Hello World!&lt;/h3&gt;&lt;p&gt;Your app is working.&lt;/p&gt;&quot;</span> <span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span> <span class="k">if</span> <span class="s">&#39;WINGDB_ACTIVE&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span> <span class="n">app</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="bp">False</span> <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> </pre></div> <p>To try it, start debugging it in Wing and use the URL printed to the <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool to load the page in a web browser. Setting a breakpoint on the <tt class="literal"><span class="pre">return</span></tt> statement will stop there whenever the page is reloaded in the browser.</p> </div> <div class="section"> <h3 class="title-3">Setting up Auto-Reload with Wing Pro</h3> <p>With the above configuration, you will need to restart Flask whenever you make a change to your code, either with <tt class="literal"><span class="pre">Restart</span> <span class="pre">Debugging</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu or with the <img src="https://wingware.com/images/doc/en/icons/wingide-debug-restart.png" alt="restart" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> toolbar icon.</p> <p>If you have Wing Pro, you can avoid the need to restart Flask by telling it to auto-restart when code changes on disk, and configuring Wing to automatically debug the restarted process.</p> <p>Flask is configured by adding a keyword argument to your <tt class="literal"><span class="pre">app.run()</span></tt> line:</p> <div class="python-highlight"><pre><span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">use_reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> </pre></div> <p>Wing is configured by enabling <tt class="literal"><span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Processes</span></tt> under the <tt class="literal"><span class="pre">Debug/Execute</span></tt> tab in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>, from the <tt class="literal"><span class="pre">Project</span></tt> menu. This tells Wing Pro to debug also child processes created by Flask, including the reloader process.</p> <p>Now Flask will automatically restart on its own whenever you save an already-loaded source file to disk, and Wing will debug the restarted process. You can add additional files for Flask to watch as follows:</p> <div class="python-highlight"><pre><span class="n">watch_files</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;/path/to/file1&#39;</span><span class="p">,</span> <span class="s">&#39;/path/to/file2&#39;</span><span class="p">]</span> <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">use_reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">extra_files</span><span class="o">=</span><span class="n">watch_files</span><span class="p">)</span> </pre></div> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/blog/flaskThu, 31 Oct 2019 01:00:00 GMTUsing Matplotlib with Wing 7https://wingware.com/blog/matplotlib<p>Wing supports interactive development and debugging of Python code designed for the Matplotlib numerical and scientific plotting library, so plots can be shown and updated from the command line. For example, two plots could be shown in succession by typing the following into Wing's <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>, one line at a time:</p> <div class="python-highlight"><pre><span class="kn">from</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">import</span> <span class="n">plot</span><span class="p">,</span> <span class="n">show</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="n">show</span><span class="p">()</span> <span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span> <span class="n">plot</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> </pre></div> <p>Wing sets up the environment so that <tt class="literal"><span class="pre">show()</span></tt> runs to completion and immediately returns you to the prompt, rather than waiting until the plot is closed. In addition, Wing calls Matplotlib's main loop to keep plots windows interactive and updating while you are at the prompt. This allows plots to be added or changed without restarting a process or interrupting your work flow:</p> <img src="https://wingware.com/images/blog/matplotlib/interactive-shell.gif" alt="/images/blog/matplotlib/interactive-shell.gif" backrefs="" caption="Working interactively with Matplotlib from Wing's Python Shell" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Working interactively with Matplotlib from Wing's Python Shell</i></p><p><strong>Evaluating Files and Selections</strong></p> <p>Code from the editor can be executed in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> with the <tt class="literal"><span class="pre">Evaluate</span> <span class="pre">...</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">Shell</span></tt> items in the <tt class="literal"><span class="pre">Source</span></tt> menu and in the editor's right-click context menu. By default the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> restarts automatically before evaluating a whole file, but this can be disabled in its <tt class="literal"><span class="pre">Options</span></tt> menu.</p> <p><strong>Active Ranges</strong></p> <p>Wing also allows you to set a selected range of lines in the editor as the &quot;active range&quot; for the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> by clicking the <img src="https://wingware.com/images/doc/en/icons/wingide-active-range-set.png" alt="setactive" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon in the top right of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> tool:</p> <img src="https://wingware.com/images/blog/matplotlib/active-range.png" alt="/images/blog/matplotlib/active-range.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="570px" /><p>Wing highlights and maintains the active range as you edit it in the editor, and it can be re-evaluated easily with the <img src="https://wingware.com/images/doc/en/icons/wingide-execute.png" alt="runactive" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon that appears in the top right of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> once an active range has been set into it.</p> <p>Use the <img src="https://wingware.com/images/doc/en/icons/wingide-active-range-clear.png" alt="clearactive" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon to clear the active range from the editor and shell.</p> <p><strong>Supported Backends</strong></p> <p>Interactive development is supported for the <tt class="literal"><span class="pre">TkAgg</span></tt>, <tt class="literal"><span class="pre">GTKAgg</span></tt>, <tt class="literal"><span class="pre">GtkCairo</span></tt>, <tt class="literal"><span class="pre">WXAgg</span></tt> (for wxPython 2.5+), <tt class="literal"><span class="pre">Qt5Agg</span></tt>, <tt class="literal"><span class="pre">Qt4Agg</span></tt>, <tt class="literal"><span class="pre">MacOSX</span></tt>, and <tt class="literal"><span class="pre">WebAgg</span></tt> backends. It will not work with other backends.</p> <div class="section"> <h3 class="title-3">Debugging</h3> <p>Code can be debugged either by launching a file with <img src="https://wingware.com/images/doc/en/icons/wingide-debug-continue.png" alt="startdebug" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> in the toolbar (or <tt class="literal"><span class="pre">Start/Continue</span></tt> the <tt class="literal"><span class="pre">Debug</span></tt> menu) or by enabling debug in the integrated <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and working from there. In either case, Wing can be used to reach breakpoints or exceptions, step through code, and view the program's data. For general information on using Wing's debugger see the <a class="reference" href="/debug/quick-start">Debugger Quick Start</a>.</p> <p>When executing code that includes <tt class="literal"><span class="pre">show()</span></tt> in the debugger, Wing will block within the <tt class="literal"><span class="pre">show()</span></tt> call just as Python would if launched on the same file. This is by design, since the debugger seeks to replicate as closely as possible how Python normally runs.</p> <p>However, interactive development from a breakpoint or exception is still possible, as described below. This capability can be used to load setup code before interacting with Matplotlib, or to try out a fix when an exception has been reached.</p> <p><strong>Interactive Debugging from the Debug Console (Wing Pro only)</strong></p> <p>Whenever the debugger is stopped at a breakpoint or exception, Wing Pro's <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> provides a command prompt that may be used to inspect and interact with the paused debug process. Commands entered here run in the context of the currently selected debug stack frame:</p> <img src="https://wingware.com/images/blog/matplotlib/debug-console.png" alt="/images/blog/matplotlib/debug-console.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="673px" /><p>The tool implements the same support for interactive development provided by the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>, so plots may be shown and modified interactively whenever Wing's debugger is paused. Once the debug process is continued, Wing switches off interactive mode and returns to behaving in the same way that Python would when running the code outside of the debugger.</p> <div class="note"> Interactive development from the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> requires that you have already imported <tt class="literal"><span class="pre">matplotlib</span></tt> in the code that you are debugging or in a previous command entered in the console. Otherwise <tt class="literal"><span class="pre">show()</span></tt> may block and plots won't be updated.</div> <p><strong>Interactive Debugging from the Python Shell</strong></p> <p>Another way to combine the debugger with interactive development is to turn on both <tt class="literal"><span class="pre">Enable</span> <span class="pre">Debugging</span></tt> and <tt class="literal"><span class="pre">Enable</span> <span class="pre">Recursive</span> <span class="pre">Prompt</span></tt> in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>'s <tt class="literal"><span class="pre">Options</span></tt> menu:</p> <img src="https://wingware.com/images/blog/matplotlib/shell-options.png" alt="/images/blog/matplotlib/shell-options.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="305px" /><p>This causes Wing to add a breakpoint margin to the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and to stop in the debugger if an exception or breakpoint is reached, either in code in the editor or code that was entered into the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>.</p> <p>The option <tt class="literal"><span class="pre">Enable</span> <span class="pre">Recursive</span> <span class="pre">Prompt</span></tt> causes Wing to show a new recursive prompt in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> whenever the debugger is paused, rather than waiting for completion of the original command before showing another prompt. Showing or updating plots from recursive prompts works interactively in the same way as described earlier.</p> <p>If another exception or breakpoint is reached, Wing stops at those as well, recursively to any depth. Continuing the debug process from a recursive prompt completes the innermost invocation and returns to the previous recursive prompt, unless another exception or breakpoint is reached first.</p> </div> <div class="section"> <h3 class="title-3">Trouble-shooting</h3> <p>If <tt class="literal"><span class="pre">show()</span></tt> blocks when typed into the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>, if plots fail to update, or if you run into other event loop problems while working with Matplotlib, then the following may help solve the problem:</p> <p>(1) When working in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, evaluate the imports that set up Matplotlib first, so that Wing can initialize its event loop support before <tt class="literal"><span class="pre">show()</span></tt> is called. Evaluating a whole file at once in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> (but not the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>) will cause <tt class="literal"><span class="pre">show()</span></tt> to block if Matplotlib was not previously imported.</p> <p>(2) In case there is a problem with the specific Matplotlib backend that you are using, try the following as a way to switch to another backend before issuing any other commands:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">matplotlib</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">use</span><span class="p">(</span><span class="s">&#39;TkAgg&#39;</span><span class="p">)</span> </pre></div> <p>Instead of <tt class="literal"><span class="pre">TkAgg</span></tt> you may also try other supported backends, including <tt class="literal"><span class="pre">Qt5Agg</span></tt> (which requires that Qt5 is installed) or <tt class="literal"><span class="pre">WebAgg</span></tt> (which uses a web browser for plot display).</p> <p>As always, please email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems that you cannot resolve.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/blog/matplotlibThu, 17 Oct 2019 01:00:00 GMT