-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: plugins can have simple dialog and receive current time and selected layer xpath #2996
Conversation
I just realized that it has the Gtk::Entry, and I didn't make any JSON escape for it. So, back to draft. |
@veermetri05 as you are a/the plugin maker, could you please test/evaluate/review this proposal? :) |
Passing data through the command line can easily reach the maximum length limit. For example for Windows this is just 8191 chars. Because you start with selected layers, next you will need additional metadata, etc. |
On Windows it is actually 32767 . I forgot to add this problem in the description ;) Anyway, I'll learn how Synfig creates temp files. |
@ice0 Now I changed to pass the filenames as arguments. |
Yes, but JSON is preferable because it doesn't require manual parsing from Python side.
Anyway, you need some rules to escape data values, so it's better to use some common format. |
@veermetri05, I updated the PR description with a better (and updated) explanation. @ice0 , please read it and tell me your opinion too XD |
@rodolforg , I appreciate the work, it a big first step for creating a better ecosystem for Synfig Plugins. I think it would be good to pass a JSON file.
I think it would be good to keep in standard JSON/XML format. Now, they would be passed as a JSON file Why not just pass everything into one file ?
maybe we can just call it Also I would like to know the reason behind why should the plugin request the current time or selected layers explicitly ? Why not always pass it ? If they don't need it they won't use it. |
Indeed! Lol Sorry, I just made it automatically...
The selected layers was due to processing the canvas tree, that could take a little while, depending on the open document. There is an intention to be able to provide selected parameters, children (library items), and waypoints too. Edit: and because I warn user a layer needs to be selected! |
For warning the user, I think it becomes necessary for the plugin to explicitly state it. |
So, I'll change the attributes ("current_time" and "layers") to be one of these options: Btw, I'll standardize the attribute names with the dictionary keys: |
@veermetri05 ping :) |
I'm okay with the attribute names. |
c6a6b53
to
d4fcb8c
Compare
@veermetri05 then I hope it is done now :) Please test it. |
For now, these data are passed as a single extra argument, in JSON format: - "time" : current time in seconds [floating point number] - "sel_layers" : array of xpath for every layer selected The file plugin.xml now has new elements and attributes: - element "plugin" now supports some metadata elements: - "author" : author name [string] - "release" : release name [translatable string] - "version" : version number [integer] - element "script" now supports some parameters from Studio! Attributes describe if they are required: - "time" : if it requires the current time ["false"/"true"] - "layers" : if it requires the selected layers ["false"/"true"]
Info is passed as JSON (dict of strings) as the 3rd or 4th argument to the script (depending if it needs info about current time and layer selection). The UI file must have the same name as the script file, except by the file extension, that must be ".ui". Synfig Studio will load the widget (container or not) identified as "dialog_contents" (i.e. its ID must be "dialog_contents"). Fields must _named_ (its "name", not its "id") as this will be the dictionary keys.
Now both metadata .xml file (provided by plugin author) and extra argument .json file (provided by Synfig Studio at runtime) use same notation: "current_time" and "selected_layers". In the same way, "canvasState" in json is now "canvas_state". Besides, plugin author can tell Synfig Studio if an extra argument (current_time or selected_layers) is unused, mandatory or optional.
Rebased again. I suggest to squash the commits for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the awesome feature!
it looks awesome! Thanks! |
@pgilfernandez Maybe @veermetri05 make (or adapt) a plugin that uses these new features lol :) Do you want to write a plugin, @pgilfernandez ? |
Thank's for summoning me here. I can't think of any way where I could take advantage of the dialog feature in my previous plugins. But I have some ideas for stroke reveal script and maybe something like a waypoint alignment plugin (still brainstorming). |
@rodolforg well, by now I just want to learn how to do it as I want to first finish the "modern icon theme" (thanks again for your help)... |
@rodolforg @veermetri05 I would like to play a little bit with this dialog feature as I would like to create a plugin to automate text animation. Do you have any demo or simple test to start it with? I read all the documentation but I would prefer to start with something that actually works (even if it does nothing) so that I can continue with it as reference. Thanks! |
insertShapeDemo.zip |
Awesome!! I found just an error in your code that you may want to fix (I don't know how, maybe looking deeper into the code): when you run the plugin but you have no layer selected it crashes Synfig when pressing OK:
Cheers |
I realized that #3178 |
@rodolforg I'm unable to retrieve
I get this error when running the plugin: Here is the whole plugin in case you want to look into it Any idea? |
Plugins can now present to user a simple (not dynamic) configuration dialog and can also get the current state of the canvas (current time and selected layers).
Configuration dialog
The dialog, if provided by the plugin, will be shown every time before the plugin actually runs.
It is static: it will not enable/disable widget according to user interaction, neither validate data unless the widgets themselves perform validation.
How to provide the configuration dialog
Synfig Studio will automatically search for a file in the plugin script folder, with the same filename, except the extension, that must be ".ui".
dialog_contents
".How to get what was set by user on the configuration dialog
If the dialog exists and user presses its OK button, the plugin script will receive, as its second argument, a filename.
If using Python, get it via
sys.argv[2]
.The file contains a JSON dictionary. The dict entry named "dialog" contains a nested dictionary with the data provided/chosen by user. The file may contain extra data, such as the Canvas state, as described in next section.
The "dialog" dictionary is a list of key-value pair, being the key the widget name (not ID) and the value that one provided by user.
Notes:
Example of data file contents
Canvas State
Synfig Studio can now pass the current canvas view state, and the plugin script can request them selectively.
These info are supported:
How to request
The metafile plugin.xml was extended to let plugin author tells Synfig Studio what info it needs.
The
<exec>
element now has two optional attributes:current_time="mandatory"
.selected_layers="optional"
.Both attribute accepts one of three possible values:
Example: If
selected_layers="mandatory"
attribute exists, the user MUST select at least one layer to run the plugin. Otherwise, Synfig Studio will warn user and abort the plugin execution (by not starting it).How to get the data
If any of the canvas state request attribute exists, the plugin script will receive, as its second argument, a filename.
If using Python, get it via
sys.argv[2]
.The file contains a JSON dictionary. The dict entry named "canvas_state" contains a nested dictionary with the requested data. The file may contain extra data, such as the Config Dialog entries, as described in previous section.
The possible keys for "canvas_state" dict are:
Notes:
sif
file. In this case, it will be followed by#
character, to mark the file path end.defs
path.Examples of file contents
Only "time" was requested
Only "layers" was requested, and user only selected one layer before calling the plugin. That layer is in the root canvas, being the second one from bottom to top.
Metadata
Plugin can now provide its author name, release name and version number.
The file
plugin.xml
now has new elements:<plugin>
now supports some metadata child elements:For now, these information do not appear anywhere in the GUI.
They can be used in the future by a plugin manager dialog in Synfig Studio.