├── README
├── doc
├── NEWS
├── TODO
├── UserManual.html
├── UserManual.txt
└── posting
├── gimpscripter
├── __init__.py
├── constantmaps.py
├── generate.py
├── gui
│ ├── __init__.py
│ ├── gimpscripter.glade
│ ├── main_gui.py
│ ├── param_dialog.py
│ └── param_widgets.py
├── macros.py
├── mockmenu
│ ├── __init__.py
│ ├── db_treemodel.py
│ ├── map_procedures.py
│ ├── path_treemodel.py
│ └── plugindb.py
├── parameters.py
├── parse_params.py
├── runtime.py
├── specification.py
└── template.py
└── plugin-gimpscripter.py
/README:
--------------------------------------------------------------------------------
1 | About Gimpscripter
2 | ==================
3 |
4 | Gimpscripter is a new version of the "Make Shortcut" plugin, now called "GimpScripter". It lets you point-and-click create a Gimp plugin that calls a sequence of plugins, PDB procedures, or macros. It is a plugin authoring tool.
5 |
6 | Gimpscripter is a Gimp plugin written in Python. It generates Python code for a Gimp plugin.
7 |
8 | The source is at github.com/bootchk/gimpscripter. Installation instruction are in the README file. The source includes many readable documents such as NEWS, TODO, and a usermanual.
9 |
10 | Gimpscripter is still in development. It works usually, but is incomplete and could be improved.
11 |
12 | Take a look if you are interested in scripting Gimp, as a user or as a programmer.
13 |
14 | Gimpscripter lets you visually (graphically, point-and-click) implement a sequential recipe, for example "Choose this, set that parameter, choose that, ..". It doesn't have any control flow statements.
15 |
16 | It uses a stack model of computation: it hides a prefix of parameters and references them to active objects.
17 |
18 | It includes a macro facility and macros for common sequences of operations, and to wrap certain PDB procedures with higher-level parameter type, e.g. PF_BRUSH instead of PF_STRING for a brush.
19 |
20 | Some people suggest using a recorder/playback tool to automate Gimp. Scripts from such tools break when the Gimp GUI changes, and the scripts are not easily distributable. Gimpscripter is an alternative.
21 |
22 | Gimpscripter does have many weaknesses, some of which can be attributed to lack of support from the PDB. So it could help guide improvements to the PDB (but it might not raise any issues not already known, such as not storing defaults.)
23 |
24 | I would welcome comments or contributions.
25 |
26 | Installation
27 | ============
28 |
29 | Instructions for typical installation on Linux, with Gimp version 2.6:
30 |
31 | cp plugin-gimpscripter.py ~/.gimp-2.6/plug-ins (user's local directory)
32 | chmod +x ~/.gimp-2.6/plug-ins/plugin-gimpscripter.py (make it executable)
33 | cp -r gimpscripter ~/.gimp-2.6/plug-ins (copy gimpscripter directory comprising .glade and .py files)
34 |
--------------------------------------------------------------------------------
/doc/NEWS:
--------------------------------------------------------------------------------
1 | NEWS
2 | ====
3 |
4 | This is the new version of the "Make Shortcut" plugin for Gimp. It is now called "Gimpscripter." It lets you point-and-click to create a plugin that calls a sequence of other plugins or PDB procedures or macros (common sequences of calls.)
5 |
6 | The differences from the prior version:
7 |
8 | - a sequence of calls instead of just one call
9 | - call any PDB procedure, not just plugins
10 | - call macros that more closely match Gimp menu semantics than the PDB does
11 | (e.g. Channel/New, which also attaches the channel)
12 | - call macros for common sequences (e.g. Display/New, also flushes)
13 | - call macros that better define parameter types (e.g. Context/Set/Choose brush)
14 | - lets you enter parameters for the called procedures
15 | - OR lets you defer parameters for called procedures until runtime
16 |
17 | See the TODO file for deficiencies.
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/doc/TODO:
--------------------------------------------------------------------------------
1 | TODO
2 | ====
3 |
4 | Here are some of the deficiencies:
5 |
6 | - defaults for settings are lame (because the PDB does not keep them)
7 | - range checking for settings is non-existent (because the PDB does not keep them)
8 | - mock menu items are missing (file map_procedures.py is incomplete)
9 | - macros are missing (file macros.py is incomplete)
10 | - the GUI could be more user friendly
11 | - the look and feel should match the Gimp style and might need to use the user's theme
12 | - should allow user to insert and remove commands from a sequence
13 | - should allow user to enter the blurb for a wrapper plugin
14 | - lightly tested. Testing should be automated.
15 | - let user choose a menu for the wrapper, not just "Shortcut>"
16 | - check the return value of wrapped procedures and raise, if error returns can be determined
17 | - substitute our own blurb for mockmenu items that have new semantics via the GS stack model
18 |
19 | These are some Gimp quirks that macros address, and that might go away:
20 | - the floating selection
21 | - creating layers that are not attached to an image
22 | - inconvenient (for users) parameter units, such as pixels instead of percent for scaling
23 | - declared type of parameters for many procedures is too generic, e.g. string for brush
24 |
--------------------------------------------------------------------------------
/doc/UserManual.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
308 |
GimpScripter User's Manual
309 |
310 |
Copyright 2010, 2011 Lloyd Konneker.
311 | This is part of the GimpScripter User's Manual.
312 | It is licensed under the GNU Free Documentation License, Version 1.3, 3 November 2008.
313 | See the file COPYING for copying conditions.
314 |
315 |
About GimpScripter
316 |
GimpScripter is an authoring tool for Gimp plugins. It is point-and-click. It lets non-programmers author plugins. You DO need to understand Gimp and the Gimp Programmer's Data Base (PDB.) Gimpscripter itself is a Gimp plugin.
317 |
It succeeds the earlier plugin called "Make Shortcut". It lets a shortcut call a sequence of procedures, instead of just one.
318 |
GimpScripter is open source software written in the Python language. It generates a plugin in the Python language. But you don't need to understand Python to use GimpScripter.
319 |
GimpScripter is a prototype or beta version. It works, but has rough edges.
320 |
321 |
322 |
Quick Start
323 |
Start Gimp and choose "Filters/Gimpscripter...". A new window opens, having three panes.
324 |
The left pane is a mockup of a cascading menu. Manipulate the menu until you see a terminal menu item. Click on the menu item. That puts the menu item, representing a command, into the middle pane. The middle pane is a list (sequence) of the commands you have chosen.
325 |
The right pane shows you the parameters or settings of the command. For now, don't change the settings.
326 |
Enter a name, for example "Foo", in the textbox labeled "Shortcut name".
327 |
Choose the OK button. The window closes and an informational dialog opens to show a summary of the plugin you have created. Choose the OK button.
328 |
Now close Gimp and restart it. You will see a new menu called "Shortcuts" with item "Foo." That is the plugin you just created.
329 |
Open an image and choose "Shortcuts/Foo". You won't see any dialog since in the settings pane you left all parameters as constants to your plugin. But your plugin "Foo" should perform the command you chose earlier. You might not be able to see the results, depending on the command you chose.
330 |
In general, you would choose a sequence of many commands, and change settings for commands, before choosing OK to create a shortcut.
331 |
332 |
333 |
Why GimpScripter?
334 |
It lets you:
335 |
336 | - automate common sequences of Gimp operations
337 | - package a sequence so you can call it from a batch processor
338 | - simplify plugins by making some of their parameters constants
339 | - alias plugins, giving them a more memorable name
340 |
341 |
342 |
343 |
Terminology
344 |
Wrapper: the plugin you author using GimpScripter.
345 |
Commands: procedures in a sequence. They can be:
346 |
347 | - plugins
348 | - Gimp internal procedures
349 | - macros.
350 |
351 |
Plugins and internal procedures are defined in the PDB. Macros are defined within GimpScripter. Macros are sequences of calls to the PDB.
352 |
You: the author, a user of GimpScripter
353 |
The user: someone using the wrapper you create with GimpScripter
354 |
Mock menu: the menu on the "Menu" pane. It resembles the Gimp menus.
355 |
Runtime: when the user choses your wrapper from Gimp.
356 |
PDB: the Gimp Programmers Data Base.
357 |
358 |
359 |
Choosing a Sequence
360 |
You click on a cascading menu on the left. When you click on a command, it is appended to the sequence shown in the middle pane and its parameters are shown in the right pane. You can enter the parameters when you first choose a command, or later.
361 |
(For now, there is no "Remove", you just start over. There is also no "Insert": a new command is always appended at the end.)
362 |
Mouseover or hover (tooltips) on a menu item shows you the 'blurb' or description of the command.
363 |
364 |
365 |
Using the Settings Pane
366 |
The settings shown in the right pane are for one command, the command that is selected in either the left pane (the mock menu) or in the middle pane (the command sequence.)
367 |
When you first choose a command, you see its settings in the right pane. You can change the settings then, or revisit them later.
368 |
(Future: if the command is a plugin, you can choose to ignore the settings and run the plugin with its most recent values at runtime.)
369 |
370 |
Revisiting Settings
371 |
To revisit settings for a command, select the command in the middle pane. The command's settings will appear in the right pane, with any values you entered earlier. You don't need to "Save" any settings you change. Whenever you revisit, you will see any changes you made earlier.
372 |
373 |
374 |
Validity Checking
375 |
Gimpscripter understands the valid type (for example, integer) for settings, and checks them as you enter them. But Gimpscripter does NOT understand the valid ranges for settings (for example, the smallest and largest acceptable values). Unfortunately, those valid ranges are not readily accessible from the PDB.
376 |
377 |
378 |
Initial Values For Settings
379 |
When you first see settings for a command, the initial values are arbitrary values. The arbitrary initial values are valid for the type of each setting. But they are NOT what you might know as the default values for the settings. Unfortunately, those default values are not readily accessible from the PDB.
380 |
381 |
382 |
Constant Settings
383 |
All settings start as "constants." The value you enter will be the value used at runtime and the user won't have a choice.
384 |
385 |
386 |
Deferred Settings
387 |
When you uncheck the "Constant" checkbox, you 'defer' a setting: the user will be able to change the setting at runtime, in a dialog as the wrapper starts. The value you enter will be what the user sees as the default in the dialog. All settings you defer will appear together in a single dialog at runtime, for the user to change.
388 |
389 |
390 |
Hidden Settings
391 |
Most commands have implied operands: the active image, layer, channel, or path. See "The Stack." These operands (parameters) are defined in the PDB but GimpScript hides them from you, the GimpScripter author, and hides them from a user.
392 |
Note that hidden settings are images, layers, or channels, but not all settings that are images, layers, or channels are hidden: any parameter of a PDB procedure that is of type image, layer, or channel and that is the second parameter of that type in the procedure, is NOT hidden.
393 |
394 |
395 |
396 |
The Stack
397 |
GimpScripter uses a stack model of computation. Each command operates on active objects, that is, the top of a set of stacks. A command that creates an object makes it active (pushes it onto a stack.) A command that removes an object makes a new object active, the object that was previously active. In other words, it pops a stack. When you choose a sequence of commands, you must consider how they will work together on a set of stacks.
398 |
There are separate stacks for images, drawable, layers, and channels. The top of the stack of drawables is either a layer or a channel, whatever was most recently created.
399 |
GimpScripter hides the parameters (settings) of commands that read or affect the stacks. That is, you won't see those parameters on the "Settings" pane.
400 |
When a wrapper starts, the active image and drawable in Gimp are on the GimpScripter stacks. (For now, you can't create a wrapper that doesn't require an open image.)
401 |
When a wrapper ends, it may have changed the active image and drawable that Gimp considers active. The top of the GimpScripter stacks will be active. You might need to include delete or remove commands in your wrapper sequence.
402 |
403 |
404 |
Macros
405 |
Some commands that you can choose from the mock menus are macros implemented in GimpScripter. A macro is a sequence of PDB procedure calls. These macros simplify common but confusing sequences of PDB calls. For example, "Channel/New" calls a macro that creates a channel and adds it to the image (which is almost always what you want.) Just be aware that some items in the mock menu do not directly map to a PDB procedure you might be familiar with (but likely to map to a Gimp menu item you might be familiar with.) The tooltips will alert you to which are macros. For more information, see the comments in the file gimpscripter/macros.py.
406 |
You can write your own macros. See the macros.py file for details. Any macros you write get expanded into wrappers you create, so you don't need to distribute your macro definitions. (More macros are needed for future GimpScripter distributions.)
407 |
408 |
409 |
The Context
410 |
The Gimp context (the active color, brush, pattern, etc.) is NOT part of the GimpScripter stacks. If you change the context, those are not stacked by GimpScripter. You can manage the context by putting commands "Context/Save" and "Context/Restore" in your wrapper sequence.
411 |
412 |
413 |
Practical Sequencing Using Stacks
414 |
You can use named buffers to reshuffle the stack, that is, to get a different object on top of a stack without losing anything on the stack. See the "Edit" commands.
415 |
416 |
417 |
About this Document
418 |
The original of this document is in the restructured text format (ReST). The HTML format is generated by invoking "rst2html UserManual.txt UserManual.html".
419 |
420 |
421 |
422 |
423 |
--------------------------------------------------------------------------------
/doc/UserManual.txt:
--------------------------------------------------------------------------------
1 | GimpScripter User's Manual
2 | ==========================
3 |
4 | Copyright 2010, 2011 Lloyd Konneker.
5 | This is part of the GimpScripter User's Manual.
6 | It is licensed under the GNU Free Documentation License, Version 1.3, 3 November 2008.
7 | See the file COPYING for copying conditions.
8 |
9 | About GimpScripter
10 | ------------------
11 |
12 | GimpScripter is an authoring tool for Gimp plugins. It is point-and-click. It lets non-programmers author plugins. You DO need to understand Gimp and the Gimp Programmer's Data Base (PDB.) Gimpscripter itself is a Gimp plugin.
13 |
14 | It succeeds the earlier plugin called "Make Shortcut". It lets a shortcut call a sequence of procedures, instead of just one.
15 |
16 | GimpScripter is open source software written in the Python language. It generates a plugin in the Python language. But you don't need to understand Python to use GimpScripter.
17 |
18 | GimpScripter is a prototype or beta version. It works, but has rough edges.
19 |
20 |
21 | Quick Start
22 | -----------
23 |
24 | Start Gimp and choose "Filters/Gimpscripter...". A new window opens, having three panes.
25 |
26 | The left pane is a mockup of a cascading menu. Manipulate the menu until you see a terminal menu item. Click on the menu item. That puts the menu item, representing a command, into the middle pane. The middle pane is a list (sequence) of the commands you have chosen.
27 |
28 | The right pane shows you the parameters or settings of the command. For now, don't change the settings.
29 |
30 | Enter a name, for example "Foo", in the textbox labeled "Shortcut name".
31 |
32 | Choose the OK button. The window closes and an informational dialog opens to show a summary of the plugin you have created. Choose the OK button.
33 |
34 | Now close Gimp and restart it. You will see a new menu called "Shortcuts" with item "Foo." That is the plugin you just created.
35 |
36 | Open an image and choose "Shortcuts/Foo". You won't see any dialog since in the settings pane you left all parameters as constants to your plugin. But your plugin "Foo" should perform the command you chose earlier. You might not be able to see the results, depending on the command you chose.
37 |
38 | In general, you would choose a sequence of many commands, and change settings for commands, before choosing OK to create a shortcut.
39 |
40 | Why GimpScripter?
41 | -----------------
42 |
43 | It lets you:
44 |
45 | - automate common sequences of Gimp operations
46 | - package a sequence so you can call it from a batch processor
47 | - simplify plugins by making some of their parameters constants
48 | - alias plugins, giving them a more memorable name
49 |
50 | Terminology
51 | -----------
52 |
53 | Wrapper: the plugin you author using GimpScripter.
54 |
55 | Commands: procedures in a sequence. They can be:
56 |
57 | - plugins
58 | - Gimp internal procedures
59 | - macros.
60 |
61 | Plugins and internal procedures are defined in the PDB. Macros are defined within GimpScripter. Macros are sequences of calls to the PDB.
62 |
63 | You: the author, a user of GimpScripter
64 |
65 | The user: someone using the wrapper you create with GimpScripter
66 |
67 | Mock menu: the menu on the "Menu" pane. It resembles the Gimp menus.
68 |
69 | Runtime: when the user choses your wrapper from Gimp.
70 |
71 | PDB: the Gimp Programmers Data Base.
72 |
73 | Choosing a Sequence
74 | -------------------
75 |
76 | You click on a cascading menu on the left. When you click on a command, it is appended to the sequence shown in the middle pane and its parameters are shown in the right pane. You can enter the parameters when you first choose a command, or later.
77 |
78 | (For now, there is no "Remove", you just start over. There is also no "Insert": a new command is always appended at the end.)
79 |
80 | Mouseover or hover (tooltips) on a menu item shows you the 'blurb' or description of the command.
81 |
82 | Using the Settings Pane
83 | -----------------------
84 |
85 | The settings shown in the right pane are for one command, the command that is selected in either the left pane (the mock menu) or in the middle pane (the command sequence.)
86 |
87 | When you first choose a command, you see its settings in the right pane. You can change the settings then, or revisit them later.
88 |
89 | (Future: if the command is a plugin, you can choose to ignore the settings and run the plugin with its most recent values at runtime.)
90 |
91 | Revisiting Settings
92 | +++++++++++++++++++
93 |
94 | To revisit settings for a command, select the command in the middle pane. The command's settings will appear in the right pane, with any values you entered earlier. You don't need to "Save" any settings you change. Whenever you revisit, you will see any changes you made earlier.
95 |
96 | Validity Checking
97 | +++++++++++++++++
98 |
99 | Gimpscripter understands the valid type (for example, integer) for settings, and checks them as you enter them. But Gimpscripter does NOT understand the valid ranges for settings (for example, the smallest and largest acceptable values). Unfortunately, those valid ranges are not readily accessible from the PDB.
100 |
101 | Initial Values For Settings
102 | +++++++++++++++++++++++++++
103 |
104 | When you first see settings for a command, the initial values are arbitrary values. The arbitrary initial values are valid for the type of each setting. But they are NOT what you might know as the default values for the settings. Unfortunately, those default values are not readily accessible from the PDB.
105 |
106 | Constant Settings
107 | +++++++++++++++++
108 |
109 | All settings start as "constants." The value you enter will be the value used at runtime and the user won't have a choice.
110 |
111 | Deferred Settings
112 | +++++++++++++++++
113 |
114 | When you uncheck the "Constant" checkbox, you 'defer' a setting: the user will be able to change the setting at runtime, in a dialog as the wrapper starts. The value you enter will be what the user sees as the default in the dialog. All settings you defer will appear together in a single dialog at runtime, for the user to change.
115 |
116 | Hidden Settings
117 | +++++++++++++++
118 |
119 | Most commands have implied operands: the active image, layer, channel, or path. See "The Stack." These operands (parameters) are defined in the PDB but GimpScript hides them from you, the GimpScripter author, and hides them from a user.
120 |
121 | Note that hidden settings are images, layers, or channels, but not all settings that are images, layers, or channels are hidden: any parameter of a PDB procedure that is of type image, layer, or channel and that is the second parameter of that type in the procedure, is NOT hidden.
122 |
123 | The Stack
124 | ---------
125 |
126 | GimpScripter uses a stack model of computation. Each command operates on active objects, that is, the top of a set of stacks. A command that creates an object makes it active (pushes it onto a stack.) A command that removes an object makes a new object active, the object that was previously active. In other words, it pops a stack. When you choose a sequence of commands, you must consider how they will work together on a set of stacks.
127 |
128 | There are separate stacks for images, drawable, layers, and channels. The top of the stack of drawables is either a layer or a channel, whatever was most recently created.
129 |
130 | GimpScripter hides the parameters (settings) of commands that read or affect the stacks. That is, you won't see those parameters on the "Settings" pane.
131 |
132 | When a wrapper starts, the active image and drawable in Gimp are on the GimpScripter stacks. (For now, you can't create a wrapper that doesn't require an open image.)
133 |
134 | When a wrapper ends, it may have changed the active image and drawable that Gimp considers active. The top of the GimpScripter stacks will be active. You might need to include delete or remove commands in your wrapper sequence.
135 |
136 |
137 | Macros
138 | ------
139 |
140 | Some commands that you can choose from the mock menus are macros implemented in GimpScripter. A macro is a sequence of PDB procedure calls. These macros simplify common but confusing sequences of PDB calls. For example, "Channel/New" calls a macro that creates a channel and adds it to the image (which is almost always what you want.) Just be aware that some items in the mock menu do not directly map to a PDB procedure you might be familiar with (but likely to map to a Gimp menu item you might be familiar with.) The tooltips will alert you to which are macros. For more information, see the comments in the file gimpscripter/macros.py.
141 |
142 | You can write your own macros. See the macros.py file for details. Any macros you write get expanded into wrappers you create, so you don't need to distribute your macro definitions. (More macros are needed for future GimpScripter distributions.)
143 |
144 | The Context
145 | -----------
146 |
147 | The Gimp context (the active color, brush, pattern, etc.) is NOT part of the GimpScripter stacks. If you change the context, those are not stacked by GimpScripter. You can manage the context by putting commands "Context/Save" and "Context/Restore" in your wrapper sequence.
148 |
149 | Practical Sequencing Using Stacks
150 | ---------------------------------
151 |
152 | You can use named buffers to reshuffle the stack, that is, to get a different object on top of a stack without losing anything on the stack. See the "Edit" commands.
153 |
154 | About this Document
155 | -------------------
156 |
157 | The original of this document is in the restructured text format (ReST). The HTML format is generated by invoking "rst2html UserManual.txt UserManual.html".
158 |
159 |
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/doc/posting:
--------------------------------------------------------------------------------
1 | Announcing a new version of the "Make Shortcut" plugin, now called "GimpScripter". It lets you point-and-click create a plugin that calls a sequence of plugins, PDB procedures, or macros. It is a plugin authoring tool.
2 |
3 | Gimpscripter is a Gimp plugin written in Python. It generates Python code for a plugin.
4 |
5 | The source is at github.com/bootchk/gimpscripter. Installation instruction are in the README file. The source includes many readable documents such as NEWS, TODO, and a user's manual.
6 |
7 | Gimpscripter is still in development. It usually works, but is incomplete and could be improved.
8 |
9 | Take a look if you are interested in scripting Gimp, as a user or as a programmer.
10 |
11 | Gimpscripter lets you visually (graphically, point-and-click) implement a sequential recipe, for example "Choose this, set that parameter, choose that, ..". It doesn't have any control flow statements.
12 |
13 | It uses a stack model: it hides a prefix of parameters and references them to active objects.
14 |
15 | It includes a macro facility and macros for common sequences of operations, and to wrap certain PDB procedures with higher-level parameter type, e.g. PF_BRUSH instead of PF_STRING for a brush.
16 |
17 | Some people suggest using a recorder/playback tool to automate Gimp. Scripts from such tools break when the Gimp GUI changes, and the scripts are not easily distributable. Gimpscripter is an alternative.
18 |
19 | Gimpscripter does have many weaknesses, some of which can be attributed to lack of support from the PDB. So it could help guide improvements to the PDB (but it might not raise any issues not already known, such as not storing defaults.)
20 |
21 | I welcome comments or contributions.
22 |
23 | Here is an example use, to make a plugin "Stroke selection with selection":
24 |
25 | Choose "Filter/Gimpscripter" to start Gimpscripter.
26 | From the menu pane choose "Edit/Copy".
27 | Choose "Edit/Paste as/New Brush".
28 | Choose "Select/To path".
29 | Choose "Edit/Stroke/Path".
30 | Enter a name for the plugin, for example "Stroke selection with selection".
31 | Choose the OK button.
32 | Read the summary and choose the OK button.
33 | Restart Gimp.
34 | Open an image and make a selection.
35 | Choose "Shortcuts/Stroke selection with selection".
36 | You should see a mobius like effect.
37 |
38 |
39 |
--------------------------------------------------------------------------------
/gimpscripter/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/gimpscripter/constantmaps.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | '''
4 | Mappings of constants.
5 | Derived from gimpfu.py.
6 |
7 | Copyright 2010 Lloyd Konneker
8 |
9 | This program is free software; you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation; either version 2 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program; if not, write to the Free Software
21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 | '''
23 | from gimpfu import *
24 |
25 | '''
26 | Here I started an elegant way to create the mapping, but gave up on it.
27 | How do you instantiate a type without knowing what parameters __call__ takes??
28 | _instance_mapping = { }
29 | for (typeconstant, type) in gimpfu._obj_mapping.items():
30 | _instance_mapping[typeconstant] = type.__call__()
31 |
32 | '''
33 |
34 | '''
35 | Map parameter type to don't care instance of that parameter type.
36 | Used for actual values to a plugin call, might be type checked
37 | (not by Python but possibly by Pygimp?)
38 | but ignored because it is RUN_LAST_VAL.
39 | !!! Use None for ephemeral types.
40 | '''
41 | _instance_map = {
42 | PF_INT8 : 0,
43 | PF_INT16 : 0,
44 | PF_INT32 : 0,
45 | PF_FLOAT : 0.0,
46 | PF_STRING : "foo", # At shortcut time: a don't care string (can't be empty.)
47 | PF_COLOR : (0,0,0), # a don't care color
48 | PF_DISPLAY : None,
49 | PF_IMAGE : None,
50 | PF_LAYER : None,
51 | PF_CHANNEL : None,
52 | PF_DRAWABLE : None,
53 | PF_VECTORS : None,
54 | PF_BOOL : True,
55 |
56 | PF_BRUSH : "foo", # TODO the rest of the upconverted types
57 | }
58 |
59 | '''
60 | Map parameter type to default instance of that parameter type.
61 | There is some logic here, 1 is better than 0 as a default for most plugins parameters?
62 | Note this might go away if we can determine the actual defaults for wrapped plugins.
63 | !!! Use common names for ephemeral types, since we are defaulting a string widget.
64 | '''
65 | _default_map = {
66 | PF_INT8 : 1,
67 | PF_INT16 : 1,
68 | PF_INT32 : 1,
69 | PF_FLOAT : 5.0,
70 | PF_STRING : "bar", # At shortcut time: a don't care string (can't be empty.)
71 | PF_COLOR : (37,37,37), # a don't care color
72 | PF_DISPLAY : None, # ???
73 | PF_IMAGE : "Untitled",
74 | PF_LAYER : "Clipboard",
75 | PF_CHANNEL : "Alpha",
76 | PF_DRAWABLE : "Clipboard",
77 | PF_VECTORS : "Path",
78 | PF_BOOL : "True",
79 |
80 | PF_BRUSH : "Circle (05)"
81 | }
82 |
83 |
84 | '''
85 | For hidden parameters, map parameter type to an actual parameter.
86 | Actual parameters are references to stacks of ephemera.
87 | Used to generate a call string.
88 | '''
89 | _hidden_actual_map = {
90 | PF_IMAGE : "ephemera.top(PF_IMAGE)",
91 | PF_DRAWABLE : "ephemera.top(PF_DRAWABLE)",
92 | PF_LAYER : "ephemera.top(PF_LAYER)",
93 | PF_CHANNEL : "ephemera.top(PF_CHANNEL)",
94 | PF_VECTORS : "ephemera.top(PF_VECTORS)",
95 | }
96 |
97 | '''
98 | Map numeric parameter type PDB to name in Python.
99 |
100 | Note, we have lost information: the PDB doesn't know the original types,
101 | that also described the widget for entering it, such as PF_SLIDER for PF_FLOAT.
102 | '''
103 | _type_to_string_map = {
104 | PF_INT8 : "PF_INT8",
105 | PF_INT16 : "PF_INT16",
106 | PF_INT32 : "PF_INT32",
107 | PF_FLOAT : "PF_FLOAT",
108 | PF_STRING : "PF_STRING",
109 | PF_COLOR : "PF_COLOR",
110 | PF_DISPLAY : "PF_DISPLAY",
111 | PF_IMAGE : "PF_IMAGE",
112 | PF_LAYER : "PF_LAYER",
113 | PF_CHANNEL : "PF_CHANNEL",
114 | PF_DRAWABLE : "PF_DRAWABLE",
115 | PF_VECTORS : "PF_VECTORS",
116 | PF_BOOL : "PF_BOOL",
117 |
118 | PF_BRUSH : "PF_BRUSH",
119 | }
120 |
--------------------------------------------------------------------------------
/gimpscripter/generate.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | '''
4 | Crux of generating a wrapping plugin.
5 | Generates another plugin (in Python language) that is a wrapping plugin to a target plugin.
6 | Shortcut means:
7 | 1) alias or link to target plugin
8 | 2) possibly different settings dialog at wrapping plugin runtime:
9 | a) no dialog, use standard or current settings for target plugin.
10 | b) no dialog, use constant settings for target plugin (chosen at creation time)
11 | c) dialog of deferred parameters (deferred and defaulted at creation time.)
12 |
13 | Copyright 2010 Lloyd Konneker
14 |
15 | This program is free software; you can redistribute it and/or modify
16 | it under the terms of the GNU General Public License as published by
17 | the Free Software Foundation; either version 2 of the License, or
18 | (at your option) any later version.
19 |
20 | This program is distributed in the hope that it will be useful,
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 | GNU General Public License for more details.
24 |
25 | You should have received a copy of the GNU General Public License
26 | along with this program; if not, write to the Free Software
27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 | '''
29 |
30 | '''
31 | Terminology:
32 |
33 | Wrapped versus wrapping, target versus wrapping plugin:
34 | This plugin: what you are reading now, that generates code.
35 | Wrapping plugin: plugin code generated by this plugin.
36 | Wrapped plugin: plugin that wrapping plugin calls, iow the target.
37 |
38 | Formal versus actual parameters:
39 | Formal parameters are in a definition
40 | Actual parameters are in a call
41 |
42 | Script-declared versus PDB-declared parameters:
43 | Script-declared: in "parameters" argument of a register() call
44 | PDB-declared: in paramdefs held by PDB
45 | and in formal parameters of a plugin_main()
46 | Hidden parameters: the difference, i.e. prefix of PDB-declared parameters
47 | e.g. "run-mode, image, drawable"
48 | that Pygimp gimpfu module hides from script authors.
49 |
50 | Users:
51 | wrapping-user: a user of a plugin generated by GimpScripter
52 | author-user: a user of GimpScripter to create a plugin
53 |
54 | Definitions:
55 |
56 | Settings versus options versus preferences: all essentially the same thing.
57 | Gimp seems to use "settings" for plugins and "options" for tools.
58 | In most GUI terminology, "options" or "preferences" is used.
59 |
60 | Preset: define initial value of, but still allow changes. Same as default.
61 | Constant: not changeable by wrapping-user. Changeable when you create a wrapping plugin, constant thereafter.
62 | '''
63 |
64 | '''
65 | I tried to simply register an existing plugin under a new menu item.
66 | It doesn't work, disallowed by GIMP, can only register menu at certain times in life of plugin, init etc.
67 | gimp.pdb.gimp_plugin_menu_register("python_fu_impscriptor", "