Get clipboard pasted into script?

Moderator: Kathy_9

Post Reply
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Get clipboard pasted into script?

Post by terrypin »

I have some text on the clipboard. How can I run an unattended script that will get that into a text operation please?

For example, instead of this script entering My text, I want it to enter whatever I've pasted to the clipboard:

Code: Select all

from JascApp import *

def ScriptProperties():
    return {
        'Author': u'Terry Pinnell',
        'Copyright': u'',
        'Description': u'',
        'Host': u'Paint Shop Pro',
        'Host Version': u'8.10'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            
            })

    # Text
    App.Do( Environment, 'Text', {
            'CreateAs': App.Constants.CreateAs.Vector, 
            'Segments': [{
                'Bold': App.Constants.Boolean.true, 
                'Fill': {
                    'Color': (0,0,0), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }, 
                'Font': u'Arial', 
                'LineStyle': {
                    'Name': u'', 
                    'FirstCap': (u'Butt',0.25,0.25), 
                    'LastCap': (u'Butt',0.25,0.25), 
                    'FirstSegCap': (u'',0.25), 
                    'LastSegCap': (u'',0.25), 
                    'UseSegmentCaps': App.Constants.Boolean.false, 
                    'Segments': []
                    }, 
                'LineWidth': 0, 
                'PointSize': 18, 
                'SetText': App.Constants.Justify.Center, 
                'Start': (17.5,175.5), 
                'Stroke': {
                    'Color': (255,255,220), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }
                },{
                'Antialias': App.Constants.Boolean.true, 
                'WarpText': App.Constants.Boolean.true, 
                'AutoKern': App.Constants.Boolean.true, 
                'Bold': App.Constants.Boolean.true, 
                'Kerning': 0, 
                'Leading': 0, 
                'Fill': {
                    'Color': (0,0,0), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }, 
                'Font': u'Arial', 
                'Italic': App.Constants.Boolean.false, 
                'Join': App.Constants.JointStyle.Miter, 
                'LineStyle': {
                    'Name': u'', 
                    'FirstCap': (u'Butt',0.25,0.25), 
                    'LastCap': (u'Butt',0.25,0.25), 
                    'FirstSegCap': (u'',0.25), 
                    'LastSegCap': (u'',0.25), 
                    'UseSegmentCaps': App.Constants.Boolean.false, 
                    'Segments': []
                    }, 
                'LineWidth': 0, 
                'MiterLimit': 10, 
                'PointSize': 18, 
                'SetText': App.Constants.Justify.Left, 
                'Start': (17.5,175.5), 
                'Strikethru': App.Constants.Boolean.false, 
                'Stroke': {
                    'Color': (255,255,220), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }, 
                'Underline': App.Constants.Boolean.false
                },{
                'Characters': u'My text'
                }], 
            'SavedText': None, 
            'FinalApply': App.Constants.Boolean.false, 
            'Matrix': None, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Get clipboard pasted into script?

Post by LeviFiction »

o.o

So there isn't a built in option to do that. You have to use external libraries, so this will be a script that is run from the Scripts Trusted folder. If you don't put this script into your Scripts-Trusted folder it won't run at all. Of course I can't guarantee it'll run for you anyway. The biggest issue is that I don't know what your version of Python has.

If your version of Python contains ctypes or TKinter then we're golden. We can create a clipboard copy/paste operation.

Here's a version of your script that contains a simple "getText" function that is supposed to grab text from the clipboard if it has it. The "getText" code was taken from http://stackoverflow.com/questions/1011 ... rom-python

This code only supports plain text. Nothing fancy. If you want it to maintain bolding and stuff like that, that would take a huge amount of work to do in script.

Code: Select all

from JascApp import *
import ctypes

def ScriptProperties():
    return {
        'Author': u'Terry Pinnell',
        'Copyright': u'',
        'Description': u'',
        'Host': u'Paint Shop Pro',
        'Host Version': u'8.10'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            
            })

    # Text
    App.Do( Environment, 'Text', {
            'CreateAs': App.Constants.CreateAs.Vector, 
            'Segments': [{
                'Bold': App.Constants.Boolean.true, 
                'Fill': {
                    'Color': (0,0,0), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }, 
                'Font': u'Arial', 
                'LineStyle': {
                    'Name': u'', 
                    'FirstCap': (u'Butt',0.25,0.25), 
                    'LastCap': (u'Butt',0.25,0.25), 
                    'FirstSegCap': (u'',0.25), 
                    'LastSegCap': (u'',0.25), 
                    'UseSegmentCaps': App.Constants.Boolean.false, 
                    'Segments': []
                    }, 
                'LineWidth': 0, 
                'PointSize': 18, 
                'SetText': App.Constants.Justify.Center, 
                'Start': (17.5,175.5), 
                'Stroke': {
                    'Color': (255,255,220), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }
                },{
                'Antialias': App.Constants.Boolean.true, 
                'WarpText': App.Constants.Boolean.true, 
                'AutoKern': App.Constants.Boolean.true, 
                'Bold': App.Constants.Boolean.true, 
                'Kerning': 0, 
                'Leading': 0, 
                'Fill': {
                    'Color': (0,0,0), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }, 
                'Font': u'Arial', 
                'Italic': App.Constants.Boolean.false, 
                'Join': App.Constants.JointStyle.Miter, 
                'LineStyle': {
                    'Name': u'', 
                    'FirstCap': (u'Butt',0.25,0.25), 
                    'LastCap': (u'Butt',0.25,0.25), 
                    'FirstSegCap': (u'',0.25), 
                    'LastSegCap': (u'',0.25), 
                    'UseSegmentCaps': App.Constants.Boolean.false, 
                    'Segments': []
                    }, 
                'LineWidth': 0, 
                'MiterLimit': 10, 
                'PointSize': 18, 
                'SetText': App.Constants.Justify.Left, 
                'Start': (17.5,175.5), 
                'Strikethru': App.Constants.Boolean.false, 
                'Stroke': {
                    'Color': (255,255,220), 
                    'Pattern': None, 
                    'Gradient': None, 
                    'Texture': None, 
                    'Identity': u'Material'
                    }, 
                'Underline': App.Constants.Boolean.false
                },{
                'Characters': getText()
                }], 
            'SavedText': None, 
            'FinalApply': App.Constants.Boolean.false, 
            'Matrix': None, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
            
def getText():
    CF_TEXT = 1

    k = ctypes.windll.kernel32
    u = ctypes.windll.user32

    u.OpenClipboard(0)
    text = ""
    if u.IsClipboardFormatAvailable(CF_TEXT):
        data = u.GetClipboardData(CF_TEXT)
        data_locked = k.GlobalLock(data)
        text = ctypes.c_char_p(data_locked)
        text = text.value.decode("utf-8")
        k.GlobalUnlock(data_locked)
    u.CloseClipboard()
    return text
I know you're not a scripter but for anyone else. What the writer of this function did is used the ctypes library to actually access the Windows win32 api. This is what allows us access Windows resources like the Clipboard. It's possible to make this a lot more robust but for simple text it should work.
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Get clipboard pasted into script?

Post by terrypin »

Thanks LeviFiction, but unfortunately it doesn't seem to work in PSP8, giving this error:

Traceback (most recent call last):
File "C:\Docs\My PSP8 Files\Scripts-Trusted\Clipboard to PSP8 Text-2.PspScript", line 2, in ?
import ctypes
ImportError: No module named ctypes

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Get clipboard pasted into script?

Post by LeviFiction »

Yeah I figured that was a possibility.

That just leaves TKinter. If PSP8 does not have Tkinter then access to the clipboard, while not impossible, won't be as easy.

Can you do a search in the Corel Program Files folder for "lib-tk" or "tcl"? I would post code to try but I don't know the proper code off hand.
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Get clipboard pasted into script?

Post by terrypin »

This looks more promising.

Both of those seem available. Here are some relevant folders/subfolders:
https://dl.dropboxusercontent.com/u/401 ... rary-1.jpg

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Get clipboard pasted into script?

Post by LeviFiction »

Alright, so this code is taken from the exact same place but uses the Tkinter GUI library to access the clipboard.

Once again, the script must be saved to your Scripts-trusted folder in order for this to work.

Code: Select all

from JascApp import *
from Tkinter import Tk

def ScriptProperties():
    return {
        'Author': u'Terry Pinnell',
        'Copyright': u'',
        'Description': u'',
        'Host': u'Paint Shop Pro',
        'Host Version': u'8.10'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
           
            })

    # Text
    App.Do( Environment, 'Text', {
            'CreateAs': App.Constants.CreateAs.Vector,
            'Segments': [{
                'Bold': App.Constants.Boolean.true,
                'Fill': {
                    'Color': (0,0,0),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    },
                'Font': u'Arial',
                'LineStyle': {
                    'Name': u'',
                    'FirstCap': (u'Butt',0.25,0.25),
                    'LastCap': (u'Butt',0.25,0.25),
                    'FirstSegCap': (u'',0.25),
                    'LastSegCap': (u'',0.25),
                    'UseSegmentCaps': App.Constants.Boolean.false,
                    'Segments': []
                    },
                'LineWidth': 0,
                'PointSize': 18,
                'SetText': App.Constants.Justify.Center,
                'Start': (17.5,175.5),
                'Stroke': {
                    'Color': (255,255,220),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    }
                },{
                'Antialias': App.Constants.Boolean.true,
                'WarpText': App.Constants.Boolean.true,
                'AutoKern': App.Constants.Boolean.true,
                'Bold': App.Constants.Boolean.true,
                'Kerning': 0,
                'Leading': 0,
                'Fill': {
                    'Color': (0,0,0),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    },
                'Font': u'Arial',
                'Italic': App.Constants.Boolean.false,
                'Join': App.Constants.JointStyle.Miter,
                'LineStyle': {
                    'Name': u'',
                    'FirstCap': (u'Butt',0.25,0.25),
                    'LastCap': (u'Butt',0.25,0.25),
                    'FirstSegCap': (u'',0.25),
                    'LastSegCap': (u'',0.25),
                    'UseSegmentCaps': App.Constants.Boolean.false,
                    'Segments': []
                    },
                'LineWidth': 0,
                'MiterLimit': 10,
                'PointSize': 18,
                'SetText': App.Constants.Justify.Left,
                'Start': (17.5,175.5),
                'Strikethru': App.Constants.Boolean.false,
                'Stroke': {
                    'Color': (255,255,220),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    },
                'Underline': App.Constants.Boolean.false
                },{
                'Characters': getText()
                }],
            'SavedText': None,
            'FinalApply': App.Constants.Boolean.false,
            'Matrix': None,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
           
def getText():
    r = Tk()
    text = r.clipboard_get()
    r.withdraw()
    r.update()
    r.destroy()
    return text
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Get clipboard pasted into script?

Post by terrypin »

Many thanks for sticking with me on this and I'm sure success is close, but when I run that on a new image I get this in the Script Output:

Executing RunScript
Executing EnableOptimizedScriptUndo
Traceback (most recent call last):
File "C:\Docs\My PSP8 Files\Scripts-Trusted\GetClipboard-LeviFiction-2.PspScript", line 20, in Do
App.Do( Environment, 'Text', {
File "C:\Docs\My PSP8 Files\Scripts-Trusted\GetClipboard-LeviFiction-2.PspScript", line 106, in getText
text = r.clipboard_get()
AttributeError: Tk instance has no attribute 'clipboard_get'

Doubt if it helps, but a search with my text editor for the string 'clipboard_get' in C:\Program Files\Jasc Software Inc\Paint Shop Pro 8\Python Libraries produced no hits and clipboard produced these 39:

Code: Select all

Searching for: clipboard
DLLs\tk83.dll(11977):  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÞ
DLLs\tk83.dll(12745): (button invoke)
DLLs\tk83.dll(12841): (command for "
DLLs\tk83.dll(13773): ˆ
DLLs\tk83.dll(13830): þ
DLLs\tk83.dll(14290): 
Lib\lib-tk\Tkinter.py(461): # Clipboard handling:
Lib\lib-tk\Tkinter.py(462): def clipboard_clear(self, **kw):
Lib\lib-tk\Tkinter.py(463): """Clear the data in the Tk clipboard.
Lib\lib-tk\Tkinter.py(468): self.tk.call(('clipboard', 'clear') + self._options(kw))
Lib\lib-tk\Tkinter.py(469): def clipboard_append(self, string, **kw):
Lib\lib-tk\Tkinter.py(470): """Append STRING to the Tk clipboard.
Lib\lib-tk\Tkinter.py(473): argument specifies the target display. The clipboard
Lib\lib-tk\Tkinter.py(476): self.tk.call(('clipboard', 'append') + self._options(kw)
Lib\lib-tk\Tkinter.pyc(250): 
Lib\lib-tk\Tkinter.pyc(253): argument specifies the target display.s	
Lib\lib-tk\Tkinter.pyc(256): argument specifies the target display. The clipboard
Lib\lib-tk\Tkinter.pyc(257): can be retrieved with selection_get.s	
Lib\lib-tk\Tkinter.pyc(554): 
TCL\tk8.3\console.tcl(382): clipboard clear -displayof %W
TCL\tk8.3\console.tcl(383): clipboard append -displayof %W $data
TCL\tk8.3\console.tcl(389): clipboard clear -displayof %W
TCL\tk8.3\console.tcl(390): clipboard append -displayof %W $data
TCL\tk8.3\console.tcl(396): set clip [selection get -displayof %W -selection CLIPBOARD]
TCL\tk8.3\entry.tcl(37): clipboard clear -displayof %W
TCL\tk8.3\entry.tcl(38): clipboard append -displayof %W $tkPriv(data)
TCL\tk8.3\entry.tcl(45): clipboard clear -displayof %W
TCL\tk8.3\entry.tcl(46): clipboard append -displayof %W $tkPriv(data)
TCL\tk8.3\entry.tcl(58): %W insert insert [selection get -displayof %W -selection CLIPBOARD]
TCL\tk8.3\listbox.tcl(140): clipboard clear -displayof %W
TCL\tk8.3\listbox.tcl(141): clipboard append -displayof %W [selection get -displayof %W]
TCL\tk8.3\text.tcl(935): # clipboard.
TCL\tk8.3\text.tcl(942): clipboard clear -displayof $w
TCL\tk8.3\text.tcl(943): clipboard append -displayof $w $data
TCL\tk8.3\text.tcl(949): # clipboard, then deletes the selection (if it exists in the given
TCL\tk8.3\text.tcl(957): clipboard clear -displayof $w
TCL\tk8.3\text.tcl(958): clipboard append -displayof $w $data
TCL\tk8.3\text.tcl(964): # This procedure pastes the contents of the clipboard to the insertion
TCL\tk8.3\text.tcl(978): $w insert insert [selection get -displayof $w -selection CLIPBOARD]
Found 39 occurrence(s) in 7 file(s)
--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Get clipboard pasted into script?

Post by LeviFiction »

That's the hardest part about this, your version is so much older. I keep neglecting to verify how older versions accessed information.

So in the script replace this line

Code: Select all

text = r.clipboard_get()
with

Code: Select all

text = r.selection_get(selection='CLIPBOARD')
Here is the full code again if you just want to do a fully copy and paste.

Code: Select all

from JascApp import *
from Tkinter import Tk

def ScriptProperties():
    return {
        'Author': u'Terry Pinnell',
        'Copyright': u'',
        'Description': u'',
        'Host': u'Paint Shop Pro',
        'Host Version': u'8.10'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
           
            })

    # Text
    App.Do( Environment, 'Text', {
            'CreateAs': App.Constants.CreateAs.Vector,
            'Segments': [{
                'Bold': App.Constants.Boolean.true,
                'Fill': {
                    'Color': (0,0,0),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    },
                'Font': u'Arial',
                'LineStyle': {
                    'Name': u'',
                    'FirstCap': (u'Butt',0.25,0.25),
                    'LastCap': (u'Butt',0.25,0.25),
                    'FirstSegCap': (u'',0.25),
                    'LastSegCap': (u'',0.25),
                    'UseSegmentCaps': App.Constants.Boolean.false,
                    'Segments': []
                    },
                'LineWidth': 0,
                'PointSize': 18,
                'SetText': App.Constants.Justify.Center,
                'Start': (17.5,175.5),
                'Stroke': {
                    'Color': (255,255,220),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    }
                },{
                'Antialias': App.Constants.Boolean.true,
                'WarpText': App.Constants.Boolean.true,
                'AutoKern': App.Constants.Boolean.true,
                'Bold': App.Constants.Boolean.true,
                'Kerning': 0,
                'Leading': 0,
                'Fill': {
                    'Color': (0,0,0),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    },
                'Font': u'Arial',
                'Italic': App.Constants.Boolean.false,
                'Join': App.Constants.JointStyle.Miter,
                'LineStyle': {
                    'Name': u'',
                    'FirstCap': (u'Butt',0.25,0.25),
                    'LastCap': (u'Butt',0.25,0.25),
                    'FirstSegCap': (u'',0.25),
                    'LastSegCap': (u'',0.25),
                    'UseSegmentCaps': App.Constants.Boolean.false,
                    'Segments': []
                    },
                'LineWidth': 0,
                'MiterLimit': 10,
                'PointSize': 18,
                'SetText': App.Constants.Justify.Left,
                'Start': (17.5,175.5),
                'Strikethru': App.Constants.Boolean.false,
                'Stroke': {
                    'Color': (255,255,220),
                    'Pattern': None,
                    'Gradient': None,
                    'Texture': None,
                    'Identity': u'Material'
                    },
                'Underline': App.Constants.Boolean.false
                },{
                'Characters': getText()
                }],
            'SavedText': None,
            'FinalApply': App.Constants.Boolean.false,
            'Matrix': None,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
           
def getText():
    r = Tk()
    text = r.selection_get(selection='CLIPBOARD')
    r.withdraw()
    r.update()
    r.destroy()
    return text
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Get clipboard pasted into script?

Post by terrypin »

Thanks, LeviFiction, you're a star! :)

I now need to experiment extensively to see if I can adapt it. My immediate aim is to be able to run a version of it when the text box is already open, to paste the current clipboard contents.

BTW, my first couple of attempts running the new script produced some very weird effects. Wasn't able to capture screenshots but I had empty little 'Tk' windows appearing, mouse cursor unable to move to tray, PSP8 freezing, etc. But I closed down and restarted and subsequent runs have been flawless. I suppose it was some obscure conflict, maybe with my macro program. If it happens again I'll try capturing and report back.

Please see also my more general post about pasting scripts from here.

Much appreciate all your help.

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Get clipboard pasted into script?

Post by terrypin »

I have meanwhile been handling the text aspects of my project using my macro approach, although it was hard work.

Some context background might be useful/interesting for you - especially as I suspect I'll be back for more help!

My starting point is to display a walk/hike/track in my mapping program, Memory Map, where the profile looks like this, as you saw earlier:

https://dl.dropboxusercontent.com/u/401 ... iginal.jpg

The macro is written with Macro Express Pro, the closest I've been to programming for a decade or three (apart briefly with Excel VBA about 15 years ago). It captures that original profile image and pastes it into PSP8. I then apply your brilliant script and some of my own, giving an intermediate result with extra top and bottom borders and the solid colours changed to gradients. (I'll make another attempt later to combine all these now that I'm getting more confident.)

Those and other later scripts are started from within the macro. Over the last couple of days I've developed a way of doing it using a sub-macro which opens PSP8's Run Script browser dialog followed by a specific sub-macro that runs the script required at that point in the task.

If curious, you can get the drift from these screenshots:
https://dl.dropboxusercontent.com/u/401 ... cripts.jpg
https://dl.dropboxusercontent.com/u/401 ... iptRun.jpg
https://dl.dropboxusercontent.com/u/401 ... ptOpen.jpg
https://dl.dropboxusercontent.com/u/401 ... cripts.jpg

While initially in Mem-Map, the macro enters into variables the text I want to show on the final image, some automatically, some manual. I was unable to do so via PSP8 scripts (hence my post about clipboard transfer), so that's entirely by the macro. As well as pasting the text it also places it in the correct positions. Allowing also for reversing the direction - as in my current project, in which the walks are broadly east to west.

Here's an example of the result:
https://dl.dropboxusercontent.com/u/401 ... rofile.jpg

This will contribute a few seconds of my video/DVD of that walking holiday. Typically I have 5-20 such walks for each holiday. So potentially there are hundreds to be processed; hence the up-front work to automate much of it.
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
Post Reply