Sunday, October 31, 2010

Where on earth is pythonxx.dll? (2)

The problem with the way PyScripter searches for the python dll is that, when used without any command-line arguments, it will try to load some loose python dll found on the system path that was placed there by an installed application, even if this dll is not related to a properly installed python version.  (See step 3 in the previous post).  This typically will result in unpredictable errors after starting PyScripter, since python will not be able to find the module libraries.

As an example, this might happen when you have installed python version 2.5 but, somehow a loose python26.dll can be found on the system path.

I am thinking of dropping step 3 in the algorithm described in the previous post and only try to load registered python versions when PyScripter is invoked without any command-line parameters or with just the –PYTHONxx flag.  This means that if you want to use PyScripter with an unregistered version of Python you would have to use both the –PYTHONxx and the –PYTHONDLLPATH parameters.  Any thoughts?

Where on earth is pythonxx.dll?

Most python users have multiple python versions installed.  In addition various other software packages install custom versions of python often placing pythonxx.dll on the windows system path as defined by the environment variable %PATH%.  It is worth explaining how PyScripter locates the python dll, since the issue pops up regularly in the newsgroup and submitted bug reports.

There are two types of Python installation:

  1. All users installation
    Python creates registry entries with installation info at HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.x and puts places the python dll in c:\Windows\System32.
  2. Single user installation
    Python creates registry entries with installation info at HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\2.x and does not put the dll in c:\Windows\System32.

PyScripter, without any command line flags looks at the registry to find the latest version of Python and then for an all user installation tries to load the relevant Python dll from the system path. For a single user installation tries to load the DLL from the Install path that is in the registry.

In more detail PyScripter does the following:

Currently PyScripter knows of versions 3.2, 3.1, 3.0, 2.7...2.3. Below, system path refers to the Windows path (environment variable) and x.x refers to the version number.

Repeat for versions 3.2 down to 2.3:

  1. Look at the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\x.x (All users).  If key is found assume the dll is in the system path and try to load it.
  2. If the previous key does not exist it look at  HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\x.x (Single user) and try to load the Python DLL from the path specified in the registry.
  3. If there is no info in the registry try to load the DLL from the system path to cater for unregistered Python versions.
  4. If Python DLL was loaded successfully then break

When PyScripter is used with a --PYTHONxx flag then it does the above but searching only for the specific version. The Registry lookup does not take place when Python is used with the --PYTHONDLLPATH. Instead PyScripter tries to load the Python dll from the specified path.  The --PYTHONDLLPATH flag should be used with the --PYTHONxx flag. See http://pyscripter.googlepages.com/portablepython for an example of using PyScripter with portable Python. 

The %PYTHONHOME% environment variable is not used by PyScripter directly but by Python to find the installed libraries. See the Python documentation for its use.

Sunday, October 24, 2010

PyScripter v2.3.3 released

PyScripter version 2.3.3 was released at http://pyscripter.googlecode.com. This update fixes a regression introduced in version 2.3.2, that manifests itself when using the Run, Command Line Parameters command.

Saturday, October 23, 2010

PyScripter v2.3.2 released

PyScripter version 2.3.2 was released at http://pyscripter.googlecode.com.  This update to version 2.3.1 fixes two critical bugs:
  • Issue 432
  • A bug that could cause exceptions in the code explorer.   The fix also makes the editor more responsive when working with large files.
The update is recommended for all users of PyScripter.
The full history can be found at http://code.google.com/p/pyscripter/wiki/History.

Saturday, October 16, 2010

Tip: Zooming in and out

The View menu has the Zoom In/Out commands that allow you to increase/decrease the font size.  You can do the same pressing the Control key and moving the mouse wheel.

More on Layouts: Maximize the editor

You might have noticed the Maximize/Restore Editor commands in the View Layouts menu.  What you may not know is that you achieve the same by double-clicking on the editor tab-bar (on empty space – if you can find some!-, not on the tabs).

Add watch at cursor

A quick way to add a watch for a Python variable is to click on it and press Alt+W.  This is the shortcut of the “Add watch at cursor” command which is hidden at the context menu of the Watches Window.  In the future I will add drag-and-drop support for the Watches window so you can drop whole expressions on it.  (Can someone bother to create an issue about this at PyScripter Issue tracker to act as a reminder?)

Layout tips

If you have used PyScripter for some time you may well know that you save different layouts (IDE window arrangements) from the View, Layouts menu or the Layout toolbar button in the View Toolbar and then easily switch between them.  What you may not know that if you call a layout “Debug” then it is used in a special way.  Every time you start a debugging session, PyScripter automatically switches to the Debug layout.  At the end of the debugging session the  layout that was used before debugging started is restored.

Here is a sample debugging layout

image

Python engine initialization

Starting from the just released version 2.3.1, PyScripter users can create two startup python files that can be run at PyScripter startup.

1.   pyscripter_init.py
This script is run once in the space of the internal Python engine at start-up.  It can be used to set various PyScripter options and to customize the PyScripter user environment.

2.   python_init.py
            This file is executed when a Python engine, internal or remote, is initialized and every time the engine is reinitialized.  It can be used to customize the Python engine, for example by always importing certain units or modifying sys.path.
 
You can edit the startup files by using the new Tools menu command "Edit Startup Files".
 
PyScripter searches for startup python files first at the PyScripter.exe directory, and, if it they are not found there, at %APPDATA%\Pyscripter, where %APPDATA% is the environment variable.  The PyScripter installation program places these files without any content at %APPDATA%\Pyscripter, if the files are not there already.

TIP:  This not documented but internally PyScripter uses the following
method to prevent debugging certain modules:


__import__('module name').__traceable__ = 0

You can include such statements in python_init.py to prevent stepping into certain units.


 

Thursday, October 14, 2010

Changing those damn locals

A “feature” of Python is that the locals dictionary of a Python frame is read-only.  What this means is that if you change a local variable during debugging ,its new value will be ignored when you resume the program.  Consider for example this trivial script:

def f(a):
    b = 2*a
    print(b)  # break here

f(2)

With PyScripter 2.1.1 if you break at the print statement and issue the commands in the interpreter:

[Dbg]>>> b = 10
[Dbg]>>> b
4
[Dbg]>>>

you can see that no matter how hard you try you cannot change the value of the local variable b.  This is not just a PyScripter issue.  See for example the feature request submitted by the author of pydev at http://bugs.python.org/issue1654367.

Well, I found a way to remove this restriction and if you try the same in PyScripter 2.3 you get:

[Dbg]>>> b = 10
[Dbg]>>> b
10
[Dbg]>>>

as you would be right to expect.  The workaround requires ctypes which is included with Python 2.5 or later.

Tuesday, October 12, 2010

Revamped Code Explorer

One of the areas that received significant attention is the Code Explorer.   First of all, functions are now displayed with their arguments.  If you look at the context menu of the Code Explorer background you will see the following options:

image

Here is the explanation of the new options:

Alpha Sort
If checked, tree nodes are sorted alphabetically, otherwise the node order follows the position of the identifiers in the code.

Follow Editor
If checked, as you move the cursor in the editor the class, method or function that contains the cursor gets selected in the Code Explorer.

Show Selection
If checked, when you select a node by mouse or keyboard, the position of the identifier in the code is shown without moving the focus to the editor.  This option is very useful for browsing code.
 
If you right-click on a node a different context menu is displayed:
 
image
 
The Find Definition works the same as double-clicking on an identifier.  Focus is moved to the editor at the position of the identifier.  An improvement is that now the identifier is selected.  The Find References commands work like the equivalent command on the Search menu, but on the selected identifier.  The Highlight command, highlights all occurrences of the identifier in the editor, like the Highlight Search Text command.
 
Another important improvement is that Code Explorer saves and restores the state of the tree as you switch files.
 
Hope you like these improvements.
 

Highlight selected word

An alpha version of PyScripter 2.3 is out at the PyScripter project page.  This version contains a number of new features, about some of which I will blog here.  One new feature is the “Highlight selected word” option which is on by default.  With this option on, if you select a word by double-clicking or by the relevant editor command, other instances of the word are highlighted.  Here is what it looks like:

image

As soon as you start typing the highlight goes off (as with the Highlight search text command).  You can also hide the highlight by depressing the Highlight search text button in the Find toolbar or using the command shortcut Shift+Ctrl+H.

Monday, October 11, 2010

Code completion delight

A number of improvements to code completion have been implemented and will available with the next release of PyScripter:

  • Caching of parsed modules for greater speed
  • Background parsing of open editor files
  • Analysis of return, with and global statements
  • Completion for calls to open

Just to give a couple of examples:

In

class A():
    def a(self):
        return "abc"

def g():
    x = A()
    return x.a()

def f():
    return g()

a = f()

a.

PyScripter understands a is a string and provides autocompletion.  It also provides autocompletion in the following examples

f = open(“somefile”)

f.

and

with open(“somefile”) as f:

    f.

PyScripter in the dark (2)

In version control a new IDE option has been added “Use Python colors in IDE”.  If checked the colors of the python highlighter (Background color from the space attribute and foreground color of the identifier attribute) are used in the IDE windows. When a dark highlighter is used this option helps achieve a uniform "dark" look. Here is how PyScripter looks with this option checked.
image

Sunday, October 10, 2010

PyScripter in the dark

There was a user question at comp.lang.python about how to setup PyScripter in dark colours.
In PyScripter try View, Themes, EOS
Further dark theme is available at http://www.mytreedb.com/downloads/m-subcat/a-skins.html(you need to download the archive and place the skin file at %APPDATA%/pyscripter/skins)

You can find dark highlighters at http://code.google.com/p/pyscripter/wiki/Customization
(download and import into PyScripter via View, Options, Import/Export)


Finally you can create your own skin using the skin editor at
http://www.silverpointdevelopment.com/skineditor/index.htm

Here is a sample of what you can get:
screenshot9

Welcome to the PyScripter Blog

This blog was set up to provide information about the Python IDE PyScripter.  I will occasionally blog here about development progress, new features, future plans and usage tips.