Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

[SOLVED] Developer tool: "Copy as Python"

Got a good idea? You can suggest new features here.
Post Reply
User avatar
blackwind
Experienced User
Posts: 182
Joined: Wed Sep 12, 2012 2:59 am
Location: Canada
Contact:

[SOLVED] Developer tool: "Copy as Python"

Post by blackwind »

The current method of retrieving an action's corresponding Python code (Ctrl+C) has a number of pitfalls:
  1. Why should I have to open another window, paste, and clip out what I need?
  2. Why should I have to manually unescape ampersands and other HTML entities escaped by the XML generator?
  3. Why should I have to prepend "eg.plugins." to the result?
These could all be resolved with a "Copy as Python" menuitem, perhaps with Shift+Ctrl+C as its shortcut. Such an addition would increase the speed of my workflow immensely. Thoughts?
Last edited by blackwind on Thu Jul 07, 2016 12:45 am, edited 1 time in total.
/bw
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Developer tool: "Copy as Python"

Post by Pako »

=> 0.4.1.r1600
Attachments
CopyAsPython_1.jpg
CopyAsPython_1.jpg (12.7 KiB) Viewed 9328 times
CopyAsPython_2.jpg
CopyAsPython_2.jpg (18.87 KiB) Viewed 9328 times
CopyAsPython_3.jpg
CopyAsPython_3.jpg (11.66 KiB) Viewed 9328 times
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Developer tool: "Copy as Python"

Post by miljbee »

Excellent !
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
cfull1
Experienced User
Posts: 124
Joined: Thu Aug 19, 2010 4:52 am

Re: Developer tool: "Copy as Python"

Post by cfull1 »

Very nice.
jonib
Plugin Developer
Posts: 1328
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: Developer tool: "Copy as Python"

Post by jonib »

So I finally needed to use the "Copy as Python" command. Thanks for adding it very useful.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image
User avatar
blackwind
Experienced User
Posts: 182
Joined: Wed Sep 12, 2012 2:59 am
Location: Canada
Contact:

Re: Developer tool: "Copy as Python"

Post by blackwind »

A small bug: Copy as Python doesn't work as expected with Python Script objects.
/bw
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Developer tool: "Copy as Python"

Post by Pako »

blackwind wrote:A small bug: Copy as Python doesn't work as expected with Python Script objects.
This is weird.
I tried it just now and no problem I have encountered.
Probably it will depend on the content. Can you please attach a script to which it is a problem?

Pako
User avatar
blackwind
Experienced User
Posts: 182
Joined: Wed Sep 12, 2012 2:59 am
Location: Canada
Contact:

Re: Developer tool: "Copy as Python"

Post by blackwind »

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1610">
    <Action Name="Disable WOW64 Redirection">
        EventGhost.PythonScript(u'import win32file\nwin32file.Wow64DisableWow64FsRedirection()\n')
    </Action>
</EventGhost>
When copied as Python, this is the result:

Code: Select all

eg.plugins.sion="1.0" encoding="UTF-8" ?>
<EventGhost Version="1610">
    <Action Name="Disable WOW64 Redirection">
        EventGhost.PythonScript(u'import win32file\nwin32file.Wow64DisableWow64FsRedirection()\n')
This only applies to Python Scripts -- not Python Commands.
/bw
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Developer tool: "Copy as Python"

Post by Pako »

So now it is completely clear.
The bug is not related to Python Script action, but any action that is renamed (its label in the tree is written in italics).
But it is obvious, that it happens most frequently just with Python Script :) .
You can download the corrected file TreeItem.py.

Pako
User avatar
blackwind
Experienced User
Posts: 182
Joined: Wed Sep 12, 2012 2:59 am
Location: Canada
Contact:

Re: Developer tool: "Copy as Python"

Post by blackwind »

Ah, that's interesting. Yep, Python Scripts are the only actions I ever rename, and I've done so for every single one in my config.

One last thing: I was thinking, wouldn't it make more sense if Python Commands and Scripts copied as their contained code rather than an eg.plugins reference? So, this:

Code: Select all

import win32file
win32file.Wow64DisableWow64FsRedirection()
...rather than this:

Code: Select all

eg.plugins.EventGhost.PythonScript(u'import win32file\nwin32file.Wow64DisableWow64FsRedirection()\n')
I, for one, can't think of any scenario in which I'd want the latter over the former.
/bw
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Developer tool: "Copy as Python"

Post by Pako »

Yes, it is a good idea. It's logical.
I thought it would be very simple. But it gave me quite a hard time.
I had received ...

Code: Select all

import win32file\nwin32file.Wow64DisableWow64FsRedirection()
instead of ...

Code: Select all

import win32file
win32file.Wow64DisableWow64FsRedirection()
and long time I could not figure out how to get rid of.
But now it works. Again, you can download the new version of TreeItem.py file.

Pako
User avatar
blackwind
Experienced User
Posts: 182
Joined: Wed Sep 12, 2012 2:59 am
Location: Canada
Contact:

Re: Developer tool: "Copy as Python"

Post by blackwind »

Excellent. I'd recommend removing the trailing " + chr(10)" on both lines so the code that's copied is identical to the code written, but other than that, looks good!
/bw
Post Reply