Timed disabling of button in pygtk - gtk

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.

Related

RENODE How press a button for 5s and invert the methods Press and Release to be compatible with button with pullup configuration

I want to simulate in RENODE my stm32f030 to pressing a button for 5 seconds. But I have some problems related to the time and also with the RENODE method to simulate a Press and a Release of the button
In my firmware I configured the pin that is connected to the button as pull-up, that is, the button without pressing it has Status=TRUE. When the button is pressed, it goes to GND and Status=FALSE.
I did a 'debug' in the RENODE methods, I simulate a Press and then with the Pressed method it returns the status, you can check that:
Press results in True status
Release results in False status
Is there a possibility to reverse this method? Or do I put it as an alias in the robot framework? I found very little documentation, any light on my problem is already welcome
About the problem with time, when I execute the Press method and then the Release method and wait for close to 20 seconds it executes the action which is to blink together the Red and Blue LEDs, see below. However in my firmware it is configured to occur an interruption in the timer after 5s.
I read a bit about this in the official documentation (https://renode.readthedocs.io/en/latest/advanced/time_framework.html) and I suspect it is related to this, but I haven't identified what I need to do to fix it.
Reversing the state of a button is quite easy.
As in the miv-board.repl file, you can do the following:
user_switch_0: Miscellaneous.Button # gpioInputs 0
invert: true <--- this is relevant here
-> gpioInputs#0
Regarding time flow, Renode operates in virtual time domain to ensure determinism of execution, regardless of the host machine. It can be similar to real time flow, but depends heavily on the type of application you run. If you poll a lot and not use interrupts to sleep - things will be slower.
To get information about current virtual time you can run emulation GetTimeSourceInfo and see the output like this:
(machine) emulation GetTimeSourceInfo
Elapsed Virtual Time: 00:00:00.304409 <--- you want this to be 5s
Elapsed Host Time: 00:00:00.831891
Current load: 2.5
Cumulative load: 2.73280684868056
State: WaitingForReportBack
Advance immediately: False
Quantum: 00:00:00.000100

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

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.

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.

How can I create a countdown timer that stops at zero on iOS?

The app description would be something like this:
There are:
3 buttons: start, reset and click here (the last one isn't enabled when the app starts)
2 labels: timer and mainTimer
When you click on start button, the timer goes from 3 seconds to 0 seconds, when it reaches 0, it stops, the click here button gets enabled and the mainTimer gets active, it goes from 60 seconds to 0 seconds. Finally, when mainTimer reaches 0, the start button gets disabled again, the mainTimer stops, and an alert shows up saying: time's up!
When the alert disappears everything gets the same state as in the beginning by clicking the reset button, and you are able to repeat the process.
My main problems are stoping the timers on 0, becoming enabled and disabled the click here button and to make the reset button putting everything as they were in the beginning.
Thanks a lot!!
Please take a look at the NSTimer class reference. Your feature may be implemented with a property for the countdown, a property with the NSTimer and putting the pieces together :)
NSTimer

Reason for 5 sec delay to show an activity on pressing the home button?

I am facing delay of 5 sec to show an Activity after pressing the HOME key. I had gone through some post and found that after pressing the HOME button, android prevents services and broadcast-receivers from calling startActivity for 5 seconds.
Q1. Can anyone please let me know the reason to happening this delay ?
Q2. When I modified the ActivityManagerService::checkAppSwitchAllowedLocked() to always return true, it avoids checking lock and hence Activity gets shown without any delay. Would it be a good solution to avoid delay or it may cause any wrong effect in other ways ?
I know, it's probably too late (half year passed). However, here is the answer
You won't be able to get this permission on not rooted phone, unless your application is signed with the same keys as system. Android has some permissions like that.
Also, you may be interested to check this question. Starting an activity from a service after HOME button pressed without the 5 seconds delay