Sign in to follow this  
NomBot

How to reset / restart a plugin programmatically

Recommended Posts

I'm looking for a way to restart a plugin (as if the user cancelled then reopened it) but without the user actually doing that.

If it's possible, what's the safest way of doing it? In other words, what gets called when 'cancel' is pressed and when the plugin is reopened? 

 

Share this post


Link to post
Share on other sites

 If the plug-in is written using indirect UI,  that really isn't possible. Basically, what you are doing is pressing the reset button on each control.  There is no quick way to do that.  In fact, there is no way to  programmatically change values on the UI while the effect is running. 

 

Now, if you are running your own effect without using indirect UI, you can initialize each of your controls from the values in the token. 

Share this post


Link to post
Share on other sites

Thanks, BoltBait. I guess that explains why trying to change the UI wasn't working for me ...

What I'm trying to do is read from a file then alter the UI based on that.

 

Any tips on doing this while avoiding indirect UI?

Share this post


Link to post
Share on other sites
1 hour ago, NomBot said:

... then alter the UI based on that.

What all are you wanting to change? Just setting the values (or other properties) of different controls?

 

The XmlSerializer in .NET makes this very easy. It automatically generates a properly structured XML file based on your code, making the importing and exporting of plugin settings (values) nearly effortless. Or it could be used for loading presets into a plugin.

 

Is that what you're looking for?

 

1 hour ago, NomBot said:

Any tips on doing this while avoiding indirect UI?

If want to avoid using WinForms, you could try OptionBasedEffects. It gives you a good balance of the customization of WinForms and the abstraction of IndirectUI.

Share this post


Link to post
Share on other sites

hi toe_head2001,

XML serializer is something I need to look into.

 

but this is what I want to do:

1. user enters settings in UI.

2. this is saved to a file.

3. plugin reads the file.

4. plugin alters UI based on the file.(persistent save of UI option)

 

without user restarting the plugin.

 

I can't figure out how to do that...

 

also looked at optionbased, but can it get around the problem? and is there any doc for this other than play it by ear? :/

Edited by NomBot
missed ref

Share this post


Link to post
Share on other sites
19 minutes ago, NomBot said:

1. user enters settings in UI.

2. this is saved to a file.

3. plugin reads the file.

4. plugin alters UI based on the file.(persistent save of UI option)

 

I have no idea why you'd do that, it can be done in WinForms for sure.

 

If you need an example of the XmlSerializer in action, you can take a look at my Tartan plugin. Here's the two commits that added the XmlSerializer import/export functionality.

 

26 minutes ago, NomBot said:

also looked at optionbased, but can it get around the problem? and is there any doc for this other than play it by ear? :/

I'm not sure it could be done with OptionBasedEffects. Maybe it can. There really isn't any documentation for it.

I used it for my Graph Paper plugin, and I just figured out what I needed to as I went along.

Share this post


Link to post
Share on other sites

Toe_head2001,

as a sort of Scot, I read your Tartan, briefly. and it was good coding. and a good plugin.

and I think I'll need to delve into WinForms to do what i want to do, and i'm a c# noob.

 

edit: Looks like what you did there is the way to go. Thanks

 

 

Edited by NomBot

Share this post


Link to post
Share on other sites

just to clarify:

 

           ops = GetOpts(filePath);
            Amount1Control.SetValueDisplayName(Amount1Options.Amount1Option1, ops[1]);

etc. if that makes sense ... doesn't do what I wanted it to do

 

Edited by NomBot

Share this post


Link to post
Share on other sites

Whether a real person changes the UI properties, or you park a FileSystemWatcher on some configuration file which is used to populate the UI properties, it's the same idea. External input changes the property values which causes the effect rendering to begin a new.

 

But yeah you can't do that with IndirectUI because you don't have write access to the properties and their values. Only the UI, and thus the user, has that access.

Share this post


Link to post
Share on other sites

Update:

Good news, OptionBasedEffects can do what I wanted to do (update UI behind-the-scenes etc) ... and I like the look and feel of it better than WinForms.

 

minor snag: can't get the OptionDoubleVectorPan control to work, wondering if anyone has used it in a plugin.

 

OptionDoubleVectorPan(OptionNames.VecPan,optContext,0.5,0.0,1.0,0.5,0.0,1.0),

gives me a System.OverflowException: Overflow error.

Share this post


Link to post
Share on other sites
1 hour ago, NomBot said:

OptionDoubleVectorPan(OptionNames.VecPan,optContext,0.5,0.0,1.0,0.5,0.0,1.0),

gives me a System.OverflowException: Overflow error.

 

It's System.Drawing that is throwing the exception, because it can't draw the Pan's vector lines.

 

Easy fix though. You just need set the StaticBitmapUnderlay property. Then it will have an area in which to draw those lines.

 

 

To set the image as the source selection:

Rectangle selection = this.EnvironmentParameters.GetSelection(this.EnvironmentParameters.SourceSurface.Bounds).GetBoundsInt();


OptionDoubleVectorPan pan = new OptionDoubleVectorPan(OptionNames.Pan, optContext, 0.5, 0.0, 1.0, 0.5, 0.0, 1.0);
pan.StaticBitmapUnderlay = this.EnvironmentParameters.SourceSurface.CreateAliasedBitmap(selection);

or

Rectangle selection = this.EnvironmentParameters.GetSelection(this.EnvironmentParameters.SourceSurface.Bounds).GetBoundsInt();


new OptionDoubleVectorPan(OptionNames.Pan, optContext, 0.5, 0.0, 1.0, 0.5, 0.0, 1.0)
{
	StaticBitmapUnderlay = this.EnvironmentParameters.SourceSurface.CreateAliasedBitmap(new Rectangle(0, 0, 50, 50))
},

 

 

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this