Interception of a cancelled interactive command

Moderator: Kathy_9

Interception of a cancelled interactive command

Postby fs999 » Thu Aug 01, 2019 10:12 am

Is it possible to intercept when a user cancels an interactive command ?

In this script I'm adding a layer and calling an external module (Topaz Adjust 5.2).
And I want to remove the layer if the user cancels the external module.

I tried this but it does nothing...

Code: Select all
from PSPApp import *
import PSPUtils

def ScriptProperties():
    return {
        'Author': u'F. Schneider',
        'Copyright': u'\u00A9 2013-19 by F. Schneider',
        'Description': u'Adjust 5.2',
        'Host': u'PaintShop Pro',
        'Host Version': u'16.00'
        }



def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((15,0,0),1)
                }
            })

    # LayerDuplicate
    App.Do( Environment, 'LayerDuplicate', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((17,0,0),1)
                }
            })

    # Layer Properties
    App.Do( Environment, 'LayerProperties', {
            'General': {
                'Opacity': None,
                'Name': u'Topaz Adjust',
                'IsVisible': None,
                'IsTransparencyLocked': None,
                'LinkSet': None,
                'UseHighlight': None,
                'PaletteHighlightColor': None,
                'GroupLink': None,
                'BlendMode': None
                },
            'BlendRanges': None,
            'Path': (0,0,[],False),
            'ArtMediaTexture': None,
            'Effects': None,
            'BrightnessContrast': None,
            'ChannelMixer': None,
            'ColorBalance': None,
            'CurveParams': None,
            'HSL': None,
            'Threshold': None,
            'Levels': None,
            'Posterize': None,
            'Vibrancy': None,
            'Overlay': None,
            'LocalToneMapping': None,
            'Invert': None,
            'HistogramAdjustment': None,
            'FillLightClarity': None,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Default,
                'Version': ((18,0,0),1)
                }
            })

    # Topaz Labs_Topaz Adjust 5
    res = App.Do( Environment, 'Topaz Labs_Topaz Adjust 5', {
               'GeneralSettings': {
                  'ExecutionMode': App.Constants.ExecutionMode.Interactive,
                  'Version': ((15,0,0),1)
                  }
              })

    if res == App.Constants.Boolean.false:
      # DeleteLayer
      App.Do( Environment, 'DeleteLayer', {
              'Path': None,
              'MergeMask': True,
              'WorkingMode': 1,
              'GeneralSettings': {
                  'ExecutionMode': App.Constants.ExecutionMode.Silent,
                  'AutoActionMode': App.Constants.AutoActionMode.Match,
                  'Version': ((21,0,0),1)
                  }
              })


Kind regards
Frederic
User avatar
fs999
 
Posts: 19
Joined: Thu Jul 21, 2011 9:55 pm
operating_system: Windows 10
System_Drive: Z
32bit or 64bit: 64 Bit
motherboard: Intel
processor: i7 860
ram: 32GB
Video Card: NVIDIA GeForce GTX 730
sound_card: Samsung HDMI
Hard_Drive_Capacity: 28 TB
Monitor/Display Make & Model: Philips 24P4 & Samsung UE46M6050
Corel programs: PaintShop 2019 Ultimate

Re: Interception of a cancelled interactive command

Postby LeviFiction » Thu Aug 01, 2019 3:10 pm

I do not know of a way to catch PSP canceling a command. Usually, when a user hits cancel they are canceling the full execution of the script. Not just a single command. PSP catches the cancel command and asks if the user wants to quit execution of the script, but I don't know of any situation where we can see when that happens as it seems to happen outside the script.

I don't know offhand if it's possible to check the history to see if the plugin executed. Would have to consult the API.

I do have a somewhat wonky way to check if an image has been changed at all. You use "Count Image Colors."

How you use this command depends on the end result of someone's edits. For example, if you're creating a blank layer and a plugin is creating brand new data such as perlin noise plugin or a gradient maker. Something like that. Then you hide all layers except the blank layer. After the plugin executes you run "Count Image Colors" if the value is 0 then the layer is still blank. You can delete it.

The other option is if you're editing a layer with a plugin. In this case I'm assuming you're duplicating the current layer and you want to check if the layer has been edited.

What you do is first hide all but the current layer, then duplicate the layer, set the new layer to a blend mode of "Difference" and then after the plugin executes count the image colors. If the image colors are 1, then no change has been made. A color count of 1 means that everything is black (no difference). There is of course an obviously gigantic flaw in this. Difference is not simple subtraction. So it is possible that if you're using solid colors, you'll end up with a color count of 1. But in the case of using plugins I find this likely hood to be exeedingly rare.

Also, Count Image Colors should be run silently, just check the return value.

Code: Select all
from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'LeviFiction',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'21.00'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((21,0,0),1),
                'PreviewMode': 1,
                'ScreenControl': 1
                }
            })

    # LayerViewCurrentOnly
    App.Do( Environment, 'LayerViewCurrentOnly', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((9,0,0),1),
                }
            })

    # LayerDuplicate
    App.Do( Environment, 'LayerDuplicate', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((9,0,0),1),
                }
            })

    # MultiObjectProperties
    App.Do( Environment, 'MultiObjectProperties', {
            'General': {
                'Opacity': None,
                'Name': None,
                'IsVisible': None,
                'IsTransparencyLocked': None,
                'LinkSet': None,
                'UseHighlight': None,
                'PaletteHighlightColor': None,
                'GroupLink': None,
                'BlendMode': App.Constants.BlendMode.Difference
                },
            'Effects': None,
            'WorkingMode': 1,
            'Path': None,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
                'Version': ((9,0,0),1),
                }
            })

    # Mehdi_Gradient Smithy 1.1
    App.Do( Environment, 'Mehdi_Gradient Smithy 1.1', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Interactive,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((9,0,0),1),
                },
            'DefaultProperties': []
            })

    # CountImageColors
    count = App.Do( Environment, 'CountImageColors', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((9,0,0),1),
                }
            })
    #If count is > 1 then the layer has been edited, don't delete it
    if count > 1:
        print "Don't delete the layer"
    else:
        print "Delete the layer"
LeviFiction
Advisor
 
Posts: 5631
Joined: Thu Oct 02, 2008 1:07 pm
Location: USA
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PSP: 8, 9, X, XI, X2, X8,X9, 2018, 2019

Re: Interception of a cancelled interactive command

Postby fs999 » Fri Aug 02, 2019 4:19 pm

Thank you very much. I will try that !
User avatar
fs999
 
Posts: 19
Joined: Thu Jul 21, 2011 9:55 pm
operating_system: Windows 10
System_Drive: Z
32bit or 64bit: 64 Bit
motherboard: Intel
processor: i7 860
ram: 32GB
Video Card: NVIDIA GeForce GTX 730
sound_card: Samsung HDMI
Hard_Drive_Capacity: 28 TB
Monitor/Display Make & Model: Philips 24P4 & Samsung UE46M6050
Corel programs: PaintShop 2019 Ultimate


Return to PSP Scripting

Who is online

Users browsing this forum: No registered users and 1 guest