event-handling

How to test event listeners using QUnit

感情迁移 提交于 2019-12-10 11:52:13
问题 I'm using pure Javascript (no JQuery) and I'm trying to get QUnit to test my function that is only invoked via an event, i.e. it's an event listener. So the function I wish to test is of the form: (function() { function the_one_i_want_to_test() { // do stuff } window.addEventListener('load', function() { var some_element = ...; some_element.addEventListener('click', the_one_i_want_to_test); }); })(); I know I could expose the function to test it, but it is only ever used as an event listener

Assertion Error WxPython

社会主义新天地 提交于 2019-12-10 11:49:06
问题 I have this code: import wx class application(wx.Frame): def __init__(self, *args, **kw): super(application, self).__init__(*args, **kw) panel = wx.Panel(self) # Header Header = wx.StaticText(panel, label="Browse", pos=(25, 25)) HeaderFont = Header.GetFont() HeaderFont.PointSize += 10 HeaderFont = HeaderFont.Bold() Header.SetFont(HeaderFont) # displaying everything in 'override_contents.py' from override_contents import contents posx = 25 posy = 60 change = 0 def contentButtonDisplay(panel

Why does my jQuery event handler fail when attached to multiple elements?

ε祈祈猫儿з 提交于 2019-12-10 11:46:01
问题 I am using jquery to add mulitple new "addTask" form elements to a "ul" on the page every time a link is clicked. $('span a').click(function(e){ e.preventDefault(); $('<li>\ <ul>\ <li class="sTitle"><input type="text" class="taskName"></li>\ <li><input type="button" value="saveTask" class="saveTask button"></li>\ </ul>\ </l1>') .appendTo('#toDoList'); saveTask(); }); These new nested ul elements all have an button with the same class "saveTask". I then have a function that allows you to save

Prevent double click on MFC-Dialog button

给你一囗甜甜゛ 提交于 2019-12-10 11:36:16
问题 i'm developing Autocad/Bricscad-Dialogs in MFC C++. Know i detected a bigger problem. There is a dialog which sets metadata for 'special' drawing objects. I update the data of every 'special' drawing object with this dialog (in a loop). So if you have ten 'special' drawing objects, the same dialog will open ten times (successively). Now i have the problem that the user sometimes make a double click on the "OK"-Button. But if this double click is fast enough, the "OK"-Button of the next

Javascript event handlers always increase browser memory usage

不羁岁月 提交于 2019-12-10 11:26:14
问题 Edit: On further examination Firefox does not seem to be doing this, but Chrome definitely does. I guess its just a bug with a new browser - for every event an I/O Read also occurs in Chrome but not in FF. When I load the following page in a browser (I've tested in Chrome and Firefox 3 under Vista) and move the mouse around the memory always increases and does not ever seems to recede. Is this: expected behaviour from a browser a memory leak in the browser or a memory leak in the presented

Chrome extension How to remove a Listener on chrome.webRequest.onBeforeRequest

丶灬走出姿态 提交于 2019-12-10 11:25:14
问题 i am trying to remove this Listener in a google chrome extension for blocking urls, but i don't know how! chrome.webRequest.onBeforeRequest.addListener( function(info) { console.log("Chat intercepted: " + info.url); return {cancel: true}; }, {urls: ["https://sampleUrl/*"]}, ["blocking"] ); 回答1: The solution to the problem is to create a named function instead of an anonymous function var myfunction= function (info) { //Instructions return {cancel: true}; }; and replace it as a variable in the

Interactively add and remove scatter points in matplotlib

馋奶兔 提交于 2019-12-10 11:08:22
问题 Here is the problem I would like to solve: I would like to be able to interactively (i) remove scatter points (grey dots), (ii) add new scatter points, by clicking on the plot. import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots(figsize=(16,4)) a = np.sin(range(100))*np.random.normal(20,10,100) b = [ 5, 15, 25, 30, 40, 50, 75, 85] aa = plt.plot(range(len(a)),a,color='red') bb = plt.scatter(b,a[b],color='grey',s=50) 回答1: This may not be elegant, but it works. Left-click

Simple event system using JavaScript (ES5) - JS Custom Event

最后都变了- 提交于 2019-12-10 10:45:49
问题 Instructions: make this code work without modifying snippet it in any way. Use only plain old JavaScript and no third-party libraries. Write new code that enables the code below to work properly. Hint: Feel free to extend native objects... even though it's typically a bad practice. // Start with an object, any object var myObject = {}; // Register an event on your object using // an `on` method myObject.on('myEvent', function(data) { // Log the data passed to the callback console.log(data); }

Is it OK to ask handlers of my events return immediately?

℡╲_俬逩灬. 提交于 2019-12-10 10:23:19
问题 I am writing a .NET library. One of the classes has events a user of the library will need to subscribe to. Is it OK to ask implementations of handlers for these events return quickly? Or is this a common problem for which there is a common solution? (It will no be fatal if the handler took long - but things start to wrong if their handler takes longer than about half a second - it is a networking library and peers connected will think this peer has dropped as the event is raised on the same

How to have mouseEntered execute only if mouse is pressed down in Java

和自甴很熟 提交于 2019-12-10 10:15:58
问题 I Want to execute the mouseEntered only IF the mouse is currently pressed down, basically this: @Override public void mouseEntered(MouseEvent e) { if(e.mouseDown()){ //Do stuff } } can I do it like this, or do I need a mouse motion listener or what? Thanks! EDIT: Sorry should have made this more clear, but I need the mouse to be press down Before it enters the component, its like holding down the mouse and hovering over the component activates the listener 回答1: You might want to evaluate the