Advertisement
danfalck

python.snippets

Feb 19th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 4.58 KB | None | 0 0
  1. snippet #!
  2.     #!/usr/bin/env python
  3.  
  4. snippet imp
  5.     import ${1:module}
  6. # Module Docstring
  7. snippet docs
  8.     '''
  9.     File: ${1:`Filename('$1.py', 'foo.py')`}
  10.     Author: ${2:`g:snips_author`}
  11.     Description: ${3}
  12.     '''
  13. snippet wh
  14.     while ${1:condition}:
  15.         ${2:# code...}
  16. snippet for
  17.     for ${1:needle} in ${2:haystack}:
  18.         ${3:# code...}
  19. # New Class
  20. snippet cl
  21.     class ${1:ClassName}(${2:object}):
  22.         """${3:docstring for $1}"""
  23.         def __init__(self, ${4:arg}):
  24.             ${5:super($1, self).__init__()}
  25.             self.$4 = $4
  26.             ${6}
  27. # New Function
  28. snippet def
  29.     def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
  30.         """${3:docstring for $1}"""
  31.         ${4:pass}
  32. snippet deff
  33.     def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
  34.         ${3}
  35. # New Method
  36. snippet defs
  37.     def ${1:mname}(self, ${2:arg}):
  38.         ${3:pass}
  39. # New Property
  40. snippet property
  41.     def ${1:foo}():
  42.         doc = "${2:The $1 property.}"
  43.         def fget(self):
  44.             ${3:return self._$1}
  45.         def fset(self, value):
  46.             ${4:self._$1 = value}
  47. # Lambda
  48. snippet ld
  49.     ${1:var} = lambda ${2:vars} : ${3:action}
  50. snippet .
  51.     self.
  52. snippet try Try/Except
  53.     try:
  54.         ${1:pass}
  55.     except ${2:Exception}, ${3:e}:
  56.         ${4:raise $3}
  57. snippet try Try/Except/Else
  58.     try:
  59.         ${1:pass}
  60.     except ${2:Exception}, ${3:e}:
  61.         ${4:raise $3}
  62.     else:
  63.         ${5:pass}
  64. snippet try Try/Except/Finally
  65.     try:
  66.         ${1:pass}
  67.     except ${2:Exception}, ${3:e}:
  68.         ${4:raise $3}
  69.     finally:
  70.         ${5:pass}
  71. snippet try Try/Except/Else/Finally
  72.     try:
  73.         ${1:pass}
  74.     except ${2:Exception}, ${3:e}:
  75.         ${4:raise $3}
  76.     else:
  77.         ${5:pass}
  78.     finally:
  79.         ${6:pass}
  80. # if __name__ == '__main__':
  81. snippet ifmain
  82.     if __name__ == '__main__':
  83.         ${1:main()}
  84. # __magic__
  85. snippet _
  86.     __${1:init}__${2}
  87.  
  88. # FreeCAD convienence snippets
  89. # FreeCAD
  90. #sys path to catch FreeCAD libs
  91. snippet isys
  92.     import sys
  93.     sys.path.append("usr/local/lib")
  94. snippet ifc
  95.     import FreeCAD
  96. snippet fc
  97.     FreeCAD
  98. # FreeCADGui
  99. snippet ifgui
  100.     import FreeCADGui as Gui
  101. # selection
  102. snippet sl
  103.     = Gui.Selection.getSelection()
  104. # selectionex
  105. snippet slx
  106.     = Gui.Selection.getSelectionEx()
  107. # Part
  108. snippet ip
  109.     import Part
  110. snippet sh
  111.     Shape
  112. snippet cu
  113.     Curve
  114. snippet ed
  115.     Edge
  116. snippet wi
  117.     Wire
  118. # Base
  119. snippet fb
  120.     from FreeCAD import Base
  121. # Mod
  122. snippet mod
  123.     sys.path.append("/usr/local/Mod/")
  124. # Draft
  125. snippet idf
  126.     import Draft
  127. snippet df
  128.     Draft
  129. # DraftVecUtils
  130. snippet idv
  131.     import DraftVecUtils
  132. snippet dv
  133.     DraftVecUtils
  134. # DraftGeomUtils
  135. snippet idg
  136.     import DraftGeomUtils
  137. snippet dg
  138.     DraftGeomUtils
  139. #parametric properties
  140. snippet obj.
  141.     obj.addProperty("App::Property${1}","${2}","${3}","${4}")
  142.     ${5}
  143. # Drawing Workbench
  144. snippet idw
  145.     import Drawing
  146. snippet dw
  147.     Drawing
  148. # Base.Vector
  149. snippet bv
  150.     Base.Vector(${1},${2},${3})
  151.     ${4}
  152. snippet =bv
  153.     =Base.Vector(${1},${2},${3})
  154.     ${4}
  155. # BoundBox
  156. snippet bb
  157.     BoundBox
  158. snippet bbxM
  159.     BoundBox.XMax
  160. snippet bbxm
  161.     BoundBox.XMin
  162. snippet bbyM
  163.     BoundBox.YMax
  164. snippet bbym
  165.     BoundBox.YMin
  166. snippet bbzM
  167.     BoundBox.ZMax
  168. snippet bbzm
  169.     BoundBox.ZMin
  170. # LGPLv2 license
  171. snippet lic
  172.     #***************************************************************************
  173.     #*                                                                         *
  174.     #*   Copyright (c) 2013 Daniel Falck  <ddfalck@gmail.com>                  *
  175.     #*                                                                         *
  176.     #*   This program is free software; you can redistribute it and/or modify  *
  177.     #*   it under the terms of the GNU Lesser General Public License (LGPL)    *
  178.     #*   as published by the Free Software Foundation; either version 2 of     *
  179.     #*   the License, or (at your option) any later version.                   *
  180.     #*   for detail see the LICENCE text file.                                 *
  181.     #*                                                                         *
  182.     #*   This program is distributed in the hope that it will be useful,       *
  183.     #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  184.     #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  185.     #*   GNU Library General Public License for more details.                  *
  186.     #*                                                                         *
  187.     #*   You should have received a copy of the GNU Library General Public     *
  188.     #*   License along with this program; if not, write to the Free Software   *
  189.     #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
  190.     #*   USA                                                                   *
  191.     #*                                                                         *
  192.     #***************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement