Getting window into a fixed position?

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

Getting window into a fixed position?

Post by terrypin »

I'm trying to troubleshoot a script that used to work fine. It was based almost entirely on generous help from LeviFiction and I'll include it at the end of this post, although I can no longer be sure which lines are my own.

It operates on an image like this:
Image
and when working properly fills ground and sky with two gradients. But now the result looks like this:
Image

I haven't got very far in isolating the cause but I think it must be due to some change in the size and/or position of the image window since the script's initial development. So I'm going to try writing it from scratch, but only after I've understood a fundamental point.
Q: How can I set an image window's size and position to specific values, so that lines like

Code: Select all

Point': (83.625,181.125),

have predictable results?

Earlier steps ensure that the elevation profile always has empty space below its lowest elevation. So there is always a point along the bottom where a fill could be safely applied. Ditto the top.

P.S. As a side issue, I've been using the command

Code: Select all

    exit
to terminate the script at certain points. It gives an error message 'NameError: global name 'exit' is not defined'. Why? And on closing that message it works anyway!

Code: Select all

from JascApp import *

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

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

    # Fill 1
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone green', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (83.625,181.125), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })


    # NormalViewing
    App.Do( Environment, 'NormalViewing', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })


    
    # Fill 2
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone green', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (1303.13,180.625), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })


    # Fill 3
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone green', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (896.75,181.55), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # NormalViewing
    App.Do( Environment, 'NormalViewing', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })




    # Fill 4
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone light blue', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (85.5,36.5), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # Fill 5
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone light blue', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (1302.5,34.5), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

--
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: Getting window into a fixed position?

Post by LeviFiction »

Window size is unimportant, it's image size that's the big deal. Those points refer to specific points on the image. If you can guarantee that the bottom pixel and top pixels will always be separated by that line then you can simply change the Point parameter to an area that each image you load will always have.

For example if you can guarantee that point (1,1) will always be above the line, then you can replace the sky fill Point parameter with (1,1). And if you can always guarantee that the first pixel at the bottom of the image will always be below the line then you can change the ground fills so that their Points are (1, App.TargetDocument.Height-1)

Here are the five fills - and the points where they attempt to match

Fill 1 - 'Point': (83.625,181.125) - Duotone Green - Bottom Left
Fill 2 - 'Point': (1303.13,180.625) - Duotone Green - Bottom Right
Fill 3 - 'Point': (896.75,181.55) - Duotone Green - Bottom Middle
Fill 4 - 'Point': (85.5,36.5) - Duotone Light Blue - Top Left
Fill 5 - 'Point': (1302.5,34.5) - Duotone Light Blue - Top Right

So, you need to have a point that you know will be below the line, contiguously. That's the easiest method. And by using the App.TargetDocument.Height and App.TargetDocument.Width variables you can account for any image size changes that might occur. IF there is just no way to do that reliably then you need to shoehorn it. That means adding space above and below the line and then pinpointing those spots with the fills. Can you upload one of your original images so we can test?
https://levifiction.wordpress.com/
User avatar
Ken Berry
Site Admin
Posts: 22481
Joined: Fri Dec 10, 2004 9:36 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Gigabyte B550M DS3H AC
processor: AMD Ryzen 9 5900X
ram: 32 GB DDR4
Video Card: AMD RX 6600 XT
Hard_Drive_Capacity: 1 TB SSD + 2 TB HDD
Monitor/Display Make & Model: Kogan 32" 4K 3840 x 2160
Corel programs: VS2022; PSP2023; DRAW2021; Painter 2022
Location: Levin, New Zealand

Re: Getting window into a fixed position?

Post by Ken Berry »

I've moved this thread into the Scripting sub-forum since it appears to be more appropriate there.
Ken Berry
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: Getting window into a fixed position?

Post by terrypin »

Ken Berry wrote:I've moved this thread into the Scripting sub-forum since it appears to be more appropriate there.
Sorry, I thought that was where I was posting!
--
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: Getting window into a fixed position?

Post by terrypin »

Thanks Levi. Particularly for straightening me out on the window size/position issue. I'd been wondering how it had ever worked, and that now makes it clear. And explains why I don't need to view the entire profile (with scrolling) before running the script.

After posting I came to the conclusion that much of my code was redundant. I'm still not sure what made me click more than once for each fill, but it was probably before I decided to change the way I made the profile. Previously the y-axis origin was zero (sea-level) but after some coastal walks (in which GPS recorded a few small negative values) it was obvious that I needed a margin. That also removes the possibility that the entire ground area wouldn't get filled with a single click.

My revised code appears to work fine so far.

Code: Select all

from JascApp import *

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

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

    # Fill
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone green', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (9.75,214.25), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # Fill
    App.Do( Environment, 'Fill', {
            'BlendMode': App.Constants.BlendMode.Normal, 
            'MatchMode': App.Constants.MatchMode.RGBValue, 
            'Material': {
                'Color': None, 
                'Pattern': None, 
                'Gradient': {
                    'Name': u'Duotone light blue', 
                    'GradientType': App.Constants.GradientType.Linear, 
                    'Angle': 0, 
                    'RepeatCount': 0, 
                    'RepeatType': App.Constants.RepeatType.Pad, 
                    'ColorStops': None, 
                    'TransparencyStops': [], 
                    'CenterPoint': None, 
                    'FocalPoint': None, 
                    'Invert': App.Constants.Boolean.false
                    }, 
                'Texture': None, 
                'Identity': u'Material'
                }, 
            'UseForground': App.Constants.Boolean.true, 
            'Opacity': 100, 
            'Point': (9.75,9.25), 
            'SampleMerged': App.Constants.Boolean.true, 
            'Tolerance': 20, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # NormalViewing
    App.Do( Environment, 'NormalViewing', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

In case you're curious, here are a few screenshots. This is the start point, made from GPS Utility (using a macro):
https://www.dropbox.com/s/lr4oqoq3q7hfx ... .jpg?raw=1

Several other macros then call scripts (mostly based on your help last year) and the stage reached before the colour change is this:
https://www.dropbox.com/s/7ul6b9kipk6v7 ... .jpg?raw=1

The result of then using the revised code is this:
https://www.dropbox.com/s/48b02pjpf4o3q ... .jpg?raw=1

And the final result after several more macros, most of which run PSP 8 scripts to add text and a simple frame, is this:
https://www.dropbox.com/s/ik6966iz28htd ... .jpg?raw=1

BTW, I've worked in JPG format out of habit, so I expect an improvement could be made in the outline using PNG or BMP, but I think I'll settle for this.
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
Post Reply