Best JavaScript code snippet using ng-mocks
jquery.wipetouch.js
Source:jquery.wipetouch.js
1// jQuery WipeTouch 1.2.02// ------------------------------------------------------------------------3//4// Developed and maintained by Igor Ramadas5// http://aboutigor.com6// http://devv.com7//8// USAGE9// ------------------------------------------------------------------------10//11// $(selector).wipetouch(config);12//13// The wipe events should expect the result object with the following properties:14// speed - the wipe speed from 1 to 515// x - how many pixels moved on the horizontal axis16// y - how many pixels moved on the vertical axis17// source - the element which triggered the wipe gesture18//19// EXAMPLE20// $(document).wipetouch({21// allowDiagonal: true,22// wipeLeft: function(result) { alert("Left on speed " + result.speed) },23// wipeTopLeft: function(result) { alert("Top left on speed " + result.speed) },24// wipeBottomLeft: function(result) { alert("Bottom left on speed " + result.speed) }25// });26//27//28// More details at http://wipetouch.codeplex.com/29//30// CHANGE LOG31// ------------------------------------------------------------------------32// 1.2.033// - New: wipeMove event, triggered while moving the mouse/finger.34// - New: added "source" to the result object.35// - Bug fix: sometimes vertical wipe events would not trigger correctly.36// - Bug fix: improved tapToClick handler.37// - General code refactoring.38// - Windows Phone 7 is not supported, yet! Its behaviour is completely broken and would require some special tricks to make it work. Maybe in the future...39//40// 1.1.041// - New: tapToClick, if true will identify taps and and trigger a click on the touched element. Default is false.42// - Changed: events wipeBottom*** and wipeTop*** renamed to wipeDown*** and wipeUp***.43// - Changed: better touch speed calculation (was always too fast before).44// - Changed: speed will be an integer now (instead of float).45// - Changed: better wipe detection (if Y movement is more than X, do a vertical wipe instead of horizontal).46// - Bug fix: added preventDefault to touchStart and touchEnd internal events (this was missing).47// - Other general tweaks to the code.48//49// The minified version of WipeTouch can be generated using Jasc: http://jasc.codeplex.com50(function ($) {51 $.fn.wipetouch = function (settings) {52 // ------------------------------------------------------------------------53 // PLUGIN SETTINGS54 // ------------------------------------------------------------------------55 var config = {56 // Variables and options57 moveX: 40, // minimum amount of horizontal pixels to trigger a wipe event58 moveY: 40, // minimum amount of vertical pixels to trigger a wipe event59 tapToClick: false, // if user taps the screen it will fire a click event on the touched element60 preventDefault: true, // if true, prevents default events (click for example)61 allowDiagonal: false, // if false, will trigger horizontal and vertical movements so wipeUpLeft, wipeDownLeft, wipeUpRight, wipeDownRight are ignored62 // Wipe events63 wipeLeft: false, // called on wipe left gesture64 wipeRight: false, // called on wipe right gesture65 wipeUp: false, // called on wipe up gesture66 wipeDown: false, // called on wipe down gesture67 wipeUpLeft: false, // called on wipe top and left gesture68 wipeDownLeft: false, // called on wipe bottom and left gesture69 wipeUpRight: false, // called on wipe top and right gesture70 wipeDownRight: false, // called on wipe bottom and right gesture71 wipeMove: false, // triggered whenever touchMove acts72 // DEPRECATED EVENTS73 wipeTopLeft: false, // USE WIPEUPLEFT74 wipeBottomLeft: false, // USE WIPEDOWNLEFT75 wipeTopRight: false, // USE WIPEUPRIGHT76 wipeBottomRight: false // USE WIPEDOWNRIGHT77 };78 if (settings) {79 $.extend(config, settings);80 }81 this.each(function () {82 // ------------------------------------------------------------------------83 // INTERNAL VARIABLES84 // ------------------------------------------------------------------------85 var startX; // where touch has started, left86 var startY; // where touch has started, top87 var startDate = false; // used to calculate timing and aprox. acceleration88 var curX; // keeps touch X position while moving on the screen89 var curY; // keeps touch Y position while moving on the screen90 var isMoving = false; // is user touching and moving?91 var touchedElement = false; // element which user has touched92 // These are for non-touch devices!93 var useMouseEvents = false; // force using the mouse events to simulate touch94 var clickEvent = false; // holds the click event of the target, when used hasn't clicked95 // ------------------------------------------------------------------------96 // TOUCH EVENTS97 // ------------------------------------------------------------------------98 // Called when user touches the screen.99 function onTouchStart(e) {100 var start = useMouseEvents || (e.originalEvent.touches && e.originalEvent.touches.length > 0);101 if (!isMoving && start) {102 if (config.preventDefault) {103 e.preventDefault();104 }105 // Temporary fix for deprecated events, these will be removed on next version!106 if (config.allowDiagonal) {107 if (!config.wipeDownLeft) {108 config.wipeDownLeft = config.wipeBottomLeft;109 }110 if (!config.wipeDownRight) {111 config.wipeDownRight = config.wipeBottomRight;112 }113 if (!config.wipeUpLeft) {114 config.wipeUpLeft = config.wipeTopLeft;115 }116 if (!config.wipeUpRight) {117 config.wipeUpRight = config.wipeTopRight;118 }119 }120 // When touch events are not present, use mouse events.121 if (useMouseEvents) {122 startX = e.pageX;123 startY = e.pageY;124 $(this).bind("mousemove", onTouchMove);125 $(this).one("mouseup", onTouchEnd);126 }127 else {128 startX = e.originalEvent.touches[0].pageX;129 startY = e.originalEvent.touches[0].pageY;130 $(this).bind("touchmove", onTouchMove);131 }132 // Set the start date and current X/Y.133 startDate = new Date().getTime();134 curX = startX;135 curY = startY;136 isMoving = true;137 touchedElement = $(e.target);138 }139 }140 // Called when user untouches the screen.141 function onTouchEnd(e) {142 if (config.preventDefault) {143 e.preventDefault();144 }145 // When touch events are not present, use mouse events.146 if (useMouseEvents) {147 $(this).unbind("mousemove", onTouchMove);148 }149 else {150 $(this).unbind("touchmove", onTouchMove);151 }152 // If is moving then calculate the touch results, otherwise reset it.153 if (isMoving) {154 touchCalculate(e);155 }156 else {157 resetTouch();158 }159 }160 // Called when user is touching and moving on the screen.161 function onTouchMove(e) {162 if (config.preventDefault) {163 e.preventDefault();164 }165 if (useMouseEvents && !isMoving) {166 onTouchStart(e);167 }168 if (isMoving) {169 if (useMouseEvents) {170 curX = e.pageX;171 curY = e.pageY;172 }173 else {174 curX = e.originalEvent.touches[0].pageX;175 curY = e.originalEvent.touches[0].pageY;176 }177 // If there's a wipeMove event, call it passing178 // current X and Y position (curX and curY).179 if (config.wipeMove) {180 triggerEvent(config.wipeMove, {181 curX: curX,182 curY: curY,183 startX: startX,184 startY: startY,185 moveX: curX - startX,186 moveY: curY - startY187 });188 }189 }190 }191 // ------------------------------------------------------------------------192 // CALCULATE TOUCH AND TRIGGER193 // ------------------------------------------------------------------------194 function touchCalculate(e) {195 var endDate = new Date().getTime(); // current date to calculate timing196 var ms = startDate - endDate; // duration of touch in milliseconds197 var x = curX; // current left position198 var y = curY; // current top position199 var dx = x - startX; // diff of current left to starting left200 var dy = y - startY; // diff of current top to starting top201 var ax = Math.abs(dx); // amount of horizontal movement202 var ay = Math.abs(dy); // amount of vertical movement203 // If moved less than 15 pixels, touch duration is less than 100ms,204 // and tapToClick is true then trigger a click event and stop processing.205 if (ax < 15 && ay < 15 && ms < 100) {206 clickEvent = false;207 if (config.preventDefault) {208 resetTouch();209 touchedElement.trigger("click");210 return;211 }212 }213 // When touch events are not present, use mouse events.214 else if (useMouseEvents) {215 var evts = touchedElement.data("events");216 if (evts) {217 // Save click event to the temp clickEvent variable.218 var clicks = evts.click;219 if (clicks && clicks.length > 0) {220 $.each(clicks, function (i, f) {221 clickEvent = f;222 return;223 });224 touchedElement.unbind("click");225 }226 }227 }228 // Is it moving to the right or left, top or bottom?229 var toright = dx > 0;230 var tobottom = dy > 0;231 // Calculate speed from 1 to 5, 1 being slower and 5 faster.232 var s = ((ax + ay) * 60) / ((ms) / 6 * (ms));233 if (s < 1) s = 1;234 if (s > 5) s = 5;235 var result = {236 speed: parseInt(s),237 x: ax,238 y: ay,239 source: touchedElement240 };241 if (ax >= config.moveX) {242 // Check if it's allowed and trigger diagonal wipe events.243 if (config.allowDiagonal && ay >= config.moveY) {244 if (toright && tobottom) {245 triggerEvent(config.wipeDownRight, result);246 }247 else if (toright && !tobottom) {248 triggerEvent(config.wipeUpRight, result);249 }250 else if (!toright && tobottom) {251 triggerEvent(config.wipeDownLeft, result);252 }253 else {254 triggerEvent(config.wipeUpLeft, result);255 }256 }257 // Otherwise trigger horizontal events if X > Y.258 else if (ax >= ay) {259 if (toright) {260 triggerEvent(config.wipeRight, result);261 }262 else {263 triggerEvent(config.wipeLeft, result);264 }265 }266 }267 // If Y > X and no diagonal, trigger vertical events.268 else if (ay >= config.moveY && ay > ax) {269 if (tobottom) {270 triggerEvent(config.wipeDown, result);271 }272 else {273 triggerEvent(config.wipeUp, result);274 }275 }276 resetTouch();277 }278 // Resets the cached variables.279 function resetTouch() {280 startX = false;281 startY = false;282 startDate = false;283 isMoving = false;284 // If there's a click event, bind after a few miliseconds.285 if (clickEvent) {286 window.setTimeout(function () {287 touchedElement.bind("click", clickEvent);288 clickEvent = false;289 }, 50);290 }291 }292 // Trigger a wipe event passing a result object with293 // speed from 1 to 5, x / y movement amount in pixels,294 // and the source element.295 function triggerEvent(wipeEvent, result) {296 if (wipeEvent) {297 wipeEvent(result);298 }299 }300 // ------------------------------------------------------------------------301 // ADD TOUCHSTART AND TOUCHEND EVENT LISTENERS302 // ------------------------------------------------------------------------303 if ("ontouchstart" in document.documentElement) {304 $(this).bind("touchstart", onTouchStart);305 $(this).bind("touchend", onTouchEnd);306 }307 else {308 useMouseEvents = true;309 $(this).bind("mousedown", onTouchStart);310 $(this).bind("mouseout", onTouchEnd);311 }312 });313 return this;314 };...
PictureWipe.js
Source:PictureWipe.js
1//=============================================================================2// PictureWipe.js3//=============================================================================4/*:5 * @plugindesc Transition effects for event pictures.6 * @author Yoji Ojima7 *8 * @help9 *10 * Plugin Command:11 * PictureWipe 1 down in 6012 *13 * The above plugin command means that the "down" transition effect will be14 * applied for displaying the picture #1, in 60 frames.15 *16 * The first argument specifies the picture ID.17 *18 * The second argument specifies the type of the effect.19 * Can be selected from the following types:20 * down - From the top to the bottom.21 * up - From the bottom to the top.22 * right - From the left to the right.23 * left - From the right to the left.24 * square - From the center to the edge with a square shape.25 * circle - From the center to the edge with a circle shape.26 * hblind - Horizontal blind effect.27 * vblind - Vertical blind effect.28 * grid - Grid effect.29 *30 * The third argument should be "in" to display or "out" to erase.31 *32 * The fourth argument specifies the transition time in frames.33 */34/*:ja35 * @plugindesc ãã¯ãã£ã®åãæ¿ãã¨ãã§ã¯ãã§ãã36 * @author Yoji Ojima37 *38 * @help39 *40 * ãã©ã°ã¤ã³ã³ãã³ã:41 * PictureWipe 1 down in 6042 *43 * ä¸è¨ã®ãã©ã°ã¤ã³ã³ãã³ãã¯ããã¯ãã£ï¼çªã表示ããéã«ãdownãã®åãæ¿ã44 * ã¨ãã§ã¯ãã60ãã¬ã¼ã 表示ãããã¨ãæå®ãã¦ãã¾ãã45 *46 * 1ã¤ç®ã®å¼æ°ã«ã¯ããã¯ãã£IDãæå®ãã¾ãã47 *48 * 2ã¤ç®ã®å¼æ°ã«ã¯ãã¨ãã§ã¯ãã®ç¨®é¡ãæå®ãã¾ãã49 * 以ä¸ã®ç¨®é¡ãé¸æå¯è½ã§ã:50 * down - ä¸ããä¸ã¸ã51 * up - ä¸ããä¸ã¸ã52 * right - å·¦ããå³ã¸ã53 * left - å³ããå·¦ã¸ã54 * square - æ£æ¹å½¢ã§ä¸å¤®ãã端ã¸ã55 * circle - åå½¢ã§ä¸å¤®ãã端ã¸ã56 * hblind - æ°´å¹³ãã©ã¤ã³ãå¹æã57 * vblind - åç´ãã©ã¤ã³ãå¹æã58 * grid - ã°ãªããå¹æã59 *60 * 3ã¤ç®ã®å¼æ°ã¯ã表示ãªããinããæ¶å»ãªããoutãã¨ãã¾ãã61 *62 * 4ã¤ãã®å¼æ°ã¯ããã©ã³ã¸ã·ã§ã³æéããã¬ã¼ã æ°ã§æå®ãã¾ãã63 */64(function() {65 var _Game_Interpreter_pluginCommand =66 Game_Interpreter.prototype.pluginCommand;67 Game_Interpreter.prototype.pluginCommand = function(command, args) {68 _Game_Interpreter_pluginCommand.call(this, command, args);69 if (command === 'PictureWipe') {70 var pictureId = Number(args[0]);71 var wipeType = String(args[1]) || 'down';72 var wipeDirection = String(args[2]) || 'in';73 var wipeMaxFrames = Number(args[3]) || 60;74 var picture = $gameScreen.picture(pictureId);75 if (picture) {76 picture.wipeType = wipeType;77 picture.wipeDirection = wipeDirection;78 picture.wipeMaxFrames = wipeMaxFrames;79 picture.wipeIndex = 0;80 }81 }82 };83 var _Game_Picture_update = Game_Picture.prototype.update;84 Game_Picture.prototype.update = function() {85 _Game_Picture_update.call(this);86 this.updateWipe();87 };88 Game_Picture.prototype.updateWipe = function() {89 if (this.wipeIndex < this.wipeMaxFrames) {90 this.wipeIndex++;91 }92 };93 var _Sprite_Picture_update = Sprite_Picture.prototype.update;94 Sprite_Picture.prototype.update = function() {95 _Sprite_Picture_update.call(this);96 if (this.picture() && this.visible) {97 this.updateWipe();98 }99 };100 Sprite_Picture.prototype.updateWipe = function() {101 var picture = this.picture();102 if (picture.wipeIndex < picture.wipeMaxFrames) {103 var source = ImageManager.loadPicture(this._pictureName);104 if (source.isReady()) {105 if (!this.bitmap || this.bitmap === source) {106 this.bitmap = new Bitmap(source.width, source.height);107 }108 var density = 0;109 if (picture.wipeDirection === 'in') {110 density = picture.wipeIndex / picture.wipeMaxFrames;111 } else if (picture.wipeDirection === 'out') {112 density = 1 - picture.wipeIndex / picture.wipeMaxFrames;113 }114 this.bitmap.clear();115 this.paintWipe(this.bitmap, picture.wipeType, density);116 var context = this.bitmap.context;117 context.save();118 context.globalCompositeOperation = 'source-in';119 context.drawImage(source.canvas, 0, 0);120 context.restore();121 }122 } else if (picture.wipeDirection === 'in') {123 this.bitmap = ImageManager.loadPicture(this._pictureName);124 } else if (picture.wipeDirection === 'out') {125 this.bitmap.clear();126 }127 };128 Sprite_Picture.prototype.paintWipe = function(bitmap, type, density) {129 var blindSize = 48;130 var w = bitmap.width;131 var h = bitmap.height;132 var cx = w / 2;133 var cy = h / 2;134 var color = 'white';135 var size, i, j;136 switch (type) {137 case 'down':138 size = h * density;139 bitmap.fillRect(0, 0, w, size, color);140 break;141 case 'up':142 size = h * density;143 bitmap.fillRect(0, h - size, w, size, color);144 break;145 case 'right':146 size = w * density;147 bitmap.fillRect(0, 0, size, h, color);148 break;149 case 'left':150 size = w * density;151 bitmap.fillRect(w - size, 0, size, h, color);152 break;153 case 'square':154 size = Math.max(w, h) / 2 * density;155 bitmap.fillRect(cx - size, cy - size, size * 2, size * 2, color);156 break;157 case 'circle':158 size = Math.sqrt(w * w + h * h) / 2 * density;159 bitmap.drawCircle(cx, cy, size, color);160 break;161 case 'hblind':162 size = blindSize * density;163 for (i = 0; i < h; i += blindSize) {164 bitmap.fillRect(0, i, w, size, color);165 }166 break;167 case 'vblind':168 size = blindSize * density;169 for (i = 0; i < w; i += blindSize) {170 bitmap.fillRect(i, 0, size, h, color);171 }172 break;173 case 'grid':174 size = blindSize * density;175 for (i = 0; i < h; i += blindSize) {176 for (j = 0; j < w; j += blindSize) {177 bitmap.fillRect(j, i, size, size, color);178 }179 }180 break;181 }182 };...
TestWipe.py
Source:TestWipe.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3'''4=========================================================================5 Program: Visualization Toolkit6 Module: TestNamedColorsIntegration.py7 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen8 All rights reserved.9 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.10 This software is distributed WITHOUT ANY WARRANTY; without even11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR12 PURPOSE. See the above copyright notice for more information.13=========================================================================14'''15import vtk16import vtk.test.Testing17from vtk.util.misc import vtkGetDataRoot18VTK_DATA_ROOT = vtkGetDataRoot()19class TestWipe(vtk.test.Testing.vtkTest):20 def testWipe(self):21 # Image pipeline22 renWin = vtk.vtkRenderWindow()23 image1 = vtk.vtkImageCanvasSource2D()24 image1.SetNumberOfScalarComponents(3)25 image1.SetScalarTypeToUnsignedChar()26 image1.SetExtent(0, 79, 0, 79, 0, 0)27 image1.SetDrawColor(255, 255, 0)28 image1.FillBox(0, 79, 0, 79)29 image1.Update()30 image2 = vtk.vtkImageCanvasSource2D()31 image2.SetNumberOfScalarComponents(3)32 image2.SetScalarTypeToUnsignedChar()33 image2.SetExtent(0, 79, 0, 79, 0, 0)34 image2.SetDrawColor(0, 255, 255)35 image2.FillBox(0, 79, 0, 79)36 image2.Update()37 mapper = vtk.vtkImageMapper()38 mapper.SetInputConnection(image1.GetOutputPort())39 mapper.SetColorWindow(255)40 mapper.SetColorLevel(127.5)41 actor = vtk.vtkActor2D()42 actor.SetMapper(mapper)43 imager = vtk.vtkRenderer()44 imager.AddActor2D(actor)45 renWin.AddRenderer(imager)46 wipes = ["Quad", "Horizontal", "Vertical", "LowerLeft", "LowerRight", "UpperLeft", "UpperRight"]47 wiper = dict()48 mapper = dict()49 actor = dict()50 imagers = dict()51 for wipe in wipes:52 wiper.update({wipe:vtk.vtkImageRectilinearWipe()})53 wiper[wipe].SetInput1Data(image1.GetOutput())54 wiper[wipe].SetInput2Data(image2.GetOutput())55 wiper[wipe].SetPosition(20, 20)56 eval('wiper[wipe].SetWipeTo' + wipe + '()')57 mapper.update({wipe:vtk.vtkImageMapper()})58 mapper[wipe].SetInputConnection(wiper[wipe].GetOutputPort())59 mapper[wipe].SetColorWindow(255)60 mapper[wipe].SetColorLevel(127.5)61 actor.update({wipe:vtk.vtkActor2D()})62 actor[wipe].SetMapper(mapper[wipe])63 imagers.update({wipe:vtk.vtkRenderer()})64 imagers[wipe].AddActor2D(actor[wipe])65 renWin.AddRenderer(imagers[wipe])66 imagers["Quad"].SetViewport(0, .5, .25, 1)67 imagers["Horizontal"].SetViewport(.25, .5, .5, 1)68 imagers["Vertical"].SetViewport(.5, .5, .75, 1)69 imagers["LowerLeft"].SetViewport(.75, .5, 1, 1)70 imagers["LowerRight"].SetViewport(0, 0, .25, .5)71 imagers["UpperLeft"].SetViewport(.25, 0, .5, .5)72 imagers["UpperRight"].SetViewport(.5, 0, .75, .5)73 imager.SetViewport(.75, 0, 1, .5)74 renWin.SetSize(400, 200)75 # render and interact with data76 iRen = vtk.vtkRenderWindowInteractor()77 iRen.SetRenderWindow(renWin);78 renWin.Render()79 img_file = "TestWipe.png"80 vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)81 vtk.test.Testing.interact()82if __name__ == "__main__":...
squirt.py
Source:squirt.py
1#!/usr/bin/env python32# NeoPixel library strandtest example3# Author: Tony DiCola (tony@tonydicola.com)4#5# Direct port of the Arduino NeoPixel library strandtest example. Showcases6# various animations on a pixels of NeoPixels.7import time8import neopixel9import board10import argparse11# LED pixels configuration:12num_pixels = 35013pixel_pin = board.D1214ORDER = neopixel.RGB15# Define functions which animate LEDs in various ways.16def colorWipe(pixels, color, wait_ms=70):17 """Wipe color across display a pixel at a time."""18 for i in range(num_pixels):19 pixels[i] = color20 pixels.show()21 time.sleep(wait_ms/(1000.0)) #modified from 100022# Main program logic follows:23if __name__ == '__main__':24 # Process arguments25 parser = argparse.ArgumentParser()26 parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')27 args = parser.parse_args()28 # Create NeoPixel object with appropriate configuration.29 pixels = neopixel.NeoPixel(30 pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER31 )32 print ('Press Ctrl-C to quit.')33 if not args.clear:34 print('Use "-c" argument to clear LEDs on exit')35 try:36 while True:37 #for i in range(256):38 # colorWipe(pixels, (i, 255, 255 - i)) # Blue wipe39 # colorWipe(pixels, (0, 0, 0)) # Blue wipe40 colorWipe(pixels, (0, 255, 0)) # Blue wipe41 colorWipe(pixels, (0, 0, 0)) # Blue wipe42 #colorWipe(pixels, Color(0, 200, 50)) # Blue wipe43 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe44 #colorWipe(pixels, Color(0, 150, 100)) # Blue wipe45 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe46 #colorWipe(pixels, Color(0, 100, 150)) # Blue wipe47 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe48 #colorWipe(pixels, Color(0, 50, 200)) # Blue wipe49 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe50 #colorWipe(pixels, Color(0, 0, 255)) # Blue wipe51 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe52 #colorWipe(pixels, Color(0, 50, 200)) # Blue wipe53 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe54 #colorWipe(pixels, Color(0, 100, 150)) # Blue wipe55 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe56 #colorWipe(pixels, Color(0, 50, 100)) # Blue wipe57 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe58 #colorWipe(pixels, Color(0, 200, 50)) # Blue wipe59 #colorWipe(pixels, Color(0, 0, 0)) # Blue wipe60 except KeyboardInterrupt:61 if args.clear:...
script.py
Source:script.py
1import inspect2import types3import wipeactions4from pyrevit import forms5from pyrevit import script6from pyrevit import revit, DB7from pyrevit import compat8__doc__ = 'This tools helps you to remove extra unnecessary information in '\9 'the model when sending to a contractor or consultant. '\10 'Run the tools and select the categories that you\'d like '\11 'to be removed from the model. Then hit \"Wipe Model\" and '\12 'the process will go through each category and will ' \13 'remove them. You might see some errors or warnings from Revit '\14 '(since this is a very destructive) ' \15 'process but generally they should not crash the script.'16logger = script.get_logger()17class WipeOption:18 def __init__(self, name, wipe_action=None, wipe_args=None):19 self.name = name20 self.wipe_action = wipe_action21 self.wipe_args = wipe_args22 self.is_dependent = getattr(self.wipe_action, 'is_dependent', False)23 def __repr__(self):24 return '<WipeOption Name:{} Action:{}>'\25 .format(self.name, self.wipe_action)26# generate wipe options based on functions in27# wipeactions module28wipe_options = []29for mem in inspect.getmembers(wipeactions):30 moduleobject = mem[1]31 if inspect.isfunction(moduleobject) \32 and hasattr(moduleobject, 'is_wipe_action'):33 if moduleobject.__doc__:34 wipe_options.append(WipeOption(moduleobject.__doc__,35 wipe_action=moduleobject))36for wscleaner_func in wipeactions.get_worksetcleaners():37 wipe_options.append(WipeOption(wscleaner_func.docstring,38 wipe_action=wscleaner_func.func,39 wipe_args=wscleaner_func.args))40# ask user for wipe actions41return_options = \42 forms.SelectFromList.show(43 sorted(wipe_options, key=lambda x: x.name),44 title='Wipe Options',45 width=500,46 button_name='Wipe Model',47 multiselect=True48 )49if return_options:50 dependent_actions = [wipe_act51 for wipe_act in return_options52 if wipe_act.is_dependent]53 not_dependent_actions = [wipe_act54 for wipe_act in return_options55 if not wipe_act.is_dependent]56 for actions in [dependent_actions, not_dependent_actions]:57 for wipe_act in actions:58 logger.debug('Calling: {}'.format(wipe_act))59 if wipe_act.wipe_args:60 wipe_act.wipe_action(*wipe_act.wipe_args)61 else:...
Using AI Code Generation
1import { TestBed } from '@angular/core/testing';2import { NgMocks } from 'ng-mocks';3import { MyComponent } from './my.component';4describe('MyComponent', () => {5 beforeEach(() => TestBed.configureTestingModule({6 }));7 it('should render', () => {8 const fixture = TestBed.createComponent(MyComponent);9 fixture.detectChanges();10 expect(fixture.nativeElement).toMatchSnapshot();11 });12 describe('NgMocks.wipe', () => {13 it('should wipe all properties', () => {14 const fixture = TestBed.createComponent(MyComponent);15 fixture.detectChanges();16 NgMocks.wipe(fixture);17 expect(fixture.nativeElement).toMatchSnapshot();18 });19 });20});21import { TestBed } from '@angular/core/testing';22import { NgMocks } from 'ng-mocks';23import { MyComponent } from './my.component';24describe('MyComponent', () => {25 beforeEach(() => TestBed.configureTestingModule({26 }));27 it('should render', () => {28 const fixture = NgMocks.render(MyComponent);29 expect(fixture.nativeElement).toMatchSnapshot();30 });31});32import { TestBed } from '@angular/core/testing';33import { NgMocks } from 'ng-mocks';34import { MyComponent } from './my.component';35describe('
Using AI Code Generation
1var wipe = ngMocks.wipe;2var mock = ngMocks.mock;3var mockInstance = ngMocks.mockInstance;4var mockProvider = ngMocks.mockProvider;5var mockPipe = ngMocks.mockPipe;6var mockDirective = ngMocks.mockDirective;7var mockComponent = ngMocks.mockComponent;8var mockModule = ngMocks.mockModule;9var mockRender = ngMocks.mockRender;10var mockService = ngMocks.mockService;11var mockPipe = ngMocks.mockPipe;12var mockResolver = ngMocks.mockResolver;13var mockGuard = ngMocks.mockGuard;14var mockAll = ngMocks.mockAll;15var mockAllProviders = ngMocks.mockAllProviders;16var mockAllPipes = ngMocks.mockAllPipes;17var mockAllDirectives = ngMocks.mockAllDirectives;18var mockAllComponents = ngMocks.mockAllComponents;19var mockAllModules = ngMocks.mockAllModules;20var mockAllServices = ngMocks.mockAllServices;21var mockAllResolvers = ngMocks.mockAllResolvers;22var mockAllGuards = ngMocks.mockAllGuards;
Using AI Code Generation
1var mockModule = ngMocks.default;2var mockComponent = ngMocks.default;3var mockDirective = ngMocks.default;4var mockPipe = ngMocks.default;5var mockProvider = ngMocks.default;6var mockRender = ngMocks.default;7var mockReset = ngMocks.default;8var mockInstance = ngMocks.default;9var mockClear = ngMocks.default;10var mockDefine = ngMocks.default;11var mockReplace = ngMocks.default;12var mockHelper = ngMocks.default;13var mockInput = ngMocks.default;14var mockOutput = ngMocks.default;
Using AI Code Generation
1import { wipe } from 'ng-mocks';2import { MyModule } from './my.module';3import { MyComponent } from './my.component';4import { MyService } from './my.service';5beforeEach(() => {6 wipe(MyModule);7 wipe(MyComponent);8 wipe(MyComponent, MyService);9});10import { mock } from 'ng-mocks';11import { MyModule } from './my.module';12import { MyComponent } from './my.component';13import { MyService } from './my.service';14beforeEach(() => {15 mock(MyComponent);16 mock(MyDirective);17 mock(MyPipe);18 mock(MyService);19});20import { mockInstance } from 'ng-mocks';21import { MyModule } from './my.module';22import { MyComponent } from './my.component';23import { MyService } from './my.service';24beforeEach(() => {25 mockInstance(MyComponent);26 mockInstance(MyDirective);27 mockInstance(MyPipe);28 mockInstance(MyService);29});30import { mockProvider } from 'ng-mocks';31import { MyModule } from './my.module';32import { MyComponent } from './
Using AI Code Generation
1describe('test', () => {2 beforeEach(() => {3 ngMocks.wipe();4 });5 it('test', () => {6 const mock = ngMocks.wipe(BarComponent);7 expect(mock).toBe(BarComponent);8 });9});10describe('test', () => {11 beforeEach(() => {12 ngMocks.wipe();13 });14 it('test', () => {15 const instance = ngMocks.findInstance(BarComponent);16 expect(instance).toBeTruthy();17 });18});19describe('test', () => {20 beforeEach(() => {21 ngMocks.wipe();22 });23 it('test', () => {24 const instance = ngMocks.find(BarComponent);25 expect(instance).toBeTruthy();26 });27});28describe('test', () => {29 beforeEach(() => {30 ngMocks.wipe();31 });32 it('test', () => {33 const instance = ngMocks.findInstances(BarComponent);34 expect(instance).toBeTruthy();35 });36});37describe('test', () => {38 beforeEach(() => {39 ngMocks.wipe();40 });41 it('test', () => {42 const instance = ngMocks.findComponents(BarComponent);43 expect(instance).toBeTruthy();44 });45});46describe('test', () => {47 beforeEach(() => {48 ngMocks.wipe();49 });50 it('test', () => {51 const instance = ngMocks.findDirective(BarDirective);52 expect(instance).toBeTruthy();53 });54});55describe('test', () => {56 beforeEach(() => {57 ngMocks.wipe();58 });59 it('test', () => {
Using AI Code Generation
1import { wipe } from 'ng-mocks';2import { AppComponent } from './app.component';3import { AppModule } from './app.module';4wipe();5wipe(AppModule);6wipe(AppComponent);7import { mock } from 'ng-mocks';8import { AppComponent } from './app.component';9import { AppModule } from './app.module';10mock(AppModule);11mock(AppComponent);12import { mock } from 'ng-mocks';13import { AppComponent } from './app.component';14import { AppModule } from './app.module';15mock(AppModule, { providers: { provide: 'TEST', useValue: 'TEST' } });16mock(AppComponent, { providers: { provide: 'TEST', useValue: 'TEST' } });17import { mock } from 'ng-mocks';18import { AppComponent } from './app.component';19import { AppModule } from './app.module';20mock(AppModule, { declarations: [AppComponent] });21mock(AppComponent, { declarations: [AppComponent] });22import { mock } from 'ng-mocks';23import { AppComponent } from './app.component';24import { AppModule } from './app.module';25mock(AppModule, {26 providers: { provide: 'TEST', useValue: 'TEST' }27});28mock(AppComponent, {29 providers: { provide: 'TEST', useValue: '
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!