''' Created on Jun 17, 2011 @author: cbrinley Use this file to add your own template variables. Hopefully the way to do it is more or less self evident from these examples Also see <eclipse>/plugins/org.python.pydev.jython_<version>/jysrc for more examples. helpful links for key api info: https://github.com/aptana/Pydev/tree/f742ccc87a78a0dbf5fcd618561b3a91cdfbf5f5/plugins/org.python.pydev/src http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/overview-summary.html ''' import template_helper if False: py_context_type = org.python.pydev.editor.templates.PyContextType def getModuleShortName(context): return context.getModuleName().split(".")[-1] template_helper.AddTemplateVariable(py_context_type, 'module_shortname', 'Short of current module', getModuleShortName)
return False #Default is Python 2 from org.python.pydev.core import IGrammarVersionProvider if context.getGrammarVersion( ) > IGrammarVersionProvider.LATEST_GRAMMAR_PY2_VERSION: return True return False #=============================================================================== # ISO-8601 Dates #=============================================================================== def GetISODate(context): return time.strftime("%Y-%m-%d") template_helper.AddTemplateVariable(py_context_type, 'isodate', 'ISO-8601 Ymd date', GetISODate) def GetISODateString1(context): return time.strftime("%Y-%m-%d %H:%M") template_helper.AddTemplateVariable(py_context_type, 'isodatestr', 'ISO-8601 Ymd HM date', GetISODateString1) def GetISODateString2(context): return time.strftime("%Y-%m-%d %H:%M:%S") template_helper.AddTemplateVariable(py_context_type, 'isodatestr2',
return string2Add #selection.addLine( indentationString + string2Add, stmt.beginLine - 1) #offset = doc.getLineInformation(afterLine + 1).getOffset(); #selection = PySelection(idocument.getDocument(), idocument.getStart()) #offset = doc.getLineInformation(stmt.beginLine).getOffset() #print 'offset is now ',offset #print 'on line number', selection.getLineNumber() #args = NodeUtils.getNodeArgs(stmt) #print 'args are', args #print '.getRepresentationString' , NodeUtils.getRepresentationString(stmt) #print 'full rep string:', NodeUtils.getFullRepresentationString(stmt) #return NodeUtils.getRepresentationString(stmt) # if nothing was found then return null. return "" template_helper.AddTemplateVariable(py_context_type, 'current_method_args', 'Current method Args', GetMethodArg2) def getClassArgs(idocument, selObj, beginLine): ''' This method recieves a selection object and the start and end lines of a class definition. It will then scan through the code looking for class variables. It stuffs the class variables into a list and returns them. :param selObj: The selection object, used to access the document :type selObj: org.python.pydev.core.docutils.PySelection :param beginLine: an integer indicating the first line of the class :type beginLine: integer :param endLine: (Optional) If null then assumes that this is the last class in the module and therefor all subsequent lines
def _CreateSelection(context): ''' Created method so that it can be mocked on tests. ''' selection = context.createPySelection() return selection #=================================================================================================== # GetFile #=================================================================================================== def GetFile(context): return str(context.getEditorFile()).replace('\\', '/') template_helper.AddTemplateVariable(py_context_type, 'file', 'Full path for file', GetFile) #=================================================================================================== # _IsGrammar3 #=================================================================================================== def _IsGrammar3(context): if context is None: return False #Default is Python 2 from org.python.pydev.core import IGrammarVersionProvider if context.getGrammarVersion( ) >= IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_3_0: return True return False
''' Created method so that it can be mocked on tests. ''' from org.python.pydev.core.docutils import PySelection selection = PySelection(context.getDocument(), context.getStart()) return selection #=================================================================================================== # GetFile #=================================================================================================== def GetFile(context): return str(context.getEditorFile()).replace('\\', '/') template_helper.AddTemplateVariable(py_context_type, 'file', 'Full path for file', GetFile) #=================================================================================================== # _IsGrammar3 #=================================================================================================== def _IsGrammar3(context): if context is None: return False #Default is Python 2 from org.python.pydev.core import IGrammarVersionProvider if context.getGrammarVersion( ) >= IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_3_0: return True return False