event-handling

Tkinter: Wait for item in queue

情到浓时终转凉″ 提交于 2019-11-28 17:40:11
I’m using a queue to exchange messages between a background thread and a Tk GUI application. Currently, this is done by calling a query method every now and then. def read_queue(self): try: self.process(self.queue.get(False)) # non-blocking except Queue.Empty: pass finally: self.after(UPDATE_TIME, self.read_queue) The problem with this approach is that if UPDATE_TIME is too large, the application will process new items slower than possible. If it is too small, Tk spends most of the time checking the queue although it could do other stuff in the meantime. Is there a way to automatically trigger

How to overwrite jquery event handlers

蹲街弑〆低调 提交于 2019-11-28 17:21:40
I'll try to explain the problem with a simple code. var fireClick = function() { alert('Wuala!!!') }; $('#clickme').click(fireclick); $('#clickme').click(fireclick); So now it will obviously alert 2 times but i need it alert only once. Tried so many ways, but no result. Thanks. As of jQuery 1.7 you should be using off to remove event handlers and on to add them, though you can still use the click shorthand. $('#clickme').off('click').on('click', fireclick); $('#clickme').off().on('click', fireclick); Original answer: If you want to replace all click handlers, call unbind first without a

button onclick function firing twice

时光总嘲笑我的痴心妄想 提交于 2019-11-28 17:03:48
问题 I have a button that calls a javascript function using an event handler. For some reason, the event handler is being called twice. Here is my button (I am using a php object to generate the code, that's why there are a lot of empty tags): <button name="addToCart" value="" size="" onclick="" src="" class="addToCartButton" id="0011110421111" type="button" formtarget="_self" formmethod="post" formaction="" data-mini="true" width="" height="" placeholder="" data-mini="1" onkeypress="" >Add To

jQuery Multiple Event Handlers - How to Cancel?

流过昼夜 提交于 2019-11-28 16:49:48
I have two functions bound to a click event at two different times (using jQuery). The order in which they are fired is significant. They are firing in the correct order. The problem is, when the first function returns false, the second function is still firing! How can I properly cancel the event? Example code: $(document).click(function() { alert('a'); return false; }); $(document).click(function() { alert('b'); }); You will still see the "b" alert message when clicking the page. This is unacceptable! Use the stopImmediatePropagation function of the jQuery event object. Keeps the rest of the

Handling OnPropertyChanged

ε祈祈猫儿з 提交于 2019-11-28 16:32:06
I'm not well versed in event-based programming. Basically, I'm still stumbling around with it. I'm trying to get something set up, but even with the tutorials, I can't wrap my head around it. What I would like to do (in words) is the following: I have a dataobject where a property changes. I notice this in the setter of the property, and want to raise an event that the property has changed. Elsewhere (in a different class entirely), I want to know that the property on this object has changed, and take some action. Now I'm sure this is a common enough scenario, but my google-fu is letting me

window.resize due to virtual keyboard causes issues with jquery mobile

六月ゝ 毕业季﹏ 提交于 2019-11-28 16:24:41
I'm hitting an unusual problem and I'm looking for suggestions. Basically, I'm using: JQuery Mobile 1.1 JQuery 8.2 PhoneGap (Cordova) 2.1 On many pages in my app on iPhone, if I put my cursor into an input box, this opens the virtual keyboard. That's fine and expected. Here's the problem: In some cases (but not all), placing my cursor into an input box fires the window.resize event. I've verified this via the code below: $(window).resize(function(e) { alert('The window resize occurred! Width: ' + $(window).width() + " Height: " + $(window).height()); debugger; return false; }); Immediately

What is an “event emitter”?

社会主义新天地 提交于 2019-11-28 15:38:11
Browsing through http://microjs.com , I see lots of libraries labeled "event emitters". I like to think I know my way around the basics of the javascript language pretty well, but I really have no idea what an "event emitter" is or does. Anyone care to enlighten me? It sounds interesting... niaher It triggers an event to which anyone can listen. Different libraries offer different implementations and for different purposes, but the basic idea is to provide a framework for issuing events and subscribing to them. Example from jQuery: // Subscribe to event. $('#foo').bind('click', function() {

Allow just one click in class JQUERY

不想你离开。 提交于 2019-11-28 14:30:25
I have a link that will load via ajax some content. My problem is, I don't want to remove the text "Load comments", I just want to not allow more clicks in this class. <a href="javascript:;" class="showcomments" id="'.$idf.'">Load comments</a> Jquery var Progressajax = false; $(function() { $(".showcomments").click(function(){ if(Progressajax) return; Progressajax = true; var element = $(this); var id = element.attr("id"); Progressajax = false; alert("ok"); $(data).hide().prependTo('.varload'+id).fadeIn(1000); //$(element).remove(); $(element).removeAttr("href"); $(element).removeClass(

call a function in a component from another component

陌路散爱 提交于 2019-11-28 14:06:56
In Angular2 , assume I have component1(use it as left panel navigator) and component2 .these two components are not related to each other (sibling, parent and child, ...). how can I call a function in component1 from component2? I cant use event binding here. Seid Mehmedovic Shared service is a common way of communication between non-related components. Your components need to use a single instance of the service , so make sure it's provided at the root level. Shared service: @Injectable() export class SharedService { componentOneFn: Function; constructor() { } } Component one: export class

Proper use of .on method in Jquery

梦想的初衷 提交于 2019-11-28 13:36:02
I really liked the .live method as it was straightforward and essentially not much different than your standard event handler. Alas, it was deprecated and I'm left with the .on method. Basically, I'm loading and dynamically loading content that I'll need the same event handler triggered on. Rather than add the event handler twice or however many times. .live was great for this, but .on has replaced it and I just can't seem to get it to work. check this code: jQuery('#who_me').live('click', function(){ alert('test123'); return false; }); should be the same as: jQuery('#who_me').on('click',