Monkey Studio IDE The way IDEs should be

tutorials/run-python-file-without-project

In this tutorial, you will learn how to use the "Tools" plugin and create a simple user tool.

Motivation

Sometimes, one wants to create a small file to quickly try out something - e.g. test the new library one just built. For this reason, it is very handy to have something a little "Run"-Button that just runs this file without running the whole project.

A way to do this is creatig a new project, including this file into the project and run the project. But this takes some time and is unneccessary because we are not interested in developing the file any further. So we would like to run the script directly.

If using an interpreter language, like python, this is extremely simple: Just feed the file to the interpreter and you're done. If it's a compiler language like C++, it's not much harder: Compile and run.

I will show you how to integrate this into MkS in the first case.

The Tools plugin

  1. Start Monkeystudio
  2. Go to Plugins -> Basic -> Tools and make sure "Enabled" is ticked: You enabled the "Tools"-Plugin and there should now appear an entry "Tools" in the main menu every time you start MkS.
  3. Open the menu entry "Tools" and find the (empty) "User Tools" list, "Desktop Tools" list and "edit" buttons for both of them. The "User Tools" list is the place where the desired tool will be visible in a moment.
  4. Click on the "Edit User Tools..." button. A window will appear. On top, there are buttons to add, delete and move User Tools. Directly below there is the (empty) list of User Tools.
  5. Add a User Tool by clicking on the "+"-Button. Its name will be "new Tool".
  6. Under the list, there are three text field where you can edit the tool.

Configuring a User Tool to run a python file

  1. Edit the text field below "Caption" to change the name under which the tool will appear in the menu. For example: "Run python file"
  2. In "File Path", you have to specify the command that will be executed. We want to run python on the currently open tab.
    1. We will write down "python".
      • Note: In some systems, the PATH variable may be set up incorrectly which will result in some error like "Bad command or filename". In this case, set up the PATH variable to correctly include the path where the python executable is or find out where it is (e.g. "/usr/bin/python" or "C:\python26") and insert this into the "File Path" field instead of "python".
    2. Now we have to hand over the file name of the python file to the interpreter. Of course we want to have MkS look it up on its own. You can click on the help button to find out the way to do this, or just trust me: "$cf$" is replaced by MkS with the name of the file in the active tab.
    3. In the "File Path" text field, we now have something like "python $cf$".
  3. In "Working Path", write $cfp$, which is replaced by MkS with the directory that contains the file in the active tab.
  4. Check the Box "Execute using console manager". This redirects the output of your script to MkS.
  5. You can now click ok and write or open a python file. You *don't* need to create or open a project.
  6. When you are ready, on the main menu, click on Tools -> User Tools -> Run Python file. (Or appropriately, if you chose another name) The file is now run.
  7. On the bottom of the IDE, you can choose the "Output"-Panel and look at the output of your script.

<img src="https://lh4.googleusercontent.com/-X_GFXWrCIFg/TzjDKa7ipSI/AAAAAAAAAgg/18JTtl5sGvw/s640/Screenshot-1.png" height="400" width="640" />
Альбом: Monkey Studio

Lookout

  • You can assign a keyboard shortcut to this:
    1. Go to Edit -> Shortcuts Editor. A window containing a list of all shortcuts and actions appears.
    2. In "Action Filter", type "Run python file". (or appropriately) Everything greys out except of your previously defined User Tool.
    3. Click on it, press the Keyboard Shortcut you want and click on "Set". You can now use the keyboard shortcut.
  • Currently it is not possible to feed console input to the python script. So if you have raw_input() in your code, the script will just hang until you press the "Stop" button on the upper right side. This might be changed in some future version of Monkeystudio.