Package pallavi :: Package plugins :: Module Macros
[hide private]
[frames] | no frames]

Source Code for Module pallavi.plugins.Macros

 1  # Copyright (c) 2006 Dusty Phillips 
 2   
 3  # Permission is hereby granted, free of charge, to any person obtaining a 
 4  # copy of this software and associated documentation files (the "Software"), 
 5  # to deal in the Software without restriction, including without limitation 
 6  # the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 7  # and/or sell copies of the Software, and to permit persons to whom the 
 8  # Software is furnished to do so, subject to the following conditions: 
 9   
10  # The above copyright notice and this permission notice shall be included in 
11  # all copies or substantial portions of the Software. 
12   
13  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
14  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
15  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
16  # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
17  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
18  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
19  # DEALINGS IN THE SOFTWARE. 
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   
47 -def setup():
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
54 -def ExecuteActive(data=None):
55 '''Execute the active buffer as a macro in the Pallavi context''' 56 pluginManager.ExecString(pallavi.focusedView.focusedTextView.GetText())
57
58 -def ExecuteAction(data=None):
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
64 -def ExecuteMacro(data=None):
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
87 -def InteractiveLoadPlugin(data = None):
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