-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-pdb-stubs.py
87 lines (70 loc) · 2.42 KB
/
generate-pdb-stubs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
"""GIMP plug-in that provides a convenience wrapper for invoking GIMP PDB
procedures and generates stubs for PDB procedures to allow displaying code
completion suggestions in IDEs."""
import inspect
import os
import sys
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
from gi.repository import GObject
import stubgen
current_script_dirpath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sys.path.append(os.path.dirname(current_script_dirpath))
from wrappers import procedure
def generate_pdb_stubs(proc, config, _data):
run_mode = config.get_property('run-mode')
if run_mode == Gimp.RunMode.INTERACTIVE:
GimpUi.init('generate-pdb-stubs')
dialog = GimpUi.ProcedureDialog(procedure=proc, config=config, title=None)
dialog.fill(['output-dirpath'])
is_ok_pressed = dialog.run()
if is_ok_pressed:
dialog.destroy()
else:
dialog.destroy()
return Gimp.PDBStatusType.CANCEL
output_dirpath = config.get_property('output-dirpath')
if not output_dirpath:
output_dirpath = stubgen.MODULE_DIRPATH
stubgen.generate_pdb_stubs(output_dirpath)
return Gimp.PDBStatusType.SUCCESS
procedure.register_procedure(
generate_pdb_stubs,
procedure_type=Gimp.Procedure,
arguments=[
[
'enum',
'run-mode',
'Run mode',
'The run mode',
Gimp.RunMode,
Gimp.RunMode.NONINTERACTIVE,
GObject.ParamFlags.READWRITE,
],
[
'string',
'output-dirpath',
'Output _directory path',
f'Output directory path (default: "{stubgen.MODULE_DIRPATH}")',
stubgen.MODULE_DIRPATH,
GObject.ParamFlags.READWRITE,
],
],
menu_label='Generate GIMP PDB Stubs for Python',
menu_path='<Image>/Filters/Development/Python-Fu',
documentation=(
('Generates a stub file for the GIMP procedural database (PDB) for Python plug-ins'
f' named "{stubgen.PYPDB_MODULE_NAME}.pyi".'),
(f'The "{stubgen.PYPDB_MODULE_NAME}.py" file provides a convenience wrapper'
' to simplify calls to GIMP PDB procedures from Python plug-ins.'
f' The generated "{stubgen.PYPDB_MODULE_NAME}.pyi" stub file can then be used'
' in integrated development environments (IDEs) to display code completion suggestions'
' for GIMP PDB procedures.'),
),
attribution=('Kamil Burda', '', '2023'),
)
procedure.main()