Wing Tipshttps://wingware.com/Tips, tricks, and helpful hints for Wingware's Python IDEsTue, 07 Jul 2020 04:59:19 GMTPyRSS2Gen-1.0.0http://www.dalkescientific.com/Python/PyRSS2Gen.htmlExtend Microsoft Excel with Python Using Wing and PyXLLhttps://wingware.com/blog/pyxll<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use Wing and <a class="reference" href="https://www.pyxll.com">PyXLL</a> to develop and debug Microsoft Excel add-ins that are written in Python. PyXLL is a commercial product that embeds Python into Microsoft Excel on Windows. It allows you to expose Python code to Excel as worksheet functions, macros, menus, and ribbon toolbars.</p> <div class="section"> <h3 class="title-3">Install PyXLL</h3> <p>Before getting started you will need to install Microsoft Excel, <a class="reference" href="https://python.org/">Python</a> or <a class="reference" href="https://www.anaconda.com">Anaconda</a>, <a class="reference" href="https://wingware.com/">Wing</a>, and <a class="reference" href="https://www.pyxll.com/download.html">PyXLL</a> if you don't already have them.</p> <p><strong>Important:</strong> Excel, PyXLL and Python all need to be either 32 bit or 64 bit and can't be mixed. To find out what version of Excel you have see <a class="reference" href="https://support.pyxll.com/hc/en-gb/articles/360036821613-Do-I-have-32-bit-or-64-bit-Excel-">Do I have 32 bit or 64 bit Excel?</a> You will also need to match the version of PyXLL that you download to your Python version.</p> <p>To install PyXLL, unzip the download and then edit the included <tt class="literal"><span class="pre">pyxll.cfg</span></tt> and set <tt class="literal"><span class="pre">executable</span></tt> to the full path of your Python executable. This can be a <tt class="literal"><span class="pre">python.exe</span></tt> from a virtualenv or conda env, or a base Python install. For example:</p> <pre class="literal-block"> [PYTHON] executable = C:\Users\joebloggs\Anaconda\envs\py38\python.exe </pre> <p>Next, install the PyXLL add-in into Excel. To do that, open Excel and select the <tt class="literal"><span class="pre">File</span></tt> menu. Navigate to <tt class="literal"><span class="pre">Options</span></tt>, then <tt class="literal"><span class="pre">Add-Ins</span></tt>, and click the <tt class="literal"><span class="pre">Manage</span> <span class="pre">Excel</span> <span class="pre">Add-Ins</span></tt> button. Select <tt class="literal"><span class="pre">Browse</span></tt>, navigate to the folder where you unzipped the PyXLL download, and select the <tt class="literal"><span class="pre">pyxll.xll</span></tt> file. If Excel asks if you want to copy the add-in to your add-ins folder, select <tt class="literal"><span class="pre">No</span></tt> as you want to leave it where it is. The PyXLL add-in should now appear in your list of loaded add-ins.</p> <p>If you're having trouble installing the add-in, check the PyXLL log file located in the <tt class="literal"><span class="pre">logs</span></tt> folder where you unzipped PyXLL. You can change the log level to <tt class="literal"><span class="pre">debug</span></tt> in your <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file to obtain more detailed logging. If you get stuck contact the <a class="reference" href="https://www.pyxll.com/contact.html">PyXLL support team</a> who will help you get started.</p> <p>You can also find more detailed installation instructions in <a class="reference" href="https://www.pyxll.com/docs/userguide/installation.html">Installing the PyXLL Excel Add-In</a>.</p> </div> <div class="section"> <h3 class="title-3">Create a Wing Project</h3> <p>Next create a new project in Wing with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. Select <tt class="literal"><span class="pre">Empty</span> <span class="pre">Python</span> <span class="pre">Project</span></tt> as the project type and set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the same Python used as the <tt class="literal"><span class="pre">executable</span></tt> in <tt class="literal"><span class="pre">pyxll.cfg</span></tt> above:</p> <img src="https://wingware.com/images/blog/pyxll/new-project.png" alt="/images/blog/pyxll/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="650px" /><p>Then select <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> from Wing's <tt class="literal"><span class="pre">Project</span></tt> menu and add the directory where you installed PyXLL.</p> <p>Finally, save your Wing project to disk with <tt class="literal"><span class="pre">Save</span> <span class="pre">Project</span> <span class="pre">As</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Write an Excel Function With PyXLL</h3> <p>Before we look at setting up Wing's debugger, let's write an Excel function to debug. This example uses pandas and numpy, so you will need to make sure those are installed into the Python you configured above. If you are using Anaconda, then you should already have them. In other cases, this can be done with pip. For example:</p> <pre class="literal-block"> C:\Users\joebloggs\Anaconda\envs\py38\python.exe -m pip install pandas numpy </pre> <p>Now create a Python module for your Excel function by creating a new directory on disk and placing a Python file into that directory, with the following contents:</p> <div class="python-highlight"><pre><span class="kn">from</span> <span class="nn">pyxll</span> <span class="kn">import</span> <span class="n">xl_func</span> <span class="kn">import</span> <span class="nn">pandas</span> <span class="kn">as</span> <span class="nn">pd</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span> <span class="nd">@xl_func</span><span class="p">(</span><span class="s">&quot;int, int: dataframe&lt;index=True&gt;&quot;</span><span class="p">,</span> <span class="n">auto_resize</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="k">def</span> <span class="nf">random_dataframe</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="p">):</span> <span class="sd">&quot;&quot;&quot;</span> <span class="sd"> Creates a DataFrame of random numbers.</span> <span class="sd"> :param rows: Number of rows to create the DataFrame with.</span> <span class="sd"> :param columns: Number of columns to create the DataFrame with.</span> <span class="sd"> &quot;&quot;&quot;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="p">)</span> <span class="n">column_names</span> <span class="o">=</span> <span class="p">[</span><span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="s">&#39;A&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">columns</span><span class="p">)]</span> <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">column_names</span><span class="p">)</span> <span class="k">return</span> <span class="n">df</span> </pre></div> <p>The directory and filenames can be anything, but in this example we'll use <tt class="literal"><span class="pre">C:\Users\joebloggs\Projects\PyXLL\src</span></tt> for the directory and <tt class="literal"><span class="pre">xlfuncs.py</span></tt> as the file name.</p> <p>Next update the <tt class="literal"><span class="pre">pythonpath</span></tt> and <tt class="literal"><span class="pre">modules</span></tt> setting in the same <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file where you set <tt class="literal"><span class="pre">executable</span></tt> earlier:</p> <pre class="literal-block"> [PYTHON] pythonpath = C:\Users\joebloggs\Projects\PyXLL\src [PYXLL] modules = xlfuncs </pre> <p>Note that the entry under modules omits the <tt class="literal"><span class="pre">.py</span></tt> in the filename.</p> <p>Once this is done, reload the PyXLL add-in via the PyXLL ribbon tool bar or the add-ins menu in Excel, or restart Excel. PyXLL can also be configured to auto-reload after any change made to the Python code. See <a class="reference" href="https://www.pyxll.com/docs/userguide/reloading.html">Reloading</a> in the PyXLL guide for details.</p> <div class="section"> <h4 class="title-4">How it Works</h4> <p>As you may already have figured out, the example Excel function <tt class="literal"><span class="pre">random_dataframe</span></tt> given above creates a pandas <tt class="literal"><span class="pre">DataFrame</span></tt> containing random data, and returns that to Excel as an array function.</p> <p>The <tt class="literal"><span class="pre">&#64;xl_func</span></tt> decorator tells PyXLL to use it as an Excel worksheet function. The first argument to the decorator is an optional function signature. PyXLL uses this to determine how arguments and return values should be converted between the Excel and Python data types. The example here uses the <tt class="literal"><span class="pre">dataframe</span></tt> return type to tell PyXLL to expand the pandas <tt class="literal"><span class="pre">DataFrame</span></tt> to an array of values when returning to Excel, including the index. The <tt class="literal"><span class="pre">auto_resize</span></tt> option tells PyXLL that the Excel formula should be resized automatically to fit the size of the returned array.</p> <div class="note"> <strong>Tip:</strong> In order for Wing to recognise the <tt class="literal"><span class="pre">&#64;xl_func</span></tt> decorator as a valid defined symbol, you will need to install the <tt class="literal"><span class="pre">.whl</span></tt> file included in the PyXLL download using <tt class="literal"><span class="pre">pip</span> <span class="pre">install</span></tt> followed by the full path of the <tt class="literal"><span class="pre">.whl</span></tt> file. You can also invoke pip with the <tt class="literal"><span class="pre">-m</span></tt> command line argument for Python, as shown above for installation of pandas and numpy.</div> </div> </div> <div class="section"> <h3 class="title-3">Invoke the PyXLL Function</h3> <p>Now you should be able to call the <tt class="literal"><span class="pre">random_dataframe</span></tt> function from Excel by entering it as a formula in an Excel worksheet. This is done in the same way as Excel's standard functions by using <tt class="literal"><span class="pre">=</span></tt> followed by the function name, for example <tt class="literal"><span class="pre">=random_dataframe(10,</span> <span class="pre">10)</span></tt>:</p> <img src="https://wingware.com/images/blog/pyxll/random-dataframe.gif" alt="Enter random DataFrame into Excel" backrefs="" caption="Shown Above: Type &quot;=random_dataframe(10,10)&quot; and press Enter to insert a random DataFrame into Excel" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Type "=random_dataframe(10,10)" and press Enter to insert a random DataFrame into Excel</i></p><p>For complete instructions on writing Excel worksheet functions in Python with PyXLL, please see <a class="reference" href="https://www.pyxll.com/docs/userguide/udfs/introduction.html">Worksheet Functions</a> in the PyXLL user guide.</p> </div> <div class="section"> <h3 class="title-3">Set up Wing's Debugger</h3> <p>To enable debugging, you need to tell Wing to accept connections from Python code running under Excel and then configure and load the debugger into Excel. To do this from the project you created earlier, click on the bug icon in the lower left of Wing's window, and check <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/pyxll/accept-debug-connections.jpg" alt="Accept Debug Connections" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Now hovering your mouse over the bug icon should show that Wing is listening for externally initiated debug connections on the local host:</p> <img src="https://wingware.com/images/blog/pyxll/listening-for-connections.jpg" alt="Listening for Connections" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>If Wing is not listening, it may be that it has not been allowed to do so by Windows. In that case, try restarting Wing so that Windows will prompt you to allow network connections.</p> <p>Next, find the <tt class="literal"><span class="pre">Install</span> <span class="pre">Directory</span></tt> listed in the <tt class="literal"><span class="pre">About</span></tt> box accessed from the <tt class="literal"><span class="pre">Help</span></tt> menu in Wing. Copy <tt class="literal"><span class="pre">wingdbstub.py</span></tt> from that directory to the directory that contains <tt class="literal"><span class="pre">xlfuncs.py</span></tt>.</p> <p>Then open your copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> and make the following changes:</p> <blockquote> <div class="ordered-list"><ul><li><span class="bullet"> Make sure <tt class="literal"><span class="pre">WINGHOME</span></tt> is set to the full path of your Wing installation, where you just found <tt class="literal"><span class="pre">wingdbstub.py</span></tt>. This is usually set automatically during installation of the IDE.</span></li> <li><span class="bullet"> Change the value of <tt class="literal"><span class="pre">kEmbedded</span></tt> to <tt class="literal"><span class="pre">1</span></tt>. This alters some aspects of how code is debugged, to match the environment your Python code will be running in.</span></li> </ul></div></blockquote> <p>To get Excel to load Wing's debugger, add <tt class="literal"><span class="pre">wingdbstub</span></tt> to the modules list in your <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file:</p> <pre class="literal-block"> [PYXLL] modules = wingdbstub xlfuncs </pre> <p>Finally, restart Excel or reload the PyXLL add-in. When the <tt class="literal"><span class="pre">wingdbstub</span></tt> module is loaded it will connect to Wing and the bug icon in the lower left of Wing's window will turn green, in order to let you know that the debugger is connected:</p> <img src="https://wingware.com/images/blog/pyxll/connected-to-excel.jpg" alt="Connected to Excel" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Debugging Python Code Invoked from Excel</h3> <p>You can now step through the Python code running in Excel.</p> <p>To try it out, set a breakpoint in <tt class="literal"><span class="pre">xlfuncs.py</span></tt> by opening it in Wing and clicking on the leftmost margin next to the the line that reads <tt class="literal"><span class="pre">data</span> <span class="pre">=</span> <span class="pre">np.random.rand(rows,</span> <span class="pre">columns)</span></tt> within <tt class="literal"><span class="pre">random_dataframe</span></tt>. When you call the function from Excel, the debugger will stop on the breakpoint:</p> <img src="https://wingware.com/images/blog/pyxll/debugging-excel.gif" alt="Debugging Excel" backrefs="" caption="Shown Above: Enter &quot;random_dataframe(10,10)&quot; into Excel on the left, reach a breakpoint in Wing on the right, and step through code" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Enter "random_dataframe(10,10)" into Excel on the left, reach a breakpoint in Wing on the right, and step through code</i></p><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> (Wing Pro only) or <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> in Wing's <tt class="literal"><span class="pre">Tools</span></tt> menu, set other breakpoints or conditional breakpoints (Wing Pro only), step through code, and so forth. For more information on the capabilities of Wing's debugger, see the <a class="reference" href="/doc/howtos/quickstart">Debugger Quick Start</a> or the <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu.</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, have any questions, or have topic suggestions for future Wing Tips!</p> </div> https://wingware.com/blog/pyxllWed, 24 Jun 2020 01:00:00 GMTConfiguring Wing Pro's Python Debugger for Your Code Basehttps://wingware.com/blog/debug-overview<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> provides a roadmap to the configuration options available for Wing's debugger, to make it easier to understand the available possibilities and how these can be applied to your development projects.</p> <div class="section"> <h3 class="title-3">Configuration Options</h3> <p>Broadly speaking there are five ways to configure Wing's debugger, depending on whether your code runs locally or on a remote system, and whether it is launched from the IDE or from the outside:</p> <p><strong>Local Stand-Alone Code</strong> -- Wing can debug stand-alone scripts and applications that run on your local machine and that are launched on demand from within Wing. This development approach can be used for anything that is convenient to launch from the IDE, including scripts, desktop apps, and most web frameworks. See the <a class="reference" href="/doc/debug/quick-start">Debugger Quick-Start</a> for a quick introduction to this simple case.</p> <p><strong>Remote Stand-Alone Code</strong> -- Wing Pro can also debug stand-alone code running on a remote host, virtual machine or device, in the same way as it debugs locally running code. Wing uses a remote agent launched by SSH in order to work directly with files stored on the remote host, as if Wing were itself running on that system. For details, see <a class="reference" href="/hints/remote-dev-2">Remote Development with Wing Pro</a>.</p> <p><strong>Local Externally Launched or Embedded Code</strong> -- Wing can debug locally running code that is launched by a web server or framework, embedded Python code that is used to script a larger application, and any other Python code that cannot be directly launched from the IDE. In this case, the code is started from outside of Wing and connects to the IDE by importing Wing's debugger. Debug can be controlled from the IDE and through an API accessible from the debug process. For details, see <a class="reference" href="/doc/debug/debugging-externally-launched-code">Debugging Externally Launched Code</a></p> <p><strong>Remote Externally Launched or Embedded Code</strong> -- Wing Pro can also debug externally launched or embedded code that is running on a remote system. In this case, Wing uses a remote agent to access the remote host via SSH and the debugged code imports Wing's debugger in order to connect back to the IDE through an automatically established reverse SSH tunnel. See <a class="reference" href="/doc/debug/remote-debugging">Debugging Externally Launched Remote Code</a> for brief instructions or <a class="reference" href="/doc/howtos/debugging-web-remote">Remote Web Development</a> for a more detailed guide.</p> <p><strong>Manually Configured Remote Debugging</strong> -- For remote hosts and devices that are not accessible through SSH, or where Wing's remote agent cannot be run, Wing provides a manual configuration option to make debugging on these systems possible. In this case, the device must be able to connect to the host where Wing is running via TCP/IP, and there must be some file sharing configuration so files are available both locally and on the remote system. In this approach, connectivity, file sharing, and other configuration needed to make debugging possible is accomplished entirely manually, so it can be tailored to unusual custom environments. For details, see <a class="reference" href="/doc/debug/manual-remote-debugging">Manually Configured Remote Debugging</a>.</p> <div class="section"> <h4 class="title-4">Coming Soon in Wing 8</h4> <p>Although not yet available, it's worth mentioning another type of debug configuration that is coming soon:</p> <p><strong>Containerized Code</strong> -- Wing Pro 8 will be able to debug code running in containers like those provided by Docker, without requiring access to the container through SSH and without labor-intensive manual remote debug configuration. In this model, the IDE works with the local files that are used to build the container, and launches code for unit tests and debug in the container environment. This capability should be available fairly soon through our <a class="reference" href="/wingide/early">early access program</a>.</p> </div> </div> <div class="section"> <h3 class="title-3">VirtualEnv and Anaconda Environments</h3> <p>In the context of each of the above, Wing may be used with or without an environment created by <tt class="literal"><span class="pre">virtualenv</span></tt> or Anaconda's <tt class="literal"><span class="pre">conda</span> <span class="pre">create</span></tt>. For local debugging, this is selected by 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>. For remote debugging, it is set in the remote host configuration.</p> <p>For <tt class="literal"><span class="pre">virtualenv</span></tt>, you can either set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the full path to the virtualenv's Python, or you can select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and enter the command that activates the virtual environment.</p> <p>For Anaconda environments, you must select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and then choose the environment from the drop down list to the right of this field.</p> <p>For more information on this, please see <a class="reference" href="/doc/howtos/virtualenv">Using Wing with virtualenv</a> and <a class="reference" href="/doc/howtos/anaconda">Using Wing with Anaconda</a>.</p> </div> <div class="section"> <h3 class="title-3">Specific Frameworks and Tools</h3> <p>Some frameworks and tools require some additional custom configuration to make them easy to work with in Wing. In addition to understanding the general options explained above, it is a good idea to seek out configuration details for the frameworks and tools that you use:</p> <div class="bullet-list"><ul><li><span class="bullet"> Wing's documentation contains configuration instructions for specific frameworks and tools such as <a class="reference" href="/doc/howtos/flask">Flask</a>, <a class="reference" href="/doc/howtos/django">Django</a>, <a class="reference" href="/doc/howtos/jupyter">Jupyter</a>, <a class="reference" href="/doc/howtos/wxpython">wxPython</a>, <a class="reference" href="/doc/howtos/pyqt">PyQt</a>, <a class="reference" href="/doc/howtos/blender">Blender</a>, <a class="reference" href="/doc/howtos/maya">Maya</a>, and <a class="reference" href="/doc/howtos">others</a>.</span></li> <li><span class="bullet"> There is also additional information available for specific kinds of remote development for <a class="reference" href="/doc/howtos/aws">AWS</a>, <a class="reference" href="/doc/howtos/docker">Docker</a>, <a class="reference" href="/doc/howtos/vagrant">Vagrant</a>, <a class="reference" href="/doc/howtos/wsl">Windows Subsystem for Linux</a>, <a class="reference" href="/doc/howtos/raspberry">Raspberry Pi</a>, and <a class="reference" href="/doc/howtos">others</a>.</span></li> </ul></div><p>The <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog accessed from the <tt class="literal"><span class="pre">Project</span></tt> menu provides some assistance for setting up new Wing projects for most of these.</p> </div> <div class="section"> <h3 class="title-3">Multi-threaded and Multi-process Debugging</h3> <p>Wing automatically debugs any multi-threaded code without any additional configuration.</p> <p>Multi-process code can also be debugged but requires turning on the <tt class="literal"><span class="pre">Debug/Execute</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Processes</span></tt> option in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> before child processes are automatically debugged. In this case, you may also want to configure specific options for how Wing handles and terminates child processes. See <a class="reference" href="/doc/debug/multiprocess">Multi-Process Debugging</a> for details.</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/debug-overviewThu, 04 Jun 2020 01:00:00 GMTConditional 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 GMT