Python scripting question

Moderator: Kathy_9

Post Reply
321
Posts: 22
Joined: Sun Mar 13, 2011 5:55 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-5500U
ram: 8GB
Video Card: Intel 5500
Hard_Drive_Capacity: 512GB

Python scripting question

Post by 321 »

Hi. I'm fumbling around with a Python script and need a bit of help. Is it possible to make an input dialog with a "Browse" button so the user can find a folder (to be loaded into a variable in the script)? I can't find any documentation on such an object.
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Python scripting question

Post by LeviFiction »

It is possible, yes.

PSP does not have a command for it but luckily it does come with quite a few advanced Python libraries.

Look up either TKinter or if you're adventurous the python ctypes library should give you access to the base Windows API and you can do full Windows programming inside of Python.

While still difficult to a degree, TKinter has more tutorials in Python than Windows does and is a lot easier to work with.
https://levifiction.wordpress.com/
321
Posts: 22
Joined: Sun Mar 13, 2011 5:55 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-5500U
ram: 8GB
Video Card: Intel 5500
Hard_Drive_Capacity: 512GB

Re: Python scripting question

Post by 321 »

LeviFiction wrote:It is possible, yes.

PSP does not have a command for it but luckily it does come with quite a few advanced Python libraries.

Look up either TKinter or if you're adventurous the python ctypes library should give you access to the base Windows API and you can do full Windows programming inside of Python.

While still difficult to a degree, TKinter has more tutorials in Python than Windows does and is a lot easier to work with.
Whoa, I didn't realize the scripting could be that powerful. I'll first take a look and see if TKinter can get me there; easier certainly doesn't hurt since me and OOP don't get along well to begin with. It's too bad PSP doesn't have the command for it but I don't imagine a lot of people want to get very far into scripting.
321
Posts: 22
Joined: Sun Mar 13, 2011 5:55 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-5500U
ram: 8GB
Video Card: Intel 5500
Hard_Drive_Capacity: 512GB

Re: Python scripting question

Post by 321 »

OK, the world of Python is quite interesting and I'm thinking of taking it to task.

Now I'm trying to open and copy a "pixel-perfect" watermark PNG image into an active image (with focus) through the use of a script. The script works with one exception: if the image that is getting the watermark isn't the last one opened before the script is started, the script gets lost and drops the watermark on the wrong image. I realize the SelectDocument command is relative, but this doesn't help if the number of images that are open is unknown, as is often the case. How can I set up the script to find the original target document after the watermark image has been open, copied and closed? More specifically, is there a way to get the value of SelectedImage for the opened-by-the-script watermark document (which would be relative to the original target document)?
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Python scripting question

Post by LeviFiction »

Yes

Code: Select all

    #Taken From SplitRGBtoLayerGroup.PSPScript
    # keep track of the doc we are starting with
    TargetDoc = App.TargetDocument


If you look in your scripts list you'll see a script for Split RGB To Layer Group. Split RGB To Layer Group is a script that runs the Image->Split to RGB command. This command creates 3 new greyscale images based on the Red Green and Blue channel values of the currently opened image. But the problem is it creates three new images. So what the script then does is it compares the old document list to the new document list and finds out which images are brand new since the script started. Then then grabs those and adds them into the original target image as individual layers and finally places them into a layer group.

Open that script in the editor and you'll get an excellent example of just how that sort of thing is done.
https://levifiction.wordpress.com/
321
Posts: 22
Joined: Sun Mar 13, 2011 5:55 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-5500U
ram: 8GB
Video Card: Intel 5500
Hard_Drive_Capacity: 512GB

Re: Python scripting question

Post by 321 »

OK, that example helped out a lot. I saw TargetDocument in the Corel documentation, but misread that it changes upon losing focus. That's why a little assistance is much appreciated-thanks.

This is what made it work for my script. I trust its going to hold up for more than just the testing;). While the original photo still hadn't lost its active status, I added this line:

Code: Select all

    TargetDoc = App.TargetDocument
Then, along with the first command following the closing of the new file in the script, I added a comma (to separate the optional 3rd & 4th App.Do parameters) and the new TargetDoc variable as the 4th parameter to specify the original photo. It worked!

Code: Select all

    # PasteAsNewLayer
    App.Do( Environment, 'PasteAsNewLayer', {
            'CreateFromDropData': False, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((14,0,0),1)
                }
            } , TargetDoc ) 
Post Reply