event-handling

How to trigger function on value change?

我怕爱的太早我们不能终老 提交于 2019-11-26 19:43:43
I realise this question has to do with event-handling and i've read about Python event-handler a dispatchers, so either it did not answer my question or i completely missed out the information. I want method m() of object A to be triggered whenever value v is changing: For instance (assuming money makes happy): global_wealth = 0 class Person() def __init__(self): self.wealth = 0 global global_wealth # here is where attribute should be # bound to changes in 'global_wealth' self.happiness = bind_to(global_wealth, how_happy) def how_happy(self, global_wealth): return self.wealth / global_wealth

Custom event listener on Android app

て烟熏妆下的殇ゞ 提交于 2019-11-26 19:21:06
I need to set up a simple event listener to refresh a ListView once in a while. The problem is I don't know how could I generate an event. I know that for events like key or button pressing I just need to implement the Handler . But in this specific case I actually need to generate the event, which will be fired every time another running thread of my app wakes up and refreshes its list of news from an RSS feed. I've done everything, but got stuck in here. Can I get any suggestion or link with some more info on how to implement this? Define a callback interface public interface

How to ensure an event is only subscribed to once

故事扮演 提交于 2019-11-26 18:45:39
I would like to ensure that I only subscribe once in a particular class for an event on an instance. For example I would like to be able to do the following: if (*not already subscribed*) { member.Event += new MemeberClass.Delegate(handler); } How would I go about implementing such a guard? Hamish Smith If you are talking about an event on a class that you have access to the source for then you could place the guard in the event definition. private bool _eventHasSubscribers = false; private EventHandler<MyDelegateType> _myEvent; public event EventHandler<MyDelegateType> MyEvent { add { if (

Share an event handler across multiple controls

…衆ロ難τιáo~ 提交于 2019-11-26 18:36:14
问题 In my Windows forms application written in C# I have a bunch of buttons. When the user's mouse hovers over a button, I want the button's border to change. Currently I have multiple instances of the following (a copy for each button): private void btnStopServer_MouseEnter(object sender, EventArgs e) { oldColor = btnStopServer.FlatAppearance.BorderColor; btnStopServer.FlatAppearance.BorderColor = mouseOverColor; } private void btnStopServer_MouseLeave(object sender, EventArgs e) { btnStopServer

Handling scroll event on listview in c#

混江龙づ霸主 提交于 2019-11-26 18:24:11
问题 I have a listview that generates thumbnail using a backgroundworker. When the listview is being scrolled i want to pause the backgroundworker and get the current value of the scrolled area, when the user stopped scrolling the listview, resume the backgroundworker starting from the item according to the value of the scrolled area. Is it possible to handle scroll event of a listview? if yes how? if not then what is a good alternative according to what i described above? 回答1: You'll have to add

Is it necessary to explicitly remove event handlers in C#

孤街醉人 提交于 2019-11-26 18:05:35
I have a class that offers up a few events. That class is declared globally but not instanced upon that global declaration--it's instanced on an as-needed basis in the methods that need it. Each time that class is needed in a method, it is instanced and event handlers are registered. Is it necessary to remove the event handlers explicitly before the method goes out of scope? When the method goes out of scope, so goes the instance of the class. Does leaving event handlers registered with that instance that is going out of scope have a memory footprint implication? (I'm wondering if the event

How can I make a single event handler handle ALL Button.Click events?

佐手、 提交于 2019-11-26 18:01:27
In my program, I have 9 buttons, and I have 9 separate event handlers for each of them, despite the fact that the code in each event handler is the same. It is proving to be very tedious to change the code for all of them. Is it possible to make a single Button.Click event handler that handles the Button.Click events for all of my buttons? You can modify the Handles clause on the VS generated event code so that it can process the same event for multiple controls. In most cases, someone might want to funnel most, but not all, button clicks to one procedure. To change the Handles clause: Private

Why people use message/event buses in their code? [closed]

末鹿安然 提交于 2019-11-26 17:57:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 12 months ago . Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. I think that you have heard of message/event buses, it's the single place when all events in the

Angular 2 how to keep event from triggering digest loop/detection cycle?

别等时光非礼了梦想. 提交于 2019-11-26 17:41:01
问题 We are implementing drag and drop functionality with Angular 2. I'm using the dragover event just to run the preventDefault() function. So that the drop event works as explained in this question. The dragover method is being handled by the onDragOver function in the component. <div draggable="true" (dragover)="onDragOver($event)"> ... In the component, this function prevents default behavior allowing for the dragged item to be dropped at this target. onDragOver(event) { event.preventDefault()

What is the proper way of doing event handling in C++?

。_饼干妹妹 提交于 2019-11-26 17:33:07
问题 I have an application that needs to respond to certain events in the following manner: void someMethodWithinSomeClass() { while (true) { wait for event; if (event == SomeEvent) { doSomething(); continue; } if (event == SomeOtherEvent) { doSomethingElse(); continue; } } } This would be running is some thread. In some other threads, operations would create and fire the Events. How do I get these Events to reach the above method/class? What is the proper strategy or architecture for implementing