How to make a button trigger an event (Timer)? - anylogic

I am working on a fire evacuation project and would like to trigger an event after clicking a button. Basically I want to begin the fire evacuation process manually using the button feature but would like to trigger a timer for about 60 seconds to give the pedestrians time to evacuate using the event feature.
I have tried to make pedestrians stop the evacuation process by manually clicking another button but would like to use an event trigger timer instead as this will be a better way to conduct my simulation. I cannot seem to trigger an event once the button is clicked. I've tried changing the trigger type but not sure where to go from there. Is there any code that is required or another step that is required?

Even though a dynamic event is fine in your application, you can also use a user control event:
And then in your button you can use the following code:
event.restart(60,SECOND); //you can choose any timeout here
or
event.restart(); // this will use the configuration, which in this case I set up to 60 seconds
The difference between a dynamic event and a user controlled event is that if you click the button again:
With the dynamic event, you will generate another instance of the event, meaning that if you click the button at t=0 seconds, and t=30 seconds, you will generate 2 events at t=60 seconds and t=90 seconds
With the user control event, you will restart the same event. if you click the button at t=0 seconds, and t=30 seconds, you will generate a unique event at t=90 seconds.
So depending on which one you prefer... you can choose. I would prefer the user control in case you click the button 2 times... or if you regret clicking it so fast... I don't know

Use the Dynamic Event for this.
Set it up by pulling it from the AnyLogic Agent Library to the Workspace and give it a name (here: MyDynamicEvent).
Add the code you want to have executed when the timer runs off in the Action field
Set one (or several) timed instance for this event by using the code create_MyDynamicEvent(60,SECOND);. Note: The syntax of this statement is always create_ followed by the actual name you gave your DynamicEvent type.

Related

LibreOffice Button Approve or Execute

Could someone explain me, put an example or something about the difference between the triggers "Approve Action" and "Execute Action" of the LibreOffice buttons? Both trigger the same way when pressing the button. I read this on the libreoffice wiki but I cant really figure out.
Approve action
This event takes place before an action is triggered by clicking the control. For example, clicking a "Submit" button initiates a send action; however, the actual "send" process is started only when the When initiating event occurs. The Approve action event allows you to kill the process. If the linked method sends back FALSE, When initiating will not be executed.
Execute action
The Execute action event occurs when an action is started. For example, if you have a "Submit" button in your form, the send process represents the action to be initiated.
Presumably, as the text says, the Approve action could be used to conditionally cancel the event. If you never need to do that, then the Execute action will run your code when the button gets pressed, after the action is approved.
Most likely this will work as expected for buttons. However, I have worked with certain controls and events where returning False from an event handler fails to cancel the event. My suspicion for those cases is that canceling still can happen deeper in the LibreOffice code but is not exposed through the API.

iOS RXSwift What is the equivalent of debounce which lets through first event only?

I have a button which sends network requests. I want to ignore double taps within this button. I tried .throttle, but that didn't seem to work. So I'm trying .debounce - this indeed ignores duplicate taps, but only lets through the last event.
What I want is: On first tap, send a network request, ignore subsequent taps within 0.33 seconds.
Which RXSwift operator would help me put an event through and disable subsequent events within a time window?
let buttonPressObservable = button.rx.tap.asObservable()
buttonPressObservable.debounce(0.33, scheduler: MainScheduler.instance)
.map{/*do stuff*/}
In version 4.2 of the library, throttle has a parameter latest that is set to true by default. If you set that to false, I think it will give you the behavior you want.

Continuosly pressing a button in a traitsui -based GUI

I'm building a GUI for a machine with Traits and TraitsUI. I would like the machine to perform an action as long as a button on the GUI is pressed and of course having the GUI not freeze and display the outcome of this continuous action, i.e. in a separate thread.
I can define in the class which inherits HasTraits a button and a function which performs the actions when the button is pressed (def _button_fired:), but it seems to me that the way the _button_fired is defined, the GUI actually waits for the button-pressing to be over before performing the "Action". As stated above, I would like it to execute a function the second I press the button and stop this function execution (or execute a different function) when I release the button.
You can take as an example code snippet no. 7 from Gael's tutorial and just imagine that while pressing the button, the counter should increase.
Your help will be greatly appreciated.
Hellbourne

DispatcherTimer blocks the UI from being updated?

I have two Buttons in the View, one for recording some sound, one plays the recording when recording is done. When recording is done, I set the VM property of recording_done to 1, which is used for CanPlay(), which enables the Play button. Everything works fine so far.
I added a timer to auto stop the recording after two seconds. after some trials and errors, I settled with a DispatcherTimer. My problem is the UI (Play button) does not gets enabled until I clicked the WPF window (somewhere/anywhere on the windows). Clearly the debug msg says the recording_done is set to 1. That should trigger the UI update, but it does not, until I clicked on the windows.
I tried both ways, 1. Recording button bind to Command in ViewModel, there I start the timer and stop the timer. 2. put the recording button handler and timer code in the view's code behind. similar problems.
Any suggestion? Is this a threading/UI update issue? Thanks.
If your play button is bound to a command, and the CanExecute() of the command is bound indirectly to the recording_done property or field, it won't update until the CanExecuteChanged event on the ICommand is raised, or until WPF decided to requery the commands. I suspect this is the problem - you need to have the ICommand raise CanExecuteChanged.

Timed disabling of button in pygtk

I want to show a dialog box with an OK button that is disabled for a short period of time (perhaps 5 seconds). The other buttons would still need to be responsive during this time.
You need a GTK+ timeout for that. First let the button be disabled. The timeout will call a function to enable the button.
Please not that for usability reasons, it should be visible for the user that a timer is running. You can do this by counting down, like "OK (5)", "Ok (4)" etc. until you enable the button.
See here:
http://graphics.sci.ubu.ac.th/api/pygtk/tutorials/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html
The idea is to set the timeout to 1 second (1000 ms). Everytime the callback is called you change the button label and return TRUE. When your callback is called the 5th time, you enable it and return FALSE. This will remove the timeout.