Important Setup PyCharm for Python plugins

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
3,956
1,129
113
At your house.
github.com
Lets do some nice Python plugins for Fougerite. Though for that, you might want to use an IDE.
So lets go ahead and download PyCharm. BUT, before Installing it.

PyCharm is one of the best Python IDEs, and It also supports IronPython, which we use on Fougerite.

So what are you going to need? Well, if you are familiar with Python, then you already know that you need to install Python. If you have never heard about Python, until your download finishes, let me give you a small description about Python. I can tell you that It's one of the most flexible, easiest language to handle. It's fast, stable, and good for small applications, and to be used as Scripting languages. Those who started with Java, or JavaScript, C#, C++ (Which contain { }, Alias brackets) might have some problems using It for the first time. I started with Python, I loved It. I know you are going to love It too. Youtube, and Dropbox are also written in Python. For more information about Python, check the wiki. If you would like to get some basic training, then visit this website.

Now that you have downloaded Python, and PyCharm, be sure to install both. You probably think that you finished, well no, not really. You will need IronPython installed, since that will be the SDK, that you will be working on.

So the requirements at the moment are:
Python
PyCharm
IronPython

Now that you have got everything installed, run PyCharm.

A nice window like this should popup. (Might not be black)



Lets go ahead and create a new project.
The next window is important for us, since that will be one of the part, where you define your SDK.



Now, at this time we won't be working with Python, but with IronPython. Select the interpreter, and locate "ipy.exe", It should be in the folder where you installed it.

It should look like this now:



Press OK.

Here we will be having our interface of the IDE. As you can see under the libraries we have IronPython imported. But that's not enough.



Since we are going to create a plugin, not an application, that's the reason why we decided to go with an empty sample project.

Lets create a Directory, but you can also create a (python) package, just like in Java, and create your Python files there. Your call. I'm gonna go ahead and create a directory.



I have created a folder called KillLog, now lets create a py file with the same name.



Yaay, we created a Py file. We got our nice Author sign there, but thats still not enough.
To create a plugin in Fougerite, we need to import clr, and then reference to the Fougerite dll.



Python:
import clr
clr.AddReferenceByPartialName("Fougerite")
And here gets a bit complicated. Well as an example, to show how to use methods in the IDE, I will be using Fougerite's null object method check.

Python:
__author__ = 'DreTaX'
import clr
import sys
"""
This method has to be uncommented when you will use the plugin on your live server.
"""
#clr.AddReferenceByPartialName("Fougerite")

"""
The below method in the place where our Fougerite.dll is.
This will define our IDE where to look for the functions
In python we use double \\ when giving paths.

Note: sys.path and clr.AddReferenceToFile is not required when running the plugin on a live server.
When ever you are planning to try the plugin, please COMMENT these two lines.
"""
sys.path.Add("d:\\Python33\\Fougerite\\")

"""
As above, we have given our IDE the path where to look for the libraries.
Now we define which dlls do we need.
"""
clr.AddReferenceToFile("Fougerite.dll")

#This might show errors in your IDE, if it does, just hover your mouse on the red lamp and click to ignore reference.
import Fougerite

# Lets do a simple null check here
notnull = "ImNotNull"
null = None
asd = Fougerite.Util.GetUtil().IsNull(notnull)
asd2 = Fougerite.Util.GetUtil().IsNull(null)
print asd, asd2
The output will be:



NOTES:

Be sure not to use "from Fougerite import" when running the plugin on your server, cause It will make errors.

So just to be sure and clarify the comments I gave. If you want to use it on a live server, you would need to comment the sys.path, and the referencetofile methods, BUT instead you will HAVE TO use AddReferenceByParticialName.




I hope I did help.

 
Last edited:

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
38
18
California
While we are on the subject of PyCharm, if you are a student can get


JetBrains is offering their IDE and .NET Tools Software for Free (valid for 1-Year) with a valid .Edu email address.
  1. Click here, scroll down and click on the "Apply Now" button
  2. Enter your name and .Edu email address in the space provided and click "Apply for Free Products"
  3. You will receive an email to activate your educational license. Upon activation, you will need to create a JetBrains account.
  4. After downloading and installing the software, follow the on-screen prompts and simply sign in with your JetBrains account. A license key is not required.
Includes:
  • IntelliJ IDEA
    • Java IDE
  • ReSharper
    • Productivity tool for .NET developers
  • AppCode
    • Objective-C IDE
  • PhpStorm
    • IDE for Web & PHP
  • PyCharm
    • Python and Django IDE
  • RubyMine
    • IDE for Ruby and Rails
  • WebStorm
    • Smart JavaScript IDE
  • dotCover
    • .NET Code Coverage Tool
  • dotTrace
    • .NET Code Coverage Tool
  • dotMemory
    • .NET Memory Profiler
Just saying...for people that want the Professional version, however the Community Version of PyCharm is free.
 

mikec

Master Of All That I Survey
Administrator
Jul 12, 2014
296
109
28
Los Angeles, California, USA
The PyCharm Pro version is basically WebStorm lite with Python support. AngularjS, HTML5, CSS, Node,js, CoffeeScript, are all supported in the Pro version.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
3,956
1,129
113
At your house.
github.com
Okay I added some stuffs, thats all i could add atm. If anyone think he can extend it, leave some msgs in the comment below, with a continued "story", if not, It's not a problem I will finish it.
 
  • Agree
Reactions: Snake

balu92

Moderator
Moderator
Jul 11, 2014
338
71
28
27
note that in IPModule when you use print, it will print the msg, content, whatever to the output_log.txt file
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
3,956
1,129
113
At your house.
github.com
Mike asked me to notify you guys about some stuffs, which I found out:

When doing python plugins:

Make sure your method name doesn't have the same name as ur class name
Because the old py thinks ur doing constructer from outside.
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
3,956
1,129
113
At your house.
github.com
Who wants to work with ironpy, watch It cause if something contains a number, It's wise to use the str(number) method, or It will throw an error.

Also, here is a complete plugin, which may help you as an example of the structure.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
3,956
1,129
113
At your house.
github.com
I have been testing with @balu92 and I think we did a pretty great progress on the testing, we could eliminate & find several bugs.

Unfortunately, he didn't give the release out here yet, since there wasn't any MC updates from mike. If you want It you can grab it (The module dll) from my github where my Python Plugins are.
 

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
38
18
California
Note: Mono is required if running on Linux, Mac OS, or BSD.
IronPython runs on Mono, a cross platform, open source .NET framework, enables IronPython to be used on Linux, Mac OS, and BSD systems.
Installing this on my Mac, little bit harder to get running...:(