|
| 1 | +''' |
| 2 | +Processing.py reference lookup for Sublimetext 3 |
| 3 | +
|
| 4 | +Based on "chuck_doc_search.py" by |
| 5 | + Dealga McArdle (https://github.com/zeffii), 2013 |
| 6 | +functionality: Opens webbrowser at Processing.py reference for the |
| 7 | + highlighted keyword, if the keyword is valid. |
| 8 | +Processing.py reference: http://py.processing.org/reference |
| 9 | +
|
| 10 | +- Place this .py inside "Data/Packages/User" |
| 11 | +- Add a shortcut to your user keymap file, e.g.; |
| 12 | + { "keys": ["ctrl+shift+]"], "command": "processing_ref_lookup" } |
| 13 | +- To use, make a selection of for examples "ADSR", then press your shortcut |
| 14 | + key(s). |
| 15 | +
|
| 16 | +''' |
| 17 | + |
| 18 | +import sublime |
| 19 | +import sublime_plugin |
| 20 | +import webbrowser |
| 21 | + |
| 22 | +keywords = ['abs', 'acos', 'alpha', 'ambient', 'ambientLight', |
| 23 | + 'applyMatrix', 'arc', 'asin', 'atan2', 'atan', 'background', |
| 24 | + 'beginCamera', 'beginContour', 'beginRaw', 'beginRecord', |
| 25 | + 'beginShape', 'bezier', 'bezierDetail', 'bezierPoint', |
| 26 | + 'bezierTangent', 'bezierVertex', 'binary', 'blend', 'blendMode', |
| 27 | + 'blue', 'Boolean', 'box', 'break', 'brightness', 'BufferedReader', |
| 28 | + 'camera', 'catch', 'ceil', 'class', 'clear', 'color', 'colorMode', |
| 29 | + 'concat', 'constrain', 'continue', 'copy', 'cos', 'createFont', |
| 30 | + 'createGraphics', 'createImage', 'createInput', 'createOutput', |
| 31 | + 'createReader', 'createShape', 'createWriter', 'cursor', 'curve', |
| 32 | + 'curveDetail', 'curvePoint', 'curveTangent', 'curveTightness', |
| 33 | + 'curveVertex', 'day', 'degrees', 'directionalLight', |
| 34 | + 'displayHeight', 'displayWidth', 'dist', 'draw', 'ellipse', |
| 35 | + 'ellipseMode', 'else', 'emissive', 'endCamera', 'endContour', |
| 36 | + 'endRaw', 'endRecord', 'endShape', 'exit', 'exp', 'False', 'fill', |
| 37 | + 'filter', 'float', 'floatconvert', 'floor', 'focused', 'for', |
| 38 | + 'frameCount', 'frameRate', 'frameRate_var', 'frustum', 'get', |
| 39 | + 'green', 'HALF_PI', 'HashMap', 'height', 'hex', 'hour', 'hue', |
| 40 | + 'if', 'image', 'imageMode', 'int', 'int_convert', 'join', |
| 41 | + 'JSONArray', 'JSONObject', 'key', 'keyCode', 'keyPressed_var', |
| 42 | + 'keyPressed', 'keyReleased', 'keyTyped', 'lerp', 'lerpColor', |
| 43 | + 'lightFalloff', 'lights', 'lightSpecular', 'line', 'loadBytes', |
| 44 | + 'loadFont', 'loadImage', 'loadJSONArray', 'loadJSONObject', |
| 45 | + 'loadPixels', 'loadShader', 'loadShape', 'loadStrings', |
| 46 | + 'loadTable', 'loadXML', 'log', 'loop', 'mag', 'map', 'match', |
| 47 | + 'matchAll', 'max', 'millis', 'min', 'minute', 'modelX', 'modelY', |
| 48 | + 'modelZ', 'month', 'mouseButton', 'mouseClicked', 'mouseDragged', |
| 49 | + 'mouseMoved', 'mousePressed', 'mousePressed_var', 'mouseReleased', |
| 50 | + 'mouseWheel', 'mouseX', 'mouseY', 'new', 'nf', 'nfc', 'nfp', |
| 51 | + 'nfs', 'noCursor', 'noFill', 'noise', 'noiseDetail', 'noiseSeed', |
| 52 | + 'noLights', 'noLoop', 'norm', 'normal', 'noSmooth', 'noStroke', |
| 53 | + 'noTint', 'Object', 'ortho', 'parseXML', 'perspective', 'PFont', |
| 54 | + 'PGraphics', 'PI', 'PImage', 'pixels', 'pmouseX', 'pmouseY', |
| 55 | + 'point', 'pointLight', 'popMatrix', 'popStyle', 'pow', 'print', |
| 56 | + 'printArray', 'printCamera', 'println', 'printMatrix', |
| 57 | + 'printProjection', 'PrintWriter', 'PShader', 'PShape', |
| 58 | + 'pushMatrix', 'pushStyle', 'PVector', 'quad', 'quadraticVertex', |
| 59 | + 'QUARTER_PI', 'radians', 'random', 'randomGaussian', 'randomSeed', |
| 60 | + 'rect', 'rectMode', 'red', 'redraw', 'requestImage', |
| 61 | + 'resetMatrix', 'resetShader', 'return', 'reverse', 'rotate', |
| 62 | + 'rotateX', 'rotateY', 'rotateZ', 'round', 'saturation', 'save', |
| 63 | + 'saveBytes', 'saveFrame', 'saveJSONArray', 'saveJSONObject', |
| 64 | + 'saveStream', 'saveStrings', 'saveTable', 'saveXML', 'scale', |
| 65 | + 'screenX', 'screenY', 'screenZ', 'second', 'selectFolder', |
| 66 | + 'selectInput', 'selectOutput', 'set', 'setup', 'shader', 'shape', |
| 67 | + 'shapeMode', 'shearX', 'shearY', 'shininess', 'shorten', 'sin', |
| 68 | + 'size', 'smooth', 'list_sort', 'specular', 'sphere', |
| 69 | + 'sphereDetail', 'splice', 'split', 'splitTokens', 'spotLight', |
| 70 | + 'sq', 'sqrt', 'static', 'strconvert', 'string', 'stroke', |
| 71 | + 'strokeCap', 'strokeJoin', 'strokeWeight', 'super', 'tan', 'TAU', |
| 72 | + 'text', 'textAlign', 'textAscent', 'textDescent', 'textFont', |
| 73 | + 'textLeading', 'textMode', 'textSize', 'texture', 'textureMode', |
| 74 | + 'textureWrap', 'textWidth', 'tint', 'translate', 'triangle', |
| 75 | + 'True', 'TWO_PI', 'unbinary', 'unhex', 'updatePixels', 'vertex', |
| 76 | + 'while', 'width', 'XML', 'year'] |
| 77 | + |
| 78 | +site = 'http://py.processing.org/reference/' |
| 79 | + |
| 80 | + |
| 81 | +def findDoc(target): |
| 82 | + |
| 83 | + for keyword in keywords: |
| 84 | + if target == keyword: |
| 85 | + webbrowser.open(site + keyword + '.html') |
| 86 | + return |
| 87 | + # Methods in our keyword list have an underscore appended, because, |
| 88 | + # on the Processing website, e.g. 'constrain' is 'constrain'. |
| 89 | + elif target == keyword[0:-1]: |
| 90 | + webbrowser.open(site + keyword + '.html') |
| 91 | + return |
| 92 | + |
| 93 | + |
| 94 | +class ProcessingPyRefLookup(sublime_plugin.TextCommand): |
| 95 | + def run(self, edit): |
| 96 | + if not self.enabled(): |
| 97 | + tmsg = 'Please select a keyword' |
| 98 | + sublime.status_message(tmsg) |
| 99 | + return |
| 100 | + |
| 101 | + view = self.view |
| 102 | + sel = view.sel()[0] |
| 103 | + target = view.substr(sel) |
| 104 | + findDoc(target) |
| 105 | + |
| 106 | + def enabled(self): |
| 107 | + '''only allow 1 selection for version 0.1''' |
| 108 | + |
| 109 | + sels = self.view.sel() # lists regions, |
| 110 | + nsels = len(sels) # dir(sels[0]) for methods |
| 111 | + fsel = sels[0] # first selection |
| 112 | + |
| 113 | + if nsels == 1 and not fsel.empty(): |
| 114 | + return True |
0 commit comments