Important Setup PyCharm for Python plugins

Discussion in 'Tutorials & F.A.Q.' started by DreTaX, Sep 25, 2014.

  1. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    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)

    [​IMG]

    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.

    [​IMG]

    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:

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

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

    [​IMG]

    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.

    [​IMG]

    Code (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.

    Code (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:

    [​IMG]

    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.


    [​IMG]

    I hope I did help.

     
    #1
    Last edited: Aug 2, 2018
    • Informative Informative x 2
    • Winner Winner x 1
  2. Snake
    Offline

    Snake Moderator Moderator

    Joined:
    Jul 13, 2014
    Messages:
    288
    Likes Received:
    44
    asdfg?
     
    #2
  3. CorrosionX
    Offline

    CorrosionX Plugin Developer Plugin Developer

    Joined:
    Sep 3, 2014
    Messages:
    212
    Likes Received:
    16
    While we are on the subject of PyCharm, if you are a student can get

    [​IMG]
    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.
     
    #3
  4. mikec
    Offline

    mikec Master Of All That I Survey Administrator

    Joined:
    Jul 12, 2014
    Messages:
    296
    Likes Received:
    59
    A PyCharm license is also not very expensive. $99 for life, and you can use it on as many computers as you want, Linux, Windows, Mac.
     
    #4
  5. CorrosionX
    Offline

    CorrosionX Plugin Developer Plugin Developer

    Joined:
    Sep 3, 2014
    Messages:
    212
    Likes Received:
    16
    That is good to know! Thanks! :)
     
    #5
  6. mikec
    Offline

    mikec Master Of All That I Survey Administrator

    Joined:
    Jul 12, 2014
    Messages:
    296
    Likes Received:
    59
    The PyCharm Pro version is basically WebStorm lite with Python support. AngularjS, HTML5, CSS, Node,js, CoffeeScript, are all supported in the Pro version.
     
    #6
  7. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    I have Intellij IDEA, WebStorm, and PyCharm.

    I love Java and Intellij does a prof. work.
     
    #7
  8. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    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.
     
    #8
    • Agree Agree x 1
  9. balu92
    Offline

    balu92 Moderator Moderator

    Joined:
    Jul 11, 2014
    Messages:
    338
    Likes Received:
    31
    note that in IPModule when you use print, it will print the msg, content, whatever to the output_log.txt file
     
    #9
    Last edited: Sep 26, 2014
  10. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    Well Happy py programming gentleman. Enjoy.
     
    #10
    • Like Like x 1
  11. Snake
    Offline

    Snake Moderator Moderator

    Joined:
    Jul 13, 2014
    Messages:
    288
    Likes Received:
    44
    My turn to make the C# tut ? :p
     
    #11
    • Funny Funny x 1
  12. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    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.
     
    #12
    Last edited: Sep 28, 2014
  13. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    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.
     
    #13
  14. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    Watch It.
    Don't use undefined. IronPython.Runtime.UnboundNameException: global name 'undefined' is not defined
     
    #14
    • Funny Funny x 1
  15. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    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.
     
    #15
  16. CorrosionX
    Offline

    CorrosionX Plugin Developer Plugin Developer

    Joined:
    Sep 3, 2014
    Messages:
    212
    Likes Received:
    16
    Note: Mono is required if running on Linux, Mac OS, or BSD.
    Installing this on my Mac, little bit harder to get running...:(
     
    #16
  17. P0LENT4 2
    Offline

    P0LENT4 2 Member Member

    Joined:
    Dec 26, 2016
    Messages:
    31
    Likes Received:
    1
    @DreTaX , Why can not I see the images in this post? it would be very important for me to visualize
     
    #17
  18. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    I have digged up those images lucky for you i still had them.
     
    #18
  19. P0LENT4 2
    Offline

    P0LENT4 2 Member Member

    Joined:
    Dec 26, 2016
    Messages:
    31
    Likes Received:
    1
    Can someone tell me what's wrong?
    Captura de Tela (77).png
     
    #19
  20. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,837
    Likes Received:
    609
    "#This might show errors in your IDE, if it does, just hover your mouse on the red lamp and click to ignore reference."
     
    #20

Share This Page