1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 '''Simple plugin provides actions to allow executing macro code in the
22 active buffer. In the future it could be extended to allow recording of
23 macros.
24
25 This plugin provides the following actions:
26 ExecuteActiveBuffer
27 Execute the contents of the active buffer as
28 a python script in the pallavi context.
29 IntearctiveExecuteAction
30 Prompt the user for an action to be executed and
31 invoke it.
32 ExecuteMacro
33 Show a dialog prompting for a macro name.
34 Execute the contents of a file in the pallavi_config/macros
35 directory with that name. Macros should have .py extensions,
36 but these are optional in the macro dialog.
37 InteractiveLoadPlugin
38 Prompt the user for a plugin to load and load it.
39
40 This plugin invokes the following action:
41 RequestUserInput
42 Request action, macro, or plugin name from the user'''
43 from pallavi import EventActionManager
44 import wx, os.path
45
46
48 '''Set up the actions that this plugin provides.'''
49 actions.AddAction(EventActionManager.Action("ExecuteActiveBuffer", ExecuteActive, "Execute Buffer"))
50 actions.AddAction(EventActionManager.Action("InteractiveExecuteAction", ExecuteAction, "Execute Action", "Prompt for an action name to be executed"))
51 actions.AddAction(EventActionManager.Action("ExecuteMacro", ExecuteMacro, "Execute Macro", "Prompt for a macro file name and execute it"))
52 actions.AddAction(EventActionManager.Action("InteractiveLoadPlugin", InteractiveLoadPlugin, "Load Plugin", "Prompt for a plugin name to be loaded"))
53
55 '''Execute the active buffer as a macro in the Pallavi context'''
56 pluginManager.ExecString(pallavi.focusedView.focusedTextView.GetText())
57
59 '''Interactively prompt for an action to be executed and execute it'''
60 def actionCallback(action):
61 if action != None: actions.Invoke(action)
62 actions.Invoke("RequestUserInput", "Execute Action:", actionCallback)
63
65 '''Execute a Macro by name. Macros are stored in the pallavi_config/macros
66 directory. If data is supplied, consider it a name to execute,
67 otherwise prompt for a macro name to execute'''
68 def macroCallback(macroname):
69 if macroname == None:
70 return
71 if not macroname.endswith(".py"):
72 macroname = macroname + ".py"
73
74 macrofilename = os.path.join(config.config_dir, "macros/%s" % macroname)
75 if os.path.exists(macrofilename):
76 macrofile = open(macrofilename, "r")
77 macro = macrofile.read()
78 macrofile.close()
79 pluginManager.ExecString(macro)
80
81
82 if data == None:
83 actions.Invoke("RequestUserInput", "Execute Macro:", macroCallback)
84 else:
85 macrocallback(data)
86
88 '''Prompt the user for a plugin to load and load it.'''
89 def pluginCallback(plugin):
90 if plugin != None: pluginManager.LoadPlugin(plugin)
91 actions.Invoke("RequestUserInput", "Load Plugin:", pluginCallback)
92