• home
  • forum
  • my
  • kt
  • download
  • Free Python IDE

    Author: 2007-08-25 14:28:22 From:

    SPE (version 0.8) requires Python 2.3+ and wxPython 2.5.4.1+. Blender, on the other hand, is only mandatory if you want to use its Blender support. Since 0.8.1.d there is a new way of quick install. This is found in the *-no_setup.zip. Just unpack that folder and run SPE.py. See this link.
    Visit SPE's website and download the program for your platform. Windows users should use the .exe binary, Linux (and BSD, MAC OSX, etc.) should download and unpack the tar.gz files and run the setup.py scripts (open a shell and type 'sudo python setup.py'). Either way, SPE will be installed in the site-packages directory where it belongs.

    This tutorial

    ... will focus primarily on the functionality of SPE's sidebar. SPE allows you, amongst many other things like syntax coloring, to create seperators which makes it very easy to keep your code structured. This results in a clear and fast way to maintain your code more easily. So I won't tell you anything about SPE's blender support, if there is anyone who wants to write a tutorial on that subject (or any other subject regarding SPE), I'd be more than happy to add it to this webpage.

    The comments

    Let's start SPE and study the screen. SPE's main window is roughly divided into four parts. The upper part is where the filemenu and toolbar resides, beneath it you will see two vertical windows, the left one is the sidebar and on the right you'll see the editor itself. On the bottom of the main window is the Python shell and clicking on one of the tabs will give you another view of you code. Some of these tabs are common to the one in the sidebar, but here you will find some extra functionality like a search function. As I said earlier, we will primarily focus on the sidebar.
    First, add some comments for your source (something you should always do) starting on the first line of the editor. Something like depicted below:


    click to enlarge the image, click again to return to this screen

    This is called the docstring. SPE shows you the docstrings of open files when you hover over the file tabs in SPE's sidebar with your mouse. It also displays statistics like number of lines, chars, classes and functions. It is very convenient that the text can be placed inside a tree hierarchy, you can expand the text using '+' and vice versa or by using the triangle. To give a line a lower hierarchy, press the <tab> key.

    Adding a separator and a TODO tag

    Adding a separator is a convenient way to structure your code, thus simpler to maintain. This is not only important for large files, you will find that it is also a great feature for smaller files (small files tend to grow bigger). You can add a separator using different methods: just type "#---some text" on an empty line in the editor, select it from the Edit menu or use the Alt+i shortcut. The newly created separator will appear in the explore tab of the sidebars. Right clicking on the reference to the separator in the explore tab will locate it in your code. This allows you to quickly find chunks of code in your source without having to scroll up and down and staring at the screen. This is, from a view of usability, something that can actually increase your productivity. One other thing that contributes to productivity is abillity to have different views in SPE, as notebooks, columns or rows. This function is accessible from the View menu. It offers you simultaneous view, that can be useful while comparing or while using one of the files as a documentation reference.

    Another handy feature is the auto creation of a todo list. Just add '# TODO:sometext' to your code and the todo tab of the sidebar will store the text following the '# TODO:' tag. A very easy way to keep track of the inevitable todo's! But of course, you can store all sorts of other information here for future references (e.g. 'this code fragment is from Harry's webtutorial'). A cool feature of the todo tag is that you can determine its priority by the amount of exclamation marks ("!"). The one with the most exclamation marks will be highlighted. As this you don't have to think any more about the order in which you insert your todo's. There is a special tab dedicated to the todo's on the sidebar, here you can see the priorities of your todo's.

    In the picture below you can see that I also added a function definition, this will also appear as you type in the sidebar. The reference for this function in the sidebar uses a blue font and you can use it to jump to the location in your source code. SPE's author was smart enough to add an icon also, human beings are visually orientated and icons work very well in this regard.


    click to enlarge the image, click again to return to this screen

    Browsing a class

    The next thing we'll do is to add a class to our program, but first let's create another separator named "classes". By doing so, it will be easier to identify the location of your classes.
    Beneath this separator we will create a class named SpeTut, this class contains two methods, __init__ (aka the constructor) and the method hello. As you can see in the picture below, the class browser SpeTut will be visible in the explore tab, including the aforementioned methods. Use the little triangle on the leftside to expand the tree and vice versa. The reference to the class in the explore tab has a red font and a unique icon (click on it to expand the tree!).
    You can also add a separator inside a class, a nice feature for larger classes with many methods.



    click to enlarge the image, click again to return to this screen

    Now take a look at the last line of code in the screenshot above. See the red line? That is the standard python compiler checking your code while you type your code! The auto completion of code suggests self.spe and of course, that's what you want. Now press your tab key and the code is completed, and approved by the Python compiler. I told you SPE is powerful, didn't I?
    Whenever you import a module like 'os', SPE will assist you finding the appropriate methods as depicted below. By the way, all imports will appear in the sidebar with the paperclip.


    click to enlarge the image, click again to return to this screen

    Run that Py!

    Now it's time to run our little program, so add:
    • displayConstant() [this runs the function definition]
    • doSum() [this runs the function definition]
    • say = SpeTut('Stani') [this creates an instance with an argument]
    • say.hello() [this runs the method from the class]
    to the source code.
    Use Ctrl-R (or Cmd-R on a MAC) or use the icon on the toolbar and the code will be executed. You can see the output in the Python shell in the lower area of SPE's main window. It's a good practice to do this often as you're building your code. Another nice feature of the sidebar is the source code checker (PyChecker). You can use it by clicking on the appropriate tab located in the sidebar.


    click to enlarge the image, click again to return to this screen

    Now, let's look how SPE behaves when there is an error in your script. Ad a new constant like, 'd = oops' and run the script again. Watch the output at the bottom of the screen, where you will see the following message:


    click to enlarge the image, click again to return to this screen

    This is the Python traceback to your error (NameError in this case) and as you can see, the second line is a hyperlink that jumps to the error in your script.
    Another nifty feature is that you can run a selected part of your code. For instance, select:


    click to enlarge the image, click again to return to this screen

    In your source code and do Edit > Execute in Shell to execute the selected code in the shell. A nice way to test snippets of your code.
    SPE also includes PyChecker which will give more elaborated error report on multiple lines. Invoke it by using the toolbar or Ctrl+Alt+C (or Cmd+Alt+C) on a MAC).

    Life is full of colors

    Adding colors to the separator makes it even easier to keep track of your code (as long as you don't turn it into a Christmas tree...). There are two ways to add colors to the separator, a convenient way is to use filemenu --> edit, another way is to type the colorcode (Hex, e.g. #7F7F7F). Use whatever suits you best.


    click to enlarge the image, click again to return to this screen

    Sticky notes

    Another feature I will mention in this tutorial is the ability to create sticky notes. Just click on the notes tab located in the sidebar and type some notes about your program. Making notes about your program is more important then you might think, an idea you have today may be forgotten the next day (or the next hour), it's just a small effort to make notes (real notes, not mental notes...) and SPE makes this very easy for you. The notes will be saved as an external '.txt' file and has the same name as your file. Another simple but effective way to keep track of your coding. Once you make this empty, the external file will also disappear.

    The file browser

    Working on a project often means that you have a lot of files that you have keep track of. A feature of SPE makes it quite easy to do this. Just click on the browser tab and the files of your current directory will be displayed, right-click on a file and it is opened in SPE and you can edit the file. This works for Python files, but you can also edit html files.


    click to enlarge the image, click again to return to this screen

    The end

    Here is where my little tutorial ends (this version anyway) and I just barely scratched the surface of SPE's functionality. If you are looking for a free Python IDE, you owe it to yourself to try SPE and I think you won't be disappointed. Oh, did I tell you that SPE includes wxGlade and the debugger WinPdb? You can find a tutorial on wxGlade here.

    Also, check out this SPE video on showmedo.com, a visual introduction to SPE.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Development (6)
      Introduction to Python (5)
      Miscellaneous (4)
      Searching (2)
      Web Fetching (5)
      XML and Python (0)

    New

    Hot