Page 1 of 1

New Python Script Editor

Posted: Thu Jul 21, 2016 4:03 pm
by kgschlosser
New Python Script Editor

New Version 0.2b Added On 07/21/2016

This plugin does not replace the existing Python Script Editor. (yet)

Features:

Threading!!!
Code Folding
Line Numbers
Folding Comments
Folding Icons
Folding Quoted Items

Number of Indent Spaces
Show Indent Guides
Delete Indent on Backspace
Tab Indents
Show Error on Indent Type

Anti Aliasing
Saving Dialog Size (Global)
Saving Dialog Location (Global)
Left and Right Margin Size
Top and Bottom Margin Size
Show White Space Characters
Zoom In Key
Zoom Out Key

Font Selection Per Colored Item
Color Selection Per Item (Listed Below)

Syntax Detection

Color Selection:
Correct Braces
Incorrect Braces
Caret
Class Names
Comments
Comment Block
Control Characters
Decorators
Definition Names
Double Quotes Strings
Code Folding Icons
Identifiers
Keywords
Custom Keywords
Line Numbers
Missing Closing Quotes
Numbers
Operators
Single Quotes
Triple Double Quotes
Triple Single Quotes
White Space

I have made provisions for coding example tool tips this has not been implemented as of yet.
I have also set up code completion as above not in use as of yet. i am trying to work out how to get the data file with the plugin because the code completion file is to large to do a forum post with

Syntax detection is another biggie. no more with it tossing out a traceback into the log. When you click on the Apply or Test buttons it will compile the code. and if there is an error it will move the editor to that line and add the error to the end of the line letting you know where the error is and what the error is. As soon as you start typing on that line it will remove the error message.

Threading is the biggest and best feature of this plugin in my opinion.
You can now do polling loops inside of a Python Script without having it bind up EG. You can have more then one macro running with a script at the same time.

There is a method as to how this works because you have to be able to close the thread properly as not not end up with anything orphaned. and you can also close the thread from another script if you want. I have plans to make the latter portion a lot easier to handle by returning a script number from the Action so you will be able to grab it and then use it if necessary to close the script.

the plugin will automatically close down the threads properly upon exiting of EG. please read the next forum post for further and more detailed explanation of how to use the threading bits if you are going to be looping. if you aren't going to be doing a processing loop but just want to have the ability to have more then one macro trigger at the same time then there is no need to worry about how to use the threading with a loop.

Extract the attached zip file into the EventGhost\plugins folder. It will make the necessary folders and files.
Restart EventGhost
Add the plugin. Located in the "Others" plugin category.

I am trying to work out a means to have it override the existing plugin script editor. I will add that as an option as soon as I figure out a clean way to do it.

This is a new plugin and needs to be tested fully for any weird issues. and that is why it is being posted now. it's a rather sizeable plugin and i want to make sure everything is working fine before i add anything more to it. so if you experience a problem please let me know so i can fix it. I have tried to test it as much as i can and all seems to work well.

enjoy and have fun

K

Re: New Python Script Editor

Posted: Thu Jul 21, 2016 4:04 pm
by kgschlosser
Ok so here goes about the threading.

this is how to do a polling loop using the threading option in this plugin.

I have overwritten the built in eg.Exit() to provide a lot more functionality then just exiting the script. but it will still work as usual if called in the usual way

eg.Exit()
this command will exit a python script as it has done in the past

eg.Exit.Thread(currthread=None)

this will set the exiting process for a polling loop python script. and if there wasn't a proper thread made it will just call the normal exit routine. this is set up so that if the currthread is not provided it will get the calling thread and match it to one that is in the list and start the exit routine.

if you use it while in a loop without providing the currthread parameter it will close the loop and exit the script.

if you call it with providing the thread you want to close. this is useful if you want to exit a script for another script

eg.Exit.Event(thread=None, event=None)

the above has 2 purposes if the parameters are supplied it will add the script thread and script threading.Event to a list for poling and closing. if there are no parameters supplied it check to see if an exit has been called on that thread and if it has been called will return true and if not return false. this is the core piece of the threading loop in a python script.

there is no need to have to call anything to set up any threads inside of a script this is all done automatically. all you have to do is to click the button and then use the eg.Exit.Event() to check to see if you need to exit.

Code: Select all


i = 0
j = 0
while not eg.Exit.Event():
    i += 1
    if i == 10000:
        i = 0
        j += 1
        print "thread example counter: ", j
    if j == 20:
        eg.Exit.Thread()
print "closing thread"

this is a proper use of how to use the looping thread.
the purpose for this is so that way you can do some repeating code in the loops and then if it's time to close finish it up with some closing code this is very import if you are dealing with something like a TCP/IP socket if you are listening on a port because you want to keep the port open while listening and only close it when you aren't. and you have to close the port otherwise you will orphan it requiring a reboot sometimes to free it up.

Code: Select all

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
try:
    sock.bind(("127.0.0.1", 11111))
    print "socket opened on port 11111 at address 127.0.0.1"
except:
    print "failed to bind port"
else:
    while not eg.Exit.Event():
        try:
            data, addr = sock.recvfrom(1024)
            print "data received -  From: ", str(addr[1]), " , data: ",  data
        except:
            eg.Exit.Thread()
try: sock.close()
except: pass

this is pseudo code for bind a UDP port to listen for messages but shows how error handling is done as well as using the loop and what happens after the loop is closed.
this listening will go on forever or until the thread is closed or there is some kind of an error that forces the thread to be closed.

I am going to be adding more functionality to the eg.Exit() for things like getting the thread and event handler so that way you would be able to assign them easily to a global so you can have another macro either close the thread or even just check to see if it is still running and to see if the closing process has started or taken place. i will provide examples of this when i add that functionality.

K

Re: New Python Script Editor

Posted: Wed Aug 10, 2016 2:52 pm
by Luca Brasi
Great! I'll check it out as soon as I find the time.
Thanks for the hard work!

Re: New Python Script Editor

Posted: Wed Aug 10, 2016 3:04 pm
by Luca Brasi
Had a quick look at it...
First try was simply do a script with a print in it (print "Hallo")
Got this:
17:02:27 Fehler in Befehl: "Python Editor: Script"
17:02:27 Traceback (most recent call last) (1722):
17:02:27 File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
17:02:27 return self(*args)
17:02:27 File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 86, in __call__
17:02:27 "Action has no __call__ method implemented."
17:02:27 NotImplementedError: Action has no __call__ method implemented.
Am I doing something wrong?

Re: New Python Script Editor

Posted: Thu Aug 11, 2016 10:57 am
by kgschlosser
not really sure.

but i do have a new editor that will be released within the day. i am keying up all of the instructions and examples. it's completely different then this one. this version was a first release to see if there were any issues with the config options mainly. as i was venturing into things beyond my know how. i believe i have gotten all of the kinks out of the config side of things with the newest version. but i added so many other features in the process it's going to take a while for me to type them all up.

so hopefully today maybe tomorrow. we will see how things go and if i come across any glitches that need fixing.

Re: New Python Script Editor

Posted: Tue Aug 16, 2016 9:23 pm
by yokel22
I know your working on a update, so just an fyi. I'm getting the same error as Luca.

Re: New Python Script Editor

Posted: Wed Feb 22, 2017 6:55 am
by Diz
is anything happening with fixing this editor?

Re: New Python Script Editor

Posted: Wed Feb 22, 2017 8:32 am
by kgschlosser
I am working on modifying the core of EG to run each event in it's own thread. and would render this plugin obsolete. attached is a newer version of it. tho i do not remember what is or is not working...

Re: New Python Script Editor

Posted: Wed Feb 22, 2017 4:48 pm
by Diz
oh ok. that works even less than the first one! i guess i will wait for the core update instead ;)

Re: New Python Script Editor

Posted: Thu Feb 23, 2017 7:47 pm
by kgschlosser
LOL. i do not remember where i left off with it. and the code for it is very ugly. and I have learned so much more since i last fiddled with it it would probably be easier for me to do a rewrite. but there are some of the features for it i do like and has sparked some ideas for how to pass things to scripts but to also be able to retrieve from it. and also the way it handles tracebacks as well.. some of these things might be good to add to the core script editor. i will bring this up with the dev team and see what they think. it could be some time before the threading of the events gets added. there is a very large change that has to be made with EG to allow the event threading to work and I am trying to find an easy solution to make it work. but have been unsuccessful. and i am going to have to change a lot of things about. nothing that the user would notice. but making it so that the EG API stays the same is proving to be rather difficult.

Re: New Python Script Editor

Posted: Thu Feb 23, 2017 8:13 pm
by Diz
ok cool, but dont waste time on this plugin editor for my benefit as i am happy to wait for the core update :)

Re: New Python Script Editor

Posted: Fri Feb 24, 2017 10:55 pm
by kgschlosser
I did find a solution to my issue with the core update.. YAY.. I am going to try and put some time into it this evening to see if i can get it running.. then it's off to testing and debugging.. I would love to get it into the 0.5 Final release. we will see what happens.