In 2006, I created Flowchart Python, a Python-based language that uses a flowchart for high-level language structure. I released it on pygame.org. A workmate was recently searching for something related to Python and flowcharts, and stumbled across my project. After trying to show him the project in action, I decided it was time to upload a cleaner version of Flowchart Python to the Internet.
What is Flowchart Python NOT?
Flowchart Python is not:
- a tool for editing
.pyfiles as flowcharts;
- a tool for viewing
.pyfiles as flowcharts; or
- a tool for generating
.pyfiles from flowcharts.
Perhaps Flowchart Python would be more useful if it were one of those things, and in the future I may add tools which do such things, but those were not my design goals when I wrote the software.
What is Flowchart Python?
Flowchart Python lets you design and edit flowcharts. At the lowest level (variable assignment, function calls, etc.) you enter Python code. When you run a flowchart, the flowchart will be compiled to a
.pyc file and run. This means that flowcharts can import normal Python modules and normal Python modules can import (compiled) flowcharts. But there is currently no mechanism for converting a Python source file to a flowchart or vice versa.
What Have I Changed in Version 1.1?
I have just uploaded version 1.1 of Flowchart Python. Despite all temptations I have been careful not to make any large changes in this upload. All that I have done is:
- update Flowchart Python to work with the latest Python 2 library code;
- used Python’s
tracebackmodule to display tracebacks rather than a home-rolled version;
- fixed a spurious traceback;
- fixed issues revealed by pyflakes (e.g. useless imports and assignments);
- changed the code to use Unix line endings;
- removed trailing whitespace from source code;
- called pygame.display.quit() before pygame.quit() to give the illusion of snappiness on exit.
The upshot is that Flowchart Python is now cross-platform and tested on Python 2.7.
How Do I Use It?
Flowchart Python was designed to be used by programmers. This meant that my priority in writing the software was to give hotkeys for everything useful rather than making obvious buttons in the UI. Below are a few pointers on use. In my notes below I haven’t specified the hotkeys for everything but in general if you can find a feature in the menu, the hotkey will be listed beside the command name.
- space zooms the view to the selected block
- ctrl+mouse drag pans and zooms
- alt+mouse drag pans only
- S, F, E, D to move selection left, right, up, down
- R to move selection to child of current block
- W to move selection to parent of current block
To insert control structures, you first add an empty block, then use the ‘Substitute’ menu option (or hotkey) to set up the desired kind of block.
There are two ways to add blocks. You can use the insert command (either from the menu or use the hotkey). Alternatively, if you move the mouse over the border of a given block, it will highlight the edge under the mouse in pink. This means that clicking will insert a new block at that position in the flowchart.
To add a control structure, select an empty block and choose ‘Substitute’ from the menu. The different kinds of blocks are:
- Execute – executes a chunk of Python code.
- If – tests the condition.
- Loop – surprisingly enough, this loops.
- For Loop – behaves like a Python for loop.
- Loop Escape – exits the loop (I don’t know why I didn’t call this break. I’ll probably change it to that in a future version of the software).
- Function Def – defines a function.
- Class – defines a class.
- Procedure – defines a funny flowcharty thing which can have multiple input and output routes, and cannot return a value.
- Procedure call – calls a procedure.
- Try – error checking.
- Bottleneck – from multiple strands of execution, the same thing(s) will be run, then the original strand will be resumed.
- Group – allows you to group blocks and give explanatory comments.
Between blocks are mappings. These are denoted by blue circles joined by coloured lines. You can remap any of these by either clicking on the nodes to join, or pressing ‘m’ to enter mapping mode, using e, s, d, f to navigate and enter to select nodes to connect.
I currently develop on Linux. When I originally wrote Flowchart Python I developed in Windows. On Windows, the keycodes returned by pygame do not respect the keyboard layout selected in your operating system. I’m a dvorak user, so this annoyed me. If you are running Flowchart Python on Windows and want to use it in dvorak mode, find the comment near the start of
main.py which says “To start in dvorak keyboard layout, comment out the following line.”, and do what it says.
Another note on keyboard layouts: even when typing in text fields, Flowchart Python uses the physical keystrokes to decide what letters you’ve typed. I guess I wasn’t aware that Pygame key events have a unicode character associated with them. Consequently you’ll find it very hard to insert special characters into the text fields.
How Do I Get It?
Flowchart Python is licensed under version 2 of the GNU General Public License. You may not download, distribute, edit or use the software unless you agree to the terms of the license.
If you accept the license, you can obtain version 1.1 of Flowchart Python on PyPI by following this link.
Now that I’ve dug this code out, I like the idea of doing some more work on it. My coding style has improved in the last six years, so there’s plenty of refactoring I could do. It would also be nice to rename some things to names more familiar to Python developers, and to provide some way of viewing
.py files as flowcharts. That said, I also have many other interesting projects to work on, and I can’t say how much time I’ll chose to spend on Flowchart Python.
8 Responses to Flowchart Python